Updated tests for fetch notifications by id, not simply fetch all

This commit is contained in:
Martyn Inglis
2016-01-19 13:45:57 +00:00
parent d275ba83a2
commit 7b756567af
5 changed files with 14 additions and 15 deletions

View File

@@ -24,7 +24,6 @@ def requires_auth():
try:
auth_token = auth_header[7:]
api_client = fetch_client(get_token_issuer(auth_token))
if api_client is None:
authentication_response("Invalid credentials", 403)

View File

@@ -12,9 +12,9 @@ mobile_regex = re.compile("^\\+44[\\d]{10}$")
notifications = Blueprint('notifications', __name__)
@notifications.route('/', methods=['GET'])
def get_notifications():
return jsonify(notify_alpha_client.fetch_notifications()), 200
@notifications.route('/<notification_id>', methods=['GET'])
def get_notifications(notification_id):
return jsonify(notify_alpha_client.fetch_notification_by_id(notification_id)), 200
@notifications.route('/sms', methods=['POST'])

View File

@@ -15,4 +15,4 @@ git+https://github.com/alphagov/notifications-python-client.git@0.1.5#egg=notifi
git+https://github.com/alphagov/notifications-utils.git@0.0.3#egg=notifications-utils==0.0.3
git+https://github.com/alphagov/notify-api-client.git@0.1.5#egg=notify-api-client==0.1.5
git+https://github.com/alphagov/notify-api-client.git@0.1.6#egg=notify-api-client==0.1.6

View File

@@ -30,5 +30,5 @@ display_result $? 1 "Code style check"
#display_result $? 2 "Code coverage"
py.test -v
display_result $? 3 "Unit tests"
py.test -v tests/
display_result $? 3 "Unit tests"

View File

@@ -11,7 +11,7 @@ def test_get_notifications(
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.fetch_notifications',
'app.notify_alpha_client.fetch_notification_by_id',
return_value={
'notifications': [
{
@@ -24,11 +24,11 @@ def test_get_notifications(
auth_header = create_authorization_header(
service_id=sample_admin_service_id,
path=url_for('notifications.get_notifications'),
path=url_for('notifications.get_notifications', notification_id=123),
method='GET')
response = client.get(
url_for('notifications.get_notifications'),
url_for('notifications.get_notifications', notification_id=123),
headers=[auth_header])
json_resp = json.loads(response.get_data(as_text=True))
@@ -36,7 +36,7 @@ def test_get_notifications(
assert len(json_resp['notifications']) == 1
assert json_resp['notifications'][0]['id'] == 'my_id'
assert json_resp['notifications'][0]['notification'] == 'some notify'
assert notify_alpha_client.fetch_notifications.called
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
def test_get_notifications_empty_result(
@@ -47,7 +47,7 @@ def test_get_notifications_empty_result(
with notify_api.test_request_context():
with notify_api.test_client() as client:
mocker.patch(
'app.notify_alpha_client.fetch_notifications',
'app.notify_alpha_client.fetch_notification_by_id',
return_value={
'notifications': [
]
@@ -56,17 +56,17 @@ def test_get_notifications_empty_result(
auth_header = create_authorization_header(
service_id=sample_admin_service_id,
path=url_for('notifications.get_notifications'),
path=url_for('notifications.get_notifications', notification_id=123),
method='GET')
response = client.get(
url_for('notifications.get_notifications'),
url_for('notifications.get_notifications', notification_id=123),
headers=[auth_header])
json_resp = json.loads(response.get_data(as_text=True))
assert response.status_code == 200
assert len(json_resp['notifications']) == 0
assert notify_alpha_client.fetch_notifications.called
notify_alpha_client.fetch_notification_by_id.assert_called_with("123")
def test_should_reject_if_no_phone_numbers(