Refactor tests

This commit is contained in:
Imdad Ahad
2016-12-12 18:06:14 +00:00
parent 431ec8acad
commit 52130e8ba4
2 changed files with 21 additions and 25 deletions

View File

@@ -30,7 +30,6 @@ from app.dao.notifications_dao import (
dao_update_notification, dao_update_notification,
delete_notifications_created_more_than_a_week_ago, delete_notifications_created_more_than_a_week_ago,
get_notification_by_id, get_notification_by_id,
get_notification_by_reference,
get_notification_for_job, get_notification_for_job,
get_notification_billable_unit_count_per_month, get_notification_billable_unit_count_per_month,
get_notification_with_personalisation, get_notification_with_personalisation,
@@ -626,14 +625,13 @@ def test_get_notification_by_id(sample_notification):
assert sample_notification == notification_from_db assert sample_notification == notification_from_db
def test_get_notification_by_reference(notify_db, notify_db_session): def test_get_notification_by_reference(notify_db, notify_db_session, sample_service):
notification = sample_notification(notify_db, notify_db_session, client_reference="some-client-ref") client_reference = 'some-client-ref'
notification_from_db = get_notification_by_reference( assert len(Notification.query.all()) == 0
notification.service.id, sample_notification(notify_db, notify_db_session, client_reference=client_reference)
notification.client_reference, sample_notification(notify_db, notify_db_session, client_reference=client_reference)
key_type=None all_notifications = get_notifications_for_service(sample_service.id, client_reference=client_reference).items
) assert len(all_notifications) == 2
assert notification == notification_from_db
def test_save_notification_no_job_id(sample_template, mmg_provider): def test_save_notification_no_job_id(sample_template, mmg_provider):

View File

@@ -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) auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id)
response = client.get( 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]) headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200 assert response.status_code == 200
assert response.headers['Content-type'] == 'application/json' 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): assert json_response['notifications'][0]['id'] == str(sample_notification_with_reference.id)
auth_header = create_authorization_header(service_id=sample_notification.service_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( 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]) 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)) json_response = json.loads(response.get_data(as_text=True))
assert json_response == {
"errors": [ assert response.status_code == 200
{ assert response.headers['Content-type'] == "application/json"
"error": "NoResultFound", assert len(json_response['notifications']) == 0
"message": "No result found"
}
],
"status_code": 404
}
def test_get_notification_by_id_nonexistent_id(client, sample_notification): def test_get_notification_by_id_nonexistent_id(client, sample_notification):