mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Add tests for when email / sms disabled
This commit is contained in:
@@ -23,7 +23,9 @@ from tests.app.conftest import (
|
||||
sample_template as create_sample_template,
|
||||
sample_service_whitelist as create_sample_service_whitelist,
|
||||
sample_api_key as create_sample_api_key,
|
||||
sample_service)
|
||||
sample_service,
|
||||
sample_template_without_sms_permission,
|
||||
sample_template_without_email_permission)
|
||||
|
||||
from app.models import Template
|
||||
from app.errors import InvalidRequest
|
||||
@@ -1164,3 +1166,34 @@ def test_should_allow_international_number_on_sms_notification(client, notify_db
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert response.status_code == 201
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'template_factory, to, expected_error', [
|
||||
(sample_template_without_sms_permission, '+447700900986', 'Cannot send text messages'),
|
||||
(sample_template_without_email_permission, 'notify@digital.cabinet-office.gov.uk', 'Cannot send emails')
|
||||
])
|
||||
def test_should_not_allow_notification_if_service_permission_not_set(
|
||||
client, notify_db, notify_db_session, mocker, template_factory, to, expected_error):
|
||||
template_without_permission = template_factory(notify_db, notify_db_session)
|
||||
mocked = mocker.patch(
|
||||
'app.celery.provider_tasks.deliver_{}.apply_async'.format(template_without_permission.template_type))
|
||||
|
||||
data = {
|
||||
'to': to,
|
||||
'template': str(template_without_permission.id)
|
||||
}
|
||||
|
||||
auth_header = create_authorization_header(service_id=template_without_permission.service_id)
|
||||
|
||||
response = client.post(
|
||||
path='/notifications/{}'.format(template_without_permission.template_type),
|
||||
data=json.dumps(data),
|
||||
headers=[('Content-Type', 'application/json'), auth_header])
|
||||
|
||||
assert not mocked.called
|
||||
assert response.status_code == 400
|
||||
error_json = json.loads(response.get_data(as_text=True))
|
||||
|
||||
assert error_json['result'] == 'error'
|
||||
assert error_json['message']['to'][0] == expected_error
|
||||
|
||||
Reference in New Issue
Block a user