mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 09:26:08 -05:00
For the post_sms_response and post_email_response the reference property is always present but the value can be null.
Added a test for an empty reference. Remove datetime format on the created_at attribute of a notification, it is not needed.
This commit is contained in:
@@ -57,7 +57,7 @@ def persist_notification(template_id,
|
|||||||
notification_type=notification_type,
|
notification_type=notification_type,
|
||||||
api_key_id=api_key_id,
|
api_key_id=api_key_id,
|
||||||
key_type=key_type,
|
key_type=key_type,
|
||||||
created_at=created_at or datetime.utcnow().strftime(DATETIME_FORMAT),
|
created_at=created_at or datetime.utcnow(),
|
||||||
job_id=job_id,
|
job_id=job_id,
|
||||||
job_row_number=job_row_number,
|
job_row_number=job_row_number,
|
||||||
client_reference=reference
|
client_reference=reference
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ post_sms_response = {
|
|||||||
"title": "response v2/notifications/sms",
|
"title": "response v2/notifications/sms",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": uuid,
|
"id": uuid,
|
||||||
"reference": {"type": "string"},
|
"reference": {"type": ["string", "null"]},
|
||||||
"content": sms_content,
|
"content": sms_content,
|
||||||
"uri": {"type": "string"},
|
"uri": {"type": "string"},
|
||||||
"template": template
|
"template": template
|
||||||
@@ -90,7 +90,7 @@ post_email_response = {
|
|||||||
"title": "response v2/notifications/email",
|
"title": "response v2/notifications/email",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": uuid,
|
"id": uuid,
|
||||||
"reference": {"type": "string"},
|
"reference": {"type": ["string", "null"]},
|
||||||
"content": email_content,
|
"content": email_content,
|
||||||
"uri": {"type": "string"},
|
"uri": {"type": "string"},
|
||||||
"template": template
|
"template": template
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ def post_sms_notification():
|
|||||||
notification_type=SMS_TYPE,
|
notification_type=SMS_TYPE,
|
||||||
api_key_id=api_user.id,
|
api_key_id=api_user.id,
|
||||||
key_type=api_user.key_type,
|
key_type=api_user.key_type,
|
||||||
reference=form['reference'])
|
reference=form.get('reference'))
|
||||||
send_notification_to_queue(notification, service.research_mode)
|
send_notification_to_queue(notification, service.research_mode)
|
||||||
|
|
||||||
resp = create_post_sms_response_from_notification(notification,
|
resp = create_post_sms_response_from_notification(notification,
|
||||||
@@ -65,7 +65,7 @@ def post_email_notification():
|
|||||||
notification_type=EMAIL_TYPE,
|
notification_type=EMAIL_TYPE,
|
||||||
api_key_id=api_user.id,
|
api_key_id=api_user.id,
|
||||||
key_type=api_user.key_type,
|
key_type=api_user.key_type,
|
||||||
reference=form['reference'])
|
reference=form.get('reference'))
|
||||||
|
|
||||||
send_notification_to_queue(notification, service.research_mode)
|
send_notification_to_queue(notification, service.research_mode)
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ from app.models import Notification
|
|||||||
from tests import create_authorization_header
|
from tests import create_authorization_header
|
||||||
|
|
||||||
|
|
||||||
def test_post_sms_notification_returns_201(notify_api, sample_template, mocker):
|
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
|
||||||
|
def test_post_sms_notification_returns_201(notify_api, sample_template, mocker, reference):
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
mocked = mocker.patch('app.celery.provider_tasks.deliver_sms.apply_async')
|
||||||
data = {
|
data = {
|
||||||
'phone_number': '+447700900855',
|
'phone_number': '+447700900855',
|
||||||
'template_id': str(sample_template.id),
|
'template_id': str(sample_template.id)
|
||||||
'reference': 'reference_from_client'
|
|
||||||
}
|
}
|
||||||
|
if reference:
|
||||||
|
data.update({"reference": reference})
|
||||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
@@ -27,8 +29,8 @@ def test_post_sms_notification_returns_201(notify_api, sample_template, mocker):
|
|||||||
notifications = Notification.query.all()
|
notifications = Notification.query.all()
|
||||||
assert len(notifications) == 1
|
assert len(notifications) == 1
|
||||||
notification_id = notifications[0].id
|
notification_id = notifications[0].id
|
||||||
assert resp_json['id'] is not None
|
assert resp_json['id'] == notification_id
|
||||||
assert resp_json['reference'] == 'reference_from_client'
|
assert resp_json['reference'] == reference
|
||||||
assert resp_json['content']['body'] == sample_template.content
|
assert resp_json['content']['body'] == sample_template.content
|
||||||
assert resp_json['content']['from_number'] == sample_template.service.sms_sender
|
assert resp_json['content']['from_number'] == sample_template.service.sms_sender
|
||||||
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
|
assert 'v2/notifications/{}'.format(notification_id) in resp_json['uri']
|
||||||
@@ -105,13 +107,15 @@ def test_post_sms_notification_returns_400_and_for_schema_problems(notify_api, s
|
|||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
def test_post_email_notification_returns_201(client, sample_email_template, mocker):
|
@pytest.mark.parametrize("reference", [None, "reference_from_client"])
|
||||||
|
def test_post_email_notification_returns_201(client, sample_email_template, mocker, reference):
|
||||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
mocked = mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
|
||||||
data = {
|
data = {
|
||||||
"reference": "reference from caller",
|
|
||||||
"email_address": sample_email_template.service.users[0].email_address,
|
"email_address": sample_email_template.service.users[0].email_address,
|
||||||
"template_id": sample_email_template.id,
|
"template_id": sample_email_template.id,
|
||||||
}
|
}
|
||||||
|
if reference:
|
||||||
|
data.update({"reference": reference})
|
||||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path="v2/notifications/email",
|
path="v2/notifications/email",
|
||||||
@@ -121,7 +125,7 @@ def test_post_email_notification_returns_201(client, sample_email_template, mock
|
|||||||
resp_json = json.loads(response.get_data(as_text=True))
|
resp_json = json.loads(response.get_data(as_text=True))
|
||||||
notification = Notification.query.first()
|
notification = Notification.query.first()
|
||||||
assert resp_json['id'] == str(notification.id)
|
assert resp_json['id'] == str(notification.id)
|
||||||
assert resp_json['reference'] == "reference from caller"
|
assert resp_json['reference'] == reference
|
||||||
assert notification.reference is None
|
assert notification.reference is None
|
||||||
assert resp_json['content']['body'] == sample_email_template.content
|
assert resp_json['content']['body'] == sample_email_template.content
|
||||||
assert resp_json['content']['subject'] == sample_email_template.subject
|
assert resp_json['content']['subject'] == sample_email_template.subject
|
||||||
|
|||||||
Reference in New Issue
Block a user