all tests passing

This commit is contained in:
jimmoffet
2022-10-03 20:07:42 -07:00
parent c04d1df6b3
commit fc9e4107c1
8 changed files with 118 additions and 112 deletions

View File

@@ -71,9 +71,9 @@ def test_notifications_ses_400_with_certificate(client):
def test_notifications_ses_200_autoconfirms_subscription(client, mocker):
mocker.patch("app.celery.process_ses_receipts_tasks.validate_sns_message", return_value=True)
mocker.patch("app.notifications.sns_handlers.validate_sns_cert", return_value=True)
requests_mock = mocker.patch("requests.get")
data = json.dumps({"Type": "SubscriptionConfirmation", "SubscribeURL": "https://foo"})
data = json.dumps({"Type": "SubscriptionConfirmation", "SubscribeURL": "https://foo", "Message": "foo"})
response = client.post(
path='/notifications/email/ses',
data=data,
@@ -85,9 +85,10 @@ def test_notifications_ses_200_autoconfirms_subscription(client, mocker):
def test_notifications_ses_200_call_process_task(client, mocker):
mocker.patch("app.celery.process_ses_receipts_tasks.validate_sns_message", return_value=True)
process_mock = mocker.patch("app.celery.process_ses_receipts_tasks.process_ses_results.apply_async")
data = {"Type": "Notification", "foo": "bar"}
process_mock = mocker.patch("app.notifications.notifications_ses_callback.process_ses_results.apply_async")
mocker.patch("app.notifications.sns_handlers.validate_sns_cert", return_value=True)
data = {"Type": "Notification", "foo": "bar", "Message": {"mail": "baz"} }
mocker.patch("app.notifications.sns_handlers.sns_notification_handler", return_value=data)
json_data = json.dumps(data)
response = client.post(
path='/notifications/email/ses',
@@ -95,7 +96,7 @@ def test_notifications_ses_200_call_process_task(client, mocker):
headers=[('Content-Type', 'application/json'), ('x-amz-sns-message-type', 'Notification')]
)
process_mock.assert_called_once_with([{'Message': None}], queue='notify-internal-tasks')
process_mock.assert_called_once_with([{'Message': {"mail": "baz"}}], queue='notify-internal-tasks')
assert response.status_code == 200

View File

@@ -443,17 +443,17 @@ def create_service_permission(service_id, permission=EMAIL_TYPE):
def create_inbound_sms(
service,
notify_number=None,
user_number='447700900111',
user_number='12025550104',
provider_date=None,
provider_reference=None,
content='Hello',
provider="mmg",
provider="sns",
created_at=None
):
if not service.inbound_number:
create_inbound_number(
# create random inbound number
notify_number or '07{:09}'.format(random.randint(0, 1e9 - 1)),
notify_number or '1'+str(random.randint(1001001000, 9999999999)),
provider=provider,
service_id=service.id
)

View File

@@ -39,6 +39,7 @@ def test_post_to_get_inbound_sms_with_no_params(admin_request, sample_service):
'+4407700900001',
'447700900001',
])
@pytest.mark.skip(reason="Needs updating for TTS. Don't need to test UK numbers right now")
def test_post_to_get_inbound_sms_filters_user_number(admin_request, sample_service, user_number):
# user_number in the db is international and normalised
one = create_inbound_sms(sample_service, user_number='447700900001')
@@ -65,7 +66,7 @@ def test_post_to_get_inbound_sms_filters_international_user_number(admin_request
create_inbound_sms(sample_service)
data = {
'phone_number': '+1 (202) 555-0104'
'phone_number': '12025550104'
}
sms = admin_request.post(
@@ -74,9 +75,10 @@ def test_post_to_get_inbound_sms_filters_international_user_number(admin_request
_data=data
)['data']
assert len(sms) == 1
assert sms[0]['id'] == str(one.id)
assert sms[0]['user_number'] == str(one.user_number)
assert len(sms) == 2
print(f'sms is: {sms}')
assert sms[1]['id'] == str(one.id)
assert sms[1]['user_number'] == str(one.user_number)
def test_post_to_get_inbound_sms_allows_badly_formatted_number(admin_request, sample_service):

View File

@@ -72,7 +72,7 @@ def test_process_ses_results_in_complaint_save_complaint_with_null_complaint_typ
def test_check_and_queue_callback_task(mocker, sample_notification):
mock_create = mocker.patch(
'app.notifications.notifications_ses_callback.create_delivery_status_callback_data'
'app.celery.process_ses_receipts_tasks.create_delivery_status_callback_data'
)
mock_send = mocker.patch(
@@ -86,6 +86,7 @@ def test_check_and_queue_callback_task(mocker, sample_notification):
# callback_api doesn't match by equality for some
# reason, so we need to take this approach instead
print(f'mock_create.mock_calls is: {mock_create.mock_calls}')
mock_create_args = mock_create.mock_calls[0][1]
assert mock_create_args[0] == sample_notification
assert mock_create_args[1].id == callback_api.id