mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 18:31:13 -05:00
notify-api-433b remove research mode
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import json
|
||||
import uuid
|
||||
from collections import namedtuple
|
||||
from datetime import datetime
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
from flask import current_app
|
||||
# from notifications_utils.recipients import validate_and_format_phone_number
|
||||
from requests import HTTPError
|
||||
|
||||
import app
|
||||
@@ -215,41 +213,6 @@ def test_send_sms_should_use_template_version_from_notification_not_latest(
|
||||
assert not persisted_notification.personalisation
|
||||
|
||||
|
||||
@pytest.mark.parametrize('research_mode,key_type', [
|
||||
(True, KEY_TYPE_NORMAL),
|
||||
(False, KEY_TYPE_TEST)
|
||||
])
|
||||
def test_should_call_send_sms_response_task_if_research_mode(
|
||||
notify_db_session, sample_service, sample_notification, mocker, research_mode, key_type
|
||||
):
|
||||
mocker.patch('app.aws_sns_client.send_sms')
|
||||
send_sms_response = mocker.patch('app.delivery.send_to_providers.send_sms_response')
|
||||
|
||||
if research_mode:
|
||||
sample_service.research_mode = True
|
||||
notify_db_session.add(sample_service)
|
||||
notify_db_session.commit()
|
||||
|
||||
sample_notification.key_type = key_type
|
||||
|
||||
send_to_providers.send_sms_to_provider(
|
||||
sample_notification
|
||||
)
|
||||
assert not aws_sns_client.send_sms.called
|
||||
|
||||
send_sms_response.assert_called_once_with(
|
||||
'sns', str(sample_notification.id)
|
||||
)
|
||||
|
||||
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
||||
assert persisted_notification.to == sample_notification.to
|
||||
assert persisted_notification.template_id == sample_notification.template_id
|
||||
assert persisted_notification.status == 'sending'
|
||||
assert persisted_notification.sent_at <= datetime.utcnow()
|
||||
assert persisted_notification.sent_by == 'sns'
|
||||
assert not persisted_notification.personalisation
|
||||
|
||||
|
||||
def test_should_have_sending_status_if_fake_callback_function_fails(sample_notification, mocker):
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=HTTPError)
|
||||
|
||||
@@ -328,46 +291,6 @@ def test_send_sms_should_use_service_sms_sender(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('research_mode,key_type', [
|
||||
(True, KEY_TYPE_NORMAL),
|
||||
(False, KEY_TYPE_TEST)
|
||||
])
|
||||
def test_send_email_to_provider_should_call_research_mode_task_response_task_if_research_mode(
|
||||
sample_service,
|
||||
sample_email_template,
|
||||
mocker,
|
||||
research_mode,
|
||||
key_type):
|
||||
notification = create_notification(
|
||||
template=sample_email_template,
|
||||
to_field="john@smith.com",
|
||||
key_type=key_type,
|
||||
billable_units=0
|
||||
)
|
||||
sample_service.research_mode = research_mode
|
||||
|
||||
reference = uuid.uuid4()
|
||||
mocker.patch('app.uuid.uuid4', return_value=reference)
|
||||
mocker.patch('app.aws_ses_client.send_email')
|
||||
send_email_response = mocker.patch('app.delivery.send_to_providers.send_email_response')
|
||||
|
||||
send_to_providers.send_email_to_provider(
|
||||
notification
|
||||
)
|
||||
|
||||
assert not app.aws_ses_client.send_email.called
|
||||
send_email_response.assert_called_once_with(str(reference), 'john@smith.com')
|
||||
persisted_notification = Notification.query.filter_by(id=notification.id).one()
|
||||
assert persisted_notification.to == 'john@smith.com'
|
||||
assert persisted_notification.template_id == sample_email_template.id
|
||||
assert persisted_notification.status == 'sending'
|
||||
assert persisted_notification.sent_at <= datetime.utcnow()
|
||||
assert persisted_notification.created_at <= datetime.utcnow()
|
||||
assert persisted_notification.sent_by == 'ses'
|
||||
assert persisted_notification.reference == str(reference)
|
||||
assert persisted_notification.billable_units == 0
|
||||
|
||||
|
||||
def test_send_email_to_provider_should_not_send_to_provider_when_status_is_not_created(
|
||||
sample_email_template,
|
||||
mocker
|
||||
@@ -518,25 +441,6 @@ def test_get_logo_url_works_for_different_environments(base_url, expected_url):
|
||||
assert logo_url == expected_url
|
||||
|
||||
|
||||
def test_should_not_update_notification_if_research_mode_on_exception(
|
||||
sample_service, sample_notification, mocker
|
||||
):
|
||||
mocker.patch('app.delivery.send_to_providers.send_sms_response', side_effect=Exception())
|
||||
update_mock = mocker.patch('app.delivery.send_to_providers.update_notification_to_sending')
|
||||
sample_service.research_mode = True
|
||||
sample_notification.billable_units = 0
|
||||
|
||||
try:
|
||||
send_to_providers.send_sms_to_provider(sample_notification)
|
||||
assert 1 == 0
|
||||
except Exception:
|
||||
assert 1 == 1
|
||||
|
||||
persisted_notification = notifications_dao.get_notification_by_id(sample_notification.id)
|
||||
assert persisted_notification.billable_units == 0
|
||||
assert update_mock.called
|
||||
|
||||
|
||||
@pytest.mark.parametrize("starting_status, expected_status", [
|
||||
("delivered", "delivered"),
|
||||
("created", "sending"),
|
||||
|
||||
Reference in New Issue
Block a user