mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-02 17:31:14 -05:00
Ensure restricted service are respected by tasks:
This is checked on 3rd party API calls, but jobs (CSV files) were able expected to only allow valid files. Change in tack means we want to have restricted notification failures reported in the UI.
This commit is contained in:
@@ -13,6 +13,11 @@ from app.celery import tasks
|
||||
from tests.app import load_example_csv
|
||||
from datetime import datetime, timedelta
|
||||
from freezegun import freeze_time
|
||||
from tests.app.conftest import (
|
||||
sample_service,
|
||||
sample_user,
|
||||
sample_template
|
||||
)
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
@@ -139,6 +144,89 @@ def test_should_send_sms_without_personalisation(sample_template, mocker):
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
|
||||
|
||||
def test_should_send_sms_if_restricted_service_and_valid_number(notify_db, notify_db_session, mocker):
|
||||
|
||||
user = sample_user(notify_db, notify_db_session, mobile_numnber="+441234123123")
|
||||
service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
||||
template = sample_template(notify_db, notify_db_session, service=service)
|
||||
|
||||
notification = {
|
||||
"template": template.id,
|
||||
"to": "+441234123123"
|
||||
}
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.firetext_client.send_sms')
|
||||
mocker.patch('app.firetext_client.get_name', return_value="firetext")
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
send_sms(
|
||||
service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_called_once_with("+441234123123", "Sample service: This is a template")
|
||||
|
||||
|
||||
def test_should_not_send_sms_if_restricted_service_and_invalid_number(notify_db, notify_db_session, mocker):
|
||||
|
||||
user = sample_user(notify_db, notify_db_session, mobile_numnber="+441234123123")
|
||||
service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
||||
template = sample_template(notify_db, notify_db_session, service=service)
|
||||
|
||||
notification = {
|
||||
"template": template.id,
|
||||
"to": "+440000000000"
|
||||
}
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.firetext_client.send_sms')
|
||||
mocker.patch('app.firetext_client.get_name', return_value="firetext")
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
send_sms(
|
||||
service.id,
|
||||
notification_id,
|
||||
"encrypted-in-reality",
|
||||
now
|
||||
)
|
||||
|
||||
firetext_client.send_sms.assert_not_called()
|
||||
|
||||
|
||||
def test_should_send_email_if_restricted_service_and_valid_email(notify_db, notify_db_session, mocker):
|
||||
|
||||
user = sample_user(notify_db, notify_db_session, email="test@restricted.com")
|
||||
service = sample_service(notify_db, notify_db_session, user=user, restricted=True)
|
||||
template = sample_template(notify_db, notify_db_session, service=service)
|
||||
|
||||
notification = {
|
||||
"template": template.id,
|
||||
"to": "test@restricted.com"
|
||||
}
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.aws_ses_client.send_email')
|
||||
|
||||
notification_id = uuid.uuid4()
|
||||
now = datetime.utcnow()
|
||||
send_email(
|
||||
service.id,
|
||||
notification_id,
|
||||
'subject',
|
||||
'email_from',
|
||||
"encrypted-in-reality",
|
||||
now)
|
||||
|
||||
aws_ses_client.send_email.assert_called_once_with(
|
||||
"email_from",
|
||||
"test@restricted.com",
|
||||
"subject",
|
||||
template.content
|
||||
)
|
||||
|
||||
|
||||
def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sample_job, mocker):
|
||||
notification = {
|
||||
"template": sample_job.template.id,
|
||||
|
||||
Reference in New Issue
Block a user