Only return active SMS senders

Updated the DAO methods which return a single SMS sender and all SMS senders
to only return the non-archived senders. Changed the error raised in the Admin
interface from a SQLAlchemyError to a BadRequestError.
This commit is contained in:
Katie Smith
2018-04-25 14:23:00 +01:00
parent f810daa3c5
commit 663021e494
7 changed files with 77 additions and 19 deletions

View File

@@ -485,6 +485,30 @@ def test_post_sms_notification_returns_400_if_not_allowed_to_send_int_sms(
]
def test_post_sms_notification_with_archived_reply_to_id_returns_400(client, sample_template, mocker):
archived_sender = create_service_sms_sender(
sample_template.service,
'12345',
is_default=False,
archived=True)
mocker.patch('app.celery.provider_tasks.deliver_email.apply_async')
data = {
"phone_number": '+447700900855',
"template_id": sample_template.id,
'sms_sender_id': archived_sender.id
}
auth_header = create_authorization_header(service_id=sample_template.service_id)
response = client.post(
path="v2/notifications/sms",
data=json.dumps(data),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400
resp_json = json.loads(response.get_data(as_text=True))
assert 'sms_sender_id {} does not exist in database for service id {}'. \
format(archived_sender.id, sample_template.service_id) in resp_json['errors'][0]['message']
assert 'BadRequestError' in resp_json['errors'][0]['error']
@pytest.mark.parametrize('recipient,label,template_factory,expected_error', [
('07700 900000', 'phone_number', sample_template_without_sms_permission, 'Cannot send text messages'),
('someone@test.com', 'email_address', sample_template_without_email_permission, 'Cannot send emails')])