mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-17 04:58:50 -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:
@@ -29,7 +29,7 @@ from app.models import (
|
||||
)
|
||||
from app.service.send_notification import send_one_off_notification
|
||||
from app.v2.errors import RateLimitError
|
||||
from tests import create_authorization_header
|
||||
from tests import create_service_authorization_header
|
||||
from tests.app.db import (
|
||||
create_api_key,
|
||||
create_notification,
|
||||
@@ -48,7 +48,7 @@ def test_create_notification_should_reject_if_missing_required_fields(notify_api
|
||||
with notify_api.test_client() as client:
|
||||
mocked = mocker.patch('app.celery.provider_tasks.deliver_{}.apply_async'.format(template_type))
|
||||
data = {}
|
||||
auth_header = create_authorization_header(service_id=sample_api_key.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_api_key.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/{}'.format(template_type),
|
||||
@@ -72,7 +72,7 @@ def test_should_reject_bad_phone_numbers(notify_api, sample_template, mocker):
|
||||
'to': 'invalid',
|
||||
'template': 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='/notifications/sms',
|
||||
@@ -99,7 +99,7 @@ def test_send_notification_invalid_template_id(notify_api, sample_template, mock
|
||||
'to': to,
|
||||
'template': fake_uuid
|
||||
}
|
||||
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='/notifications/{}'.format(template_type),
|
||||
@@ -126,7 +126,9 @@ def test_send_notification_with_placeholders_replaced(notify_api, sample_email_t
|
||||
'name': 'Jo'
|
||||
}
|
||||
}
|
||||
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='/notifications/email',
|
||||
@@ -196,7 +198,7 @@ def test_send_notification_with_placeholders_replaced_with_unusual_types(
|
||||
),
|
||||
headers=[
|
||||
('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=sample_email_template_with_placeholders.service.id)
|
||||
create_service_authorization_header(service_id=sample_email_template_with_placeholders.service.id)
|
||||
]
|
||||
)
|
||||
|
||||
@@ -215,7 +217,7 @@ def test_should_not_send_notification_for_archived_template(notify_api, sample_t
|
||||
'to': '+447700900855',
|
||||
'template': 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)
|
||||
|
||||
resp = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -246,7 +248,7 @@ def test_should_not_send_notification_if_restricted_and_not_a_service_user(notif
|
||||
'template': template.id
|
||||
}
|
||||
|
||||
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='/notifications/{}'.format(template_type),
|
||||
@@ -284,7 +286,7 @@ def test_should_send_notification_if_restricted_and_a_service_user(notify_api,
|
||||
'template': template.id
|
||||
}
|
||||
|
||||
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='/notifications/{}'.format(template_type),
|
||||
@@ -315,7 +317,7 @@ def test_should_not_allow_template_from_another_service(notify_api,
|
||||
'template': service_2_templates[0].id
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=service_1.id)
|
||||
auth_header = create_service_authorization_header(service_id=service_1.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/{}'.format(template_type),
|
||||
@@ -340,7 +342,7 @@ def test_should_allow_valid_sms_notification(notify_api, sample_template, mocker
|
||||
'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='/notifications/sms',
|
||||
@@ -367,7 +369,7 @@ def test_should_reject_email_notification_with_bad_email(notify_api, sample_emai
|
||||
'to': to_address,
|
||||
'template': str(sample_email_template.service_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='/notifications/email',
|
||||
@@ -392,7 +394,7 @@ def test_should_allow_valid_email_notification(notify_api, sample_email_template
|
||||
'template': 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='/notifications/email',
|
||||
@@ -434,7 +436,7 @@ def test_should_allow_api_call_if_under_day_limit_regardless_of_type(
|
||||
'template': str(sms_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='/notifications/sms',
|
||||
@@ -455,7 +457,7 @@ def test_should_not_return_html_in_body(notify_api, sample_service, mocker):
|
||||
'template': str(email_template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=email_template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=email_template.service_id)
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
data=json.dumps(data),
|
||||
@@ -473,7 +475,9 @@ def test_should_not_send_email_if_team_api_key_and_not_a_service_user(notify_api
|
||||
'template': str(sample_email_template.id),
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM)
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -499,7 +503,7 @@ def test_should_not_send_sms_if_team_api_key_and_not_a_service_user(notify_api,
|
||||
'template': str(sample_template.id),
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template.service_id, key_type=KEY_TYPE_TEAM)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template.service_id, key_type=KEY_TYPE_TEAM)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -523,7 +527,9 @@ def test_should_send_email_if_team_api_key_and_a_service_user(client, sample_ema
|
||||
'to': sample_email_template.service.created_by.email_address,
|
||||
'template': sample_email_template.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM)
|
||||
auth_header = create_service_authorization_header(
|
||||
service_id=sample_email_template.service_id, key_type=KEY_TYPE_TEAM
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -739,7 +745,7 @@ def test_should_not_persist_notification_or_send_email_if_simulated_email(
|
||||
'template': 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='/notifications/email',
|
||||
@@ -768,7 +774,7 @@ def test_should_not_persist_notification_or_send_sms_if_simulated_number(
|
||||
'template': 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='/notifications/sms',
|
||||
@@ -903,7 +909,7 @@ def test_should_error_if_notification_type_does_not_match_template_type(
|
||||
'to': to,
|
||||
'template': template.id
|
||||
}
|
||||
auth_header = create_authorization_header(service_id=template.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=template.service_id)
|
||||
response = client.post("/notifications/{}".format(notification_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
@@ -979,7 +985,7 @@ def test_send_notification_uses_priority_queue_when_template_is_marked_as_priori
|
||||
'template': 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='/notifications/{}'.format(notification_type),
|
||||
@@ -1017,7 +1023,7 @@ def test_returns_a_429_limit_exceeded_if_rate_limit_exceeded(
|
||||
'template': 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='/notifications/{}'.format(notification_type),
|
||||
@@ -1042,7 +1048,7 @@ def test_should_allow_store_original_number_on_sms_notification(client, sample_t
|
||||
'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='/notifications/sms',
|
||||
@@ -1070,7 +1076,7 @@ def test_should_not_allow_sending_to_international_number_without_international_
|
||||
'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='/notifications/sms',
|
||||
@@ -1097,7 +1103,7 @@ def test_should_allow_sending_to_crown_dependency_number_without_international_p
|
||||
'template': str(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='/notifications/sms',
|
||||
@@ -1118,7 +1124,7 @@ def test_should_allow_sending_to_international_number_with_international_permiss
|
||||
'template': str(template.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_service_full_permissions.id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_service_full_permissions.id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -1140,7 +1146,7 @@ def test_should_not_allow_sms_notifications_if_service_permission_not_set(
|
||||
'template': str(sample_template_without_sms_permission.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template_without_sms_permission.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_without_sms_permission.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/sms',
|
||||
@@ -1167,7 +1173,7 @@ def test_should_not_allow_email_notifications_if_service_permission_not_set(
|
||||
'template': str(sample_template_without_email_permission.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=sample_template_without_email_permission.service_id)
|
||||
auth_header = create_service_authorization_header(service_id=sample_template_without_email_permission.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/email',
|
||||
@@ -1187,7 +1193,7 @@ def test_should_not_allow_email_notifications_if_service_permission_not_set(
|
||||
[("letter", "letter notification type is not supported, please use the latest version of the client"),
|
||||
("apple", "apple notification type is not supported")])
|
||||
def test_should_throw_exception_if_notification_type_is_invalid(client, sample_service, notification_type, err_msg):
|
||||
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='/notifications/{}'.format(notification_type),
|
||||
data={},
|
||||
@@ -1217,7 +1223,7 @@ def test_post_notification_should_set_reply_to_text(client, sample_service, mock
|
||||
response = client.post("/notifications/{}".format(notification_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'),
|
||||
create_authorization_header(service_id=sample_service.id)]
|
||||
create_service_authorization_header(service_id=sample_service.id)]
|
||||
)
|
||||
assert response.status_code == 201
|
||||
notifications = Notification.query.all()
|
||||
|
||||
Reference in New Issue
Block a user