Skip to content

Commit

Permalink
write tests for @minglis 's code 🙁
Browse files Browse the repository at this point in the history
  • Loading branch information
leohemsted committed Dec 9, 2016
1 parent d56b7b9 commit 2419f0d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/app/notify_client/test_notify_admin_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ def test_inactive_service_can_be_modified_by_platform_admin(app_, platform_admin

assert request.called
assert ret == request.return_value


def test_generate_headers_sets_standard_headers():
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')

# with patch('app.notify_client.has_request_context', return_value=False):
headers = api_client.generate_headers('api_token')

assert set(headers.keys()) == {'Authorization', 'Content-type', 'User-agent'}
assert headers['Authorization'] == 'Bearer api_token'
assert headers['Content-type'] == 'application/json'
assert headers['User-agent'].startswith('NOTIFY-API-PYTHON-CLIENT')


def test_generate_headers_sets_request_id_if_in_request_context(app_):
api_client = NotifyAdminAPIClient('api_key', 'base_url', 'service_id')

with app_.test_request_context() as request_context:
headers = api_client.generate_headers('api_token')

assert set(headers.keys()) == {'Authorization', 'Content-type', 'User-agent', 'NotifyRequestID'}
assert headers['NotifyRequestID'] == request_context.request.request_id

0 comments on commit 2419f0d

Please sign in to comment.