mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 22:39:43 -04:00
Merge pull request #762 from alphagov/v2-get-notification-by-reference
V2 get notification by reference
This commit is contained in:
@@ -411,7 +411,8 @@ def sample_notification(notify_db,
|
||||
personalisation=None,
|
||||
api_key_id=None,
|
||||
key_type=KEY_TYPE_NORMAL,
|
||||
sent_by=None):
|
||||
sent_by=None,
|
||||
client_reference=None):
|
||||
if created_at is None:
|
||||
created_at = datetime.utcnow()
|
||||
if service is None:
|
||||
@@ -445,7 +446,8 @@ def sample_notification(notify_db,
|
||||
'api_key_id': api_key_id,
|
||||
'key_type': key_type,
|
||||
'sent_by': sent_by,
|
||||
'updated_at': created_at if status in NOTIFICATION_STATUS_TYPES_COMPLETED else None
|
||||
'updated_at': created_at if status in NOTIFICATION_STATUS_TYPES_COMPLETED else None,
|
||||
'client_reference': client_reference
|
||||
}
|
||||
if job_row_number:
|
||||
data['job_row_number'] = job_row_number
|
||||
|
||||
@@ -30,6 +30,7 @@ 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,
|
||||
@@ -616,7 +617,7 @@ def test_save_notification_with_no_job(sample_template, mmg_provider):
|
||||
assert notification_from_db.status == 'created'
|
||||
|
||||
|
||||
def test_get_notification(sample_notification):
|
||||
def test_get_notification_by_id(sample_notification):
|
||||
notification_from_db = get_notification_with_personalisation(
|
||||
sample_notification.service.id,
|
||||
sample_notification.id,
|
||||
@@ -625,6 +626,16 @@ def test_get_notification(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_save_notification_no_job_id(sample_template, mmg_provider):
|
||||
assert Notification.query.count() == 0
|
||||
data = _notification_json(sample_template)
|
||||
|
||||
@@ -60,6 +60,40 @@ def test_get_notification_by_id_returns_200(
|
||||
assert json_response == expected_response
|
||||
|
||||
|
||||
def test_get_notification_by_reference_returns_200(client, notify_db, notify_db_session):
|
||||
sample_notification_with_reference = create_sample_notification(
|
||||
notify_db, notify_db_session, client_reference='some-client-reference')
|
||||
|
||||
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),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers['Content-type'] == 'application/json'
|
||||
|
||||
|
||||
def test_get_notification_by_reference_nonexistent_reference_returns_400(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?client_reference={}'.format(sample_notification.client_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
|
||||
}
|
||||
|
||||
|
||||
def test_get_notification_by_id_nonexistent_id(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
|
||||
Reference in New Issue
Block a user