import requests
import json
protocol = 'https://'
api_version = 'v2'
def test_print_parameters(host, verifyssl):
print
print 'host', host
print 'verifyssl', verifyssl
def test_get_emoticons_unathorized_error(host, verifyssl):
print host
url_fragment = '/emoticon'
response = requests.get(protocol + host + '/' + api_version + url_fragment, verify=verifyssl)
assert 401 == response.status_code
data = json.loads(response.text)
assert 401 == data['error']['code']
assert 'Authenticated requests only. See https://www.hipchat.com/docs/apiv2/auth for more information.' == \
data['error']['message']
assert 'Unauthorized' == data['error']['type']
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# content of separate file conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption('--host', action='store', default='api.hipchat.com', help='host server to connect to')
parser.addoption('--verifyssl', action='store_true', default=False, help='validate SSL')
@pytest.fixture
def host(request):
return request.config.getoption('--host')
@pytest.fixture
def verifyssl(request):
return request.config.getoption('--verifyssl')
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
py.test -s -v test_emoticons.py --host my.example.com --verifyssl