mirror of
https://github.com/GSA/notifications-api.git
synced 2026-05-05 08:40:29 -04:00
Split generating authorization headers by type
In response to [1]. [1]: https://github.com/alphagov/notifications-api/pull/3300#discussion_r681653248
This commit is contained in:
@@ -4,7 +4,7 @@ import pytest
|
||||
from flask import json, url_for
|
||||
|
||||
from app.utils import DATETIME_FORMAT
|
||||
from tests import create_authorization_header
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import create_notification, create_template
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_get_notification_by_id_returns_200(
|
||||
scheduled_for="2017-06-12 15:15"
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -83,7 +83,7 @@ def test_get_notification_by_id_with_placeholders_returns_200(
|
||||
personalisation={"name": "Bob"}
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -131,7 +131,7 @@ def test_get_notification_by_reference_returns_200(client, sample_template):
|
||||
sample_notification_with_reference = create_notification(template=sample_template,
|
||||
client_reference='some-client-reference')
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_notification_with_reference.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification_with_reference.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?reference={}'.format(sample_notification_with_reference.client_reference),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -154,7 +154,7 @@ def test_get_notification_by_id_returns_created_by_name_if_notification_created_
|
||||
sms_notification = create_notification(template=sample_template)
|
||||
sms_notification.created_by_id = sample_user.id
|
||||
|
||||
auth_header = create_authorization_header(service_id=sms_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sms_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notification_by_id', notification_id=sms_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -165,7 +165,7 @@ def test_get_notification_by_id_returns_created_by_name_if_notification_created_
|
||||
|
||||
|
||||
def test_get_notification_by_reference_nonexistent_reference_returns_no_notifications(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?reference={}'.format('nonexistent-reference'),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -178,7 +178,7 @@ def test_get_notification_by_reference_nonexistent_reference_returns_no_notifica
|
||||
|
||||
|
||||
def test_get_notification_by_id_nonexistent_id(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/dd4b8b9d-d414-4a83-9256-580046bf18f9',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -200,7 +200,7 @@ def test_get_notification_by_id_nonexistent_id(client, sample_notification):
|
||||
|
||||
@pytest.mark.parametrize("id", ["1234-badly-formatted-id-7890", "0"])
|
||||
def test_get_notification_by_id_invalid_id(client, sample_notification, id):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -233,7 +233,7 @@ def test_get_notification_adds_delivery_estimate_for_letters(
|
||||
sample_letter_notification.created_at = datetime.date(2000, created_at_month, 1)
|
||||
sample_letter_notification.postage = postage
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -250,7 +250,7 @@ def test_get_notification_doesnt_have_delivery_estimate_for_non_letters(client,
|
||||
template = create_template(service=sample_service, template_type=template_type)
|
||||
mocked_notification = create_notification(template=template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=mocked_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=mocked_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications/{}'.format(mocked_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -264,7 +264,7 @@ def test_get_all_notifications_except_job_notifications_returns_200(client, samp
|
||||
notifications = [create_notification(template=sample_template) for _ in range(2)]
|
||||
notification = notifications[-1]
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -298,7 +298,7 @@ def test_get_all_notifications_with_include_jobs_arg_returns_200(
|
||||
]
|
||||
notification = notifications[-1]
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?include_jobs=true',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -318,7 +318,7 @@ def test_get_all_notifications_with_include_jobs_arg_returns_200(
|
||||
|
||||
|
||||
def test_get_all_notifications_no_notifications_if_no_notifications(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.get(
|
||||
path='/v2/notifications',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -339,7 +339,7 @@ def test_get_all_notifications_filter_by_template_type(client, sample_service):
|
||||
notification = create_notification(template=email_template, to_field="don.draper@scdp.biz")
|
||||
create_notification(template=sms_template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?template_type=email',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -364,7 +364,7 @@ def test_get_all_notifications_filter_by_template_type(client, sample_service):
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_template_type_invalid_template_type(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?template_type=orange',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -383,7 +383,7 @@ def test_get_all_notifications_filter_by_single_status(client, sample_template):
|
||||
notification = create_notification(template=sample_template, status="pending")
|
||||
create_notification(template=sample_template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?status=pending',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -401,7 +401,7 @@ def test_get_all_notifications_filter_by_single_status(client, sample_template):
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_status_invalid_status(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?status=elephant',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -425,7 +425,7 @@ def test_get_all_notifications_filter_by_multiple_statuses(client, sample_templa
|
||||
]
|
||||
failed_notification = create_notification(template=sample_template, status="permanent-failure")
|
||||
|
||||
auth_header = create_authorization_header(service_id=notifications[0].service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notifications[0].service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?status=created&status=pending&status=sending',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -452,7 +452,7 @@ def test_get_all_notifications_filter_by_failed_status(client, sample_template):
|
||||
for _status in ["technical-failure", "temporary-failure", "permanent-failure"]
|
||||
]
|
||||
|
||||
auth_header = create_authorization_header(service_id=created_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=created_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?status=failed',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -476,7 +476,7 @@ def test_get_all_notifications_filter_by_id(client, sample_template):
|
||||
older_notification = create_notification(template=sample_template)
|
||||
newer_notification = create_notification(template=sample_template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=newer_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=newer_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?older_than={}'.format(newer_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -493,7 +493,7 @@ def test_get_all_notifications_filter_by_id(client, sample_template):
|
||||
|
||||
|
||||
def test_get_all_notifications_filter_by_id_invalid_id(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?older_than=1234-badly-formatted-id-7890',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -508,7 +508,7 @@ def test_get_all_notifications_filter_by_id_invalid_id(client, sample_notificati
|
||||
def test_get_all_notifications_filter_by_id_no_notifications_if_nonexistent_id(client, sample_template):
|
||||
notification = create_notification(template=sample_template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?older_than=dd4b8b9d-d414-4a83-9256-580046bf18f9',
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -526,7 +526,7 @@ def test_get_all_notifications_filter_by_id_no_notifications_if_nonexistent_id(c
|
||||
def test_get_all_notifications_filter_by_id_no_notifications_if_last_notification(client, sample_template):
|
||||
notification = create_notification(template=sample_template)
|
||||
|
||||
auth_header = create_authorization_header(service_id=notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?older_than={}'.format(notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -557,7 +557,7 @@ def test_get_all_notifications_filter_multiple_query_parameters(client, sample_e
|
||||
# this notification was created too recently
|
||||
create_notification(template=sample_email_template, status="pending")
|
||||
|
||||
auth_header = create_authorization_header(service_id=newer_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=newer_notification.service_id)
|
||||
response = client.get(
|
||||
path='/v2/notifications?status=pending&template_type=email&older_than={}'.format(newer_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -587,7 +587,7 @@ def test_get_all_notifications_renames_letter_statuses(
|
||||
sample_notification,
|
||||
sample_email_notification,
|
||||
):
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notifications'),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -618,7 +618,7 @@ def test_get_notifications_renames_letter_statuses(client, sample_letter_templat
|
||||
status=db_status,
|
||||
personalisation={'address_line_1': 'Mr Foo', 'address_line_2': '1 Bar Street', 'postcode': 'N1'}
|
||||
)
|
||||
auth_header = create_authorization_header(service_id=letter_noti.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=letter_noti.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_notification_by_id', notification_id=letter_noti.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -643,7 +643,7 @@ def test_get_pdf_for_notification_returns_pdf_content(
|
||||
)
|
||||
sample_letter_notification.status = 'created'
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_pdf_for_notification', notification_id=sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -666,7 +666,7 @@ def test_get_pdf_for_notification_returns_400_if_pdf_not_found(
|
||||
)
|
||||
sample_letter_notification.status = 'created'
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_pdf_for_notification', notification_id=sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -700,7 +700,7 @@ def test_get_pdf_for_notification_only_returns_pdf_content_if_right_status(
|
||||
)
|
||||
sample_letter_notification.status = status
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_letter_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_pdf_for_notification', notification_id=sample_letter_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
@@ -715,7 +715,7 @@ def test_get_pdf_for_notification_only_returns_pdf_content_if_right_status(
|
||||
|
||||
|
||||
def test_get_pdf_for_notification_fails_for_non_letters(client, sample_notification):
|
||||
auth_header = create_authorization_header(service_id=sample_notification.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_notification.service_id)
|
||||
response = client.get(
|
||||
path=url_for('v2_notifications.get_pdf_for_notification', notification_id=sample_notification.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header]
|
||||
|
||||
@@ -26,7 +26,7 @@ from app.notifications.process_letter_notifications import (
|
||||
from app.schema_validation import validate
|
||||
from app.v2.errors import RateLimitError
|
||||
from app.v2.notifications.notification_schemas import post_letter_response
|
||||
from tests import create_authorization_header
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import create_letter_contact, create_service, create_template
|
||||
from tests.conftest import set_config_values
|
||||
|
||||
@@ -47,7 +47,7 @@ def letter_request(client, data, service_id, key_type=KEY_TYPE_NORMAL, _expected
|
||||
data=json.dumps(data),
|
||||
headers=[
|
||||
('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=service_id, key_type=key_type)
|
||||
create_service_authorization_header(service_id=service_id, key_type=key_type)
|
||||
]
|
||||
)
|
||||
json_resp = json.loads(resp.get_data(as_text=True))
|
||||
@@ -626,7 +626,7 @@ def test_post_precompiled_letter_with_invalid_base64(client, notify_user, mocker
|
||||
"reference": "letter-reference",
|
||||
"content": "hi"
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/letter",
|
||||
data=json.dumps(data),
|
||||
@@ -656,7 +656,7 @@ def test_post_precompiled_letter_notification_returns_201(
|
||||
}
|
||||
if notification_postage:
|
||||
data["postage"] = notification_postage
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/letter",
|
||||
data=json.dumps(data),
|
||||
@@ -689,7 +689,7 @@ def test_post_precompiled_letter_notification_if_s3_upload_fails_notification_is
|
||||
"content": "bGV0dGVyLWNvbnRlbnQ="
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
with pytest.raises(expected_exception=Exception):
|
||||
client.post(
|
||||
path="v2/notifications/letter",
|
||||
@@ -708,7 +708,7 @@ def test_post_letter_notification_throws_error_for_invalid_postage(client, notif
|
||||
"content": "bGV0dGVyLWNvbnRlbnQ=",
|
||||
"postage": "space unicorn"
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/letter",
|
||||
data=json.dumps(data),
|
||||
@@ -725,7 +725,7 @@ def test_post_letter_notification_throws_error_for_invalid_postage(client, notif
|
||||
['application/json', 'application/text'])
|
||||
def test_post_letter_notification_when_payload_is_invalid_json_returns_400(
|
||||
client, sample_service, content_type):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
payload_not_json = {
|
||||
"template_id": "dont-convert-to-json",
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ from app.v2.notifications.notification_schemas import (
|
||||
post_email_response,
|
||||
post_sms_response,
|
||||
)
|
||||
from tests import create_authorization_header
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import (
|
||||
create_api_key,
|
||||
create_reply_to_email,
|
||||
@@ -43,7 +43,7 @@ def test_post_sms_notification_returns_201(client, sample_template_with_placehol
|
||||
}
|
||||
if reference:
|
||||
data.update({"reference": reference})
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -83,7 +83,7 @@ def test_post_sms_notification_uses_inbound_number_as_sender(client, notify_db_s
|
||||
'template_id': str(template.id),
|
||||
'personalisation': {' Name': 'Jo'}
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -111,7 +111,7 @@ def test_post_sms_notification_uses_inbound_number_reply_to_as_sender(client, no
|
||||
'template_id': str(template.id),
|
||||
'personalisation': {' Name': 'Jo'}
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -140,7 +140,7 @@ def test_post_sms_notification_returns_201_with_sms_sender_id(
|
||||
'personalisation': {' Name': 'Jo'},
|
||||
'sms_sender_id': str(sms_sender.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -167,7 +167,7 @@ def test_post_sms_notification_uses_sms_sender_id_reply_to(
|
||||
'personalisation': {' Name': 'Jo'},
|
||||
'sms_sender_id': str(sms_sender.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -193,7 +193,7 @@ def test_notification_reply_to_text_is_original_value_if_sender_is_changed_after
|
||||
'template_id': str(sample_template.id),
|
||||
'sms_sender_id': str(sms_sender.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -225,7 +225,7 @@ def test_should_cache_template_lookups_in_memory(mocker, client, sample_template
|
||||
}
|
||||
|
||||
for _ in range(5):
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
client.post(
|
||||
path='/v2/notifications/sms',
|
||||
data=json.dumps(data),
|
||||
@@ -258,7 +258,7 @@ def test_should_cache_template_and_service_in_redis(mocker, client, sample_templ
|
||||
'template_id': str(sample_template.id),
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
client.post(
|
||||
path='/v2/notifications/sms',
|
||||
data=json.dumps(data),
|
||||
@@ -316,7 +316,7 @@ def test_should_return_template_if_found_in_redis(mocker, client, sample_templat
|
||||
'template_id': str(sample_template.id),
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
data=json.dumps(data),
|
||||
@@ -337,7 +337,7 @@ def test_post_notification_returns_400_and_missing_template(client, sample_servi
|
||||
key_send_to: send_to,
|
||||
'template_id': str(uuid.uuid4())
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -387,7 +387,7 @@ def test_notification_returns_400_and_for_schema_problems(client, sample_templat
|
||||
key_send_to: send_to,
|
||||
'template': str(sample_template.id)
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -417,7 +417,7 @@ def test_post_email_notification_returns_201(client, sample_email_template_with_
|
||||
}
|
||||
if reference:
|
||||
data.update({"reference": reference})
|
||||
auth_header = create_authorization_header(service_id=sample_email_template_with_placeholders.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template_with_placeholders.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -477,7 +477,7 @@ def test_should_not_persist_or_send_notification_if_simulated_recipient(
|
||||
'template_id': str(sample_email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -515,7 +515,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
||||
'template_id': str(sample.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -552,7 +552,7 @@ def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
||||
'template_id': str(sample.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -582,7 +582,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_int_sms(
|
||||
'phone_number': '20-12-1234-1234',
|
||||
'template_id': template.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -612,7 +612,7 @@ def test_post_sms_notification_with_archived_reply_to_id_returns_400(client, sam
|
||||
"template_id": sample_template.id,
|
||||
'sms_sender_id': archived_sender.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/sms",
|
||||
data=json.dumps(data),
|
||||
@@ -636,7 +636,7 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_notification(
|
||||
label: recipient,
|
||||
'template_id': sample_template_without_permission.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_template_without_permission.service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_without_permission.service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(sample_template_without_permission.template_type),
|
||||
@@ -665,7 +665,7 @@ def test_post_sms_notification_returns_400_if_number_not_in_guest_list(
|
||||
"phone_number": '+327700900855',
|
||||
"template_id": template.id,
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=service.id, key_type='team')
|
||||
auth_header = create_service_authorization_header(service_id=service.id, key_type='team')
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -692,7 +692,7 @@ def test_post_sms_notification_returns_201_if_allowed_to_send_int_sms(
|
||||
'phone_number': '20-12-1234-1234',
|
||||
'template_id': sample_template.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -711,7 +711,7 @@ def test_post_sms_should_persist_supplied_sms_number(client, sample_template_wit
|
||||
'personalisation': {' Name': 'Jo'}
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_with_placeholders.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/sms',
|
||||
@@ -728,7 +728,7 @@ def test_post_sms_should_persist_supplied_sms_number(client, sample_template_wit
|
||||
|
||||
|
||||
def test_post_notification_raises_bad_request_if_not_valid_notification_type(client, sample_service):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
response = client.post(
|
||||
'/v2/notifications/foo',
|
||||
data='{}',
|
||||
@@ -763,7 +763,7 @@ def test_post_notification_with_wrong_type_of_sender(
|
||||
'template_id': str(template.id),
|
||||
form_label: fake_uuid
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=template.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -784,7 +784,7 @@ def test_post_email_notification_with_valid_reply_to_id_returns_201(client, samp
|
||||
"template_id": sample_email_template.id,
|
||||
'email_reply_to_id': reply_to_email.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -807,7 +807,7 @@ def test_post_email_notification_with_invalid_reply_to_id_returns_400(client, sa
|
||||
"template_id": sample_email_template.id,
|
||||
'email_reply_to_id': fake_uuid
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -831,7 +831,7 @@ def test_post_email_notification_with_archived_reply_to_id_returns_400(client, s
|
||||
"template_id": sample_email_template.id,
|
||||
'email_reply_to_id': archived_reply_to.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -874,7 +874,7 @@ def test_post_notification_with_document_upload(client, notify_db_session, mocke
|
||||
}
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -919,7 +919,7 @@ def test_post_notification_with_document_upload_simulated(client, notify_db_sess
|
||||
"personalisation": {"document": {"file": "abababab"}}
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -950,7 +950,7 @@ def test_post_notification_without_document_upload_permission(client, notify_db_
|
||||
"personalisation": {"document": {"file": "abababab"}}
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=service.id)
|
||||
auth_header = create_service_authorization_header(service_id=service.id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data=json.dumps(data),
|
||||
@@ -960,7 +960,7 @@ def test_post_notification_without_document_upload_permission(client, notify_db_
|
||||
|
||||
|
||||
def test_post_notification_returns_400_when_get_json_throws_exception(client, sample_email_template):
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_email_template.service_id)
|
||||
response = client.post(
|
||||
path="v2/notifications/email",
|
||||
data="[",
|
||||
@@ -976,7 +976,7 @@ def test_post_notification_returns_400_when_get_json_throws_exception(client, sa
|
||||
)
|
||||
def test_post_notification_when_payload_is_invalid_json_returns_400(
|
||||
client, sample_service, notification_type, content_type):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
payload_not_json = {
|
||||
"template_id": "dont-convert-to-json",
|
||||
}
|
||||
@@ -997,7 +997,7 @@ def test_post_notification_returns_201_when_content_type_is_missing_but_payload_
|
||||
client, sample_service, notification_type, mocker):
|
||||
template = create_template(service=sample_service, template_type=notification_type)
|
||||
mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(notification_type))
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
|
||||
valid_json = {
|
||||
"template_id": str(template.id),
|
||||
@@ -1016,7 +1016,7 @@ def test_post_notification_returns_201_when_content_type_is_missing_but_payload_
|
||||
|
||||
@pytest.mark.parametrize('notification_type', ['email', 'sms'])
|
||||
def test_post_email_notification_when_data_is_empty_returns_400(client, sample_service, notification_type):
|
||||
auth_header = create_authorization_header(service_id=sample_service.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service.id)
|
||||
data = None
|
||||
response = client.post(
|
||||
path='/v2/notifications/{}'.format(notification_type),
|
||||
@@ -1054,7 +1054,7 @@ def test_post_notifications_saves_email_or_sms_to_queue(client, notify_db_sessio
|
||||
response = client.post(
|
||||
path=f'/v2/notifications/{notification_type}',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header(service_id=service.id)]
|
||||
headers=[('Content-Type', 'application/json'), create_service_authorization_header(service_id=service.id)]
|
||||
)
|
||||
|
||||
json_resp = response.get_json()
|
||||
@@ -1096,7 +1096,7 @@ def test_post_notifications_saves_email_or_sms_normally_if_saving_to_queue_fails
|
||||
response = client.post(
|
||||
path=f'/v2/notifications/{notification_type}',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), create_authorization_header(service_id=service.id)]
|
||||
headers=[('Content-Type', 'application/json'), create_service_authorization_header(service_id=service.id)]
|
||||
)
|
||||
|
||||
json_resp = response.get_json()
|
||||
@@ -1134,7 +1134,7 @@ def test_post_notifications_doesnt_use_save_queue_for_test_notifications(
|
||||
path=f'/v2/notifications/{notification_type}',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=service.id, key_type='test')]
|
||||
create_service_authorization_header(service_id=service.id, key_type='test')]
|
||||
)
|
||||
|
||||
json_resp = response.get_json()
|
||||
@@ -1169,7 +1169,7 @@ def test_post_notification_does_not_use_save_queue_for_letters(client, sample_le
|
||||
path='/v2/notifications/letter',
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=sample_letter_template.service_id)]
|
||||
create_service_authorization_header(service_id=sample_letter_template.service_id)]
|
||||
)
|
||||
assert response.status_code == 201
|
||||
json_resp = response.get_json()
|
||||
|
||||
Reference in New Issue
Block a user