From 52130e8ba4fb05edf6d5d28a0fc0d608d394aa99 Mon Sep 17 00:00:00 2001 From: Imdad Ahad Date: Mon, 12 Dec 2016 18:06:14 +0000 Subject: [PATCH] Refactor tests --- tests/app/dao/test_notification_dao.py | 16 +++++----- .../notifications/test_get_notifications.py | 30 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/tests/app/dao/test_notification_dao.py b/tests/app/dao/test_notification_dao.py index 77db3456e..167c2d5f8 100644 --- a/tests/app/dao/test_notification_dao.py +++ b/tests/app/dao/test_notification_dao.py @@ -30,7 +30,6 @@ from app.dao.notifications_dao import ( dao_update_notification, delete_notifications_created_more_than_a_week_ago, get_notification_by_id, - get_notification_by_reference, get_notification_for_job, get_notification_billable_unit_count_per_month, get_notification_with_personalisation, @@ -626,14 +625,13 @@ def test_get_notification_by_id(sample_notification): assert sample_notification == notification_from_db -def test_get_notification_by_reference(notify_db, notify_db_session): - notification = sample_notification(notify_db, notify_db_session, client_reference="some-client-ref") - notification_from_db = get_notification_by_reference( - notification.service.id, - notification.client_reference, - key_type=None - ) - assert notification == notification_from_db +def test_get_notification_by_reference(notify_db, notify_db_session, sample_service): + client_reference = 'some-client-ref' + assert len(Notification.query.all()) == 0 + sample_notification(notify_db, notify_db_session, client_reference=client_reference) + sample_notification(notify_db, notify_db_session, client_reference=client_reference) + all_notifications = get_notifications_for_service(sample_service.id, client_reference=client_reference).items + assert len(all_notifications) == 2 def test_save_notification_no_job_id(sample_template, mmg_provider): diff --git a/tests/app/v2/notifications/test_get_notifications.py b/tests/app/v2/notifications/test_get_notifications.py index 9eac5a269..abb69715e 100644 --- a/tests/app/v2/notifications/test_get_notifications.py +++ b/tests/app/v2/notifications/test_get_notifications.py @@ -66,32 +66,30 @@ def test_get_notification_by_reference_returns_200(client, notify_db, notify_db_ auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id) response = client.get( - path='/v2/notifications?client_reference={}'.format(sample_notification_with_reference.client_reference), + path='/v2/notifications?reference={}'.format(sample_notification_with_reference.client_reference), headers=[('Content-Type', 'application/json'), auth_header]) assert response.status_code == 200 assert response.headers['Content-type'] == 'application/json' + json_response = json.loads(response.get_data(as_text=True)) + assert len(json_response['notifications']) == 1 -def test_get_notification_by_reference_nonexistent_reference_returns_400(client, sample_notification): - auth_header = create_authorization_header(service_id=sample_notification.service_id) + assert json_response['notifications'][0]['id'] == str(sample_notification_with_reference.id) + assert json_response['notifications'][0]['reference'] == "some-client-reference" + + +def test_get_notification_by_reference_nonexistent_reference_returns_no_notifications(client, sample_service): + auth_header = create_authorization_header(service_id=sample_service.id) response = client.get( - path='/v2/notifications?client_reference={}'.format(sample_notification.client_reference), + path='/v2/notifications?reference={}'.format('nonexistent-reference'), headers=[('Content-Type', 'application/json'), auth_header]) - assert response.status_code == 404 - assert response.headers['Content-type'] == 'application/json' - json_response = json.loads(response.get_data(as_text=True)) - assert json_response == { - "errors": [ - { - "error": "NoResultFound", - "message": "No result found" - } - ], - "status_code": 404 - } + + assert response.status_code == 200 + assert response.headers['Content-type'] == "application/json" + assert len(json_response['notifications']) == 0 def test_get_notification_by_id_nonexistent_id(client, sample_notification):