mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-25 02:19:45 -04:00
clean flake8 except provider code
This commit is contained in:
@@ -87,7 +87,7 @@ def test_notifications_ses_200_autoconfirms_subscription(client, mocker):
|
||||
def test_notifications_ses_200_call_process_task(client, mocker):
|
||||
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"} }
|
||||
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(
|
||||
@@ -156,7 +156,10 @@ def test_ses_callback_should_update_notification_status(
|
||||
status='sending',
|
||||
sent_at=datetime.utcnow()
|
||||
)
|
||||
callback_api = create_service_callback_api(service=sample_email_template.service, url="https://original_url.com")
|
||||
callback_api = create_service_callback_api(
|
||||
service=sample_email_template.service,
|
||||
url="https://original_url.com"
|
||||
)
|
||||
assert get_notification_by_id(notification.id).status == 'sending'
|
||||
assert process_ses_results(ses_notification_callback(reference='ref'))
|
||||
assert get_notification_by_id(notification.id).status == 'delivered'
|
||||
@@ -186,13 +189,19 @@ def test_ses_callback_should_retry_if_notification_is_new(mocker):
|
||||
assert process_ses_results(ses_notification_callback(reference='ref')) is None
|
||||
assert mock_logger.call_count == 0
|
||||
assert mock_retry.call_count == 1
|
||||
|
||||
|
||||
def test_ses_callback_should_log_if_notification_is_missing(client, _notify_db, mocker):
|
||||
mock_retry = mocker.patch('app.celery.process_ses_receipts_tasks.process_ses_results.retry')
|
||||
mock_logger = mocker.patch('app.celery.process_ses_receipts_tasks.current_app.logger.warning')
|
||||
with freeze_time('2017-11-17T12:34:03.646Z'):
|
||||
assert process_ses_results(ses_notification_callback(reference='ref')) is None
|
||||
assert mock_retry.call_count == 0
|
||||
mock_logger.assert_called_once_with('notification not found for reference: ref (while attempting update to delivered)')
|
||||
mock_logger.assert_called_once_with(
|
||||
'notification not found for reference: ref (while attempting update to delivered)'
|
||||
)
|
||||
|
||||
|
||||
def test_ses_callback_should_not_retry_if_notification_is_old(mocker):
|
||||
mock_retry = mocker.patch('app.celery.process_ses_receipts_tasks.process_ses_results.retry')
|
||||
mock_logger = mocker.patch('app.celery.process_ses_receipts_tasks.current_app.logger.error')
|
||||
@@ -200,6 +209,8 @@ def test_ses_callback_should_not_retry_if_notification_is_old(mocker):
|
||||
assert process_ses_results(ses_notification_callback(reference='ref')) is None
|
||||
assert mock_logger.call_count == 0
|
||||
assert mock_retry.call_count == 0
|
||||
|
||||
|
||||
def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry(
|
||||
client,
|
||||
_notify_db,
|
||||
@@ -222,6 +233,8 @@ def test_ses_callback_does_not_call_send_delivery_status_if_no_db_entry(
|
||||
assert process_ses_results(ses_notification_callback(reference='ref'))
|
||||
assert get_notification_by_id(notification.id).status == 'delivered'
|
||||
send_mock.assert_not_called()
|
||||
|
||||
|
||||
def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
client,
|
||||
_notify_db,
|
||||
@@ -257,6 +270,8 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||
assert process_ses_results(ses_notification_callback(reference='ref2'))
|
||||
assert process_ses_results(ses_notification_callback(reference='ref3'))
|
||||
assert send_mock.called
|
||||
|
||||
|
||||
def test_ses_callback_should_set_status_to_temporary_failure(client,
|
||||
_notify_db,
|
||||
notify_db_session,
|
||||
@@ -278,6 +293,8 @@ def test_ses_callback_should_set_status_to_temporary_failure(client,
|
||||
assert process_ses_results(ses_soft_bounce_callback(reference='ref'))
|
||||
assert get_notification_by_id(notification.id).status == 'temporary-failure'
|
||||
assert send_mock.called
|
||||
|
||||
|
||||
def test_ses_callback_should_set_status_to_permanent_failure(client,
|
||||
_notify_db,
|
||||
notify_db_session,
|
||||
@@ -299,6 +316,8 @@ def test_ses_callback_should_set_status_to_permanent_failure(client,
|
||||
assert process_ses_results(ses_hard_bounce_callback(reference='ref'))
|
||||
assert get_notification_by_id(notification.id).status == 'permanent-failure'
|
||||
assert send_mock.called
|
||||
|
||||
|
||||
def test_ses_callback_should_send_on_complaint_to_user_callback_api(sample_email_template, mocker):
|
||||
send_mock = mocker.patch(
|
||||
'app.celery.service_callback_tasks.send_complaint_to_service.apply_async'
|
||||
@@ -321,4 +340,3 @@ def test_ses_callback_should_send_on_complaint_to_user_callback_api(sample_email
|
||||
'service_callback_api_url': 'https://original_url.com',
|
||||
'to': 'recipient1@example.com'
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import pytest
|
||||
from freezegun import freeze_time
|
||||
|
||||
from app import statsd_client
|
||||
# from app.celery.process_sms_client_response_tasks import (
|
||||
# process_sms_client_response,
|
||||
# )
|
||||
from app.celery.process_sms_client_response_tasks import (
|
||||
process_sms_client_response,
|
||||
)
|
||||
from app.clients import ClientException
|
||||
from app.models import NOTIFICATION_TECHNICAL_FAILURE
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ def test_should_add_to_retry_queue_if_notification_not_found_in_deliver_email_ta
|
||||
app.delivery.send_to_providers.send_email_to_provider.assert_not_called()
|
||||
app.celery.provider_tasks.deliver_email.retry.assert_called_with(queue="retry-tasks")
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Failing for unknown reason")
|
||||
@pytest.mark.parametrize(
|
||||
'exception_class', [
|
||||
|
||||
@@ -290,6 +290,7 @@ def test_create_nightly_billing_for_day_different_sent_by(
|
||||
assert record.billable_units == 1
|
||||
assert record.rate_multiplier == 1.0
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Remove mail")
|
||||
def test_create_nightly_billing_for_day_different_letter_postage(
|
||||
notify_db_session,
|
||||
|
||||
@@ -24,4 +24,4 @@ def test_send_sms_returns_raises_error_if_there_is_no_valid_number_is_found(noti
|
||||
content = reference = 'foo'
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
aws_sns_client.send_sms(to, content, reference)
|
||||
assert 'No valid numbers found for SMS delivery' in str(excinfo.value)
|
||||
assert 'No valid numbers found for SMS delivery' in str(excinfo.value)
|
||||
|
||||
@@ -15,6 +15,7 @@ def fake_client(notify_api):
|
||||
fake_client.init_app(notify_api, statsd_client)
|
||||
return fake_client
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: New SMS client")
|
||||
def test_send_sms(fake_client, mocker):
|
||||
mock_send = mocker.patch.object(fake_client, 'try_send_sms')
|
||||
@@ -31,6 +32,7 @@ def test_send_sms(fake_client, mocker):
|
||||
'to', 'content', 'reference', False, 'testing'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: New SMS client")
|
||||
def test_send_sms_error(fake_client, mocker):
|
||||
mocker.patch.object(
|
||||
|
||||
@@ -144,6 +144,7 @@ def test_adjust_provider_priority_sets_priority(
|
||||
assert mmg_provider.created_by.id == notify_user.id
|
||||
assert mmg_provider.priority == 50
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
|
||||
@freeze_time('2016-01-01 00:30')
|
||||
def test_adjust_provider_priority_adds_history(
|
||||
@@ -172,6 +173,7 @@ def test_adjust_provider_priority_adds_history(
|
||||
assert updated_provider_history_rows[0].version - old_provider_history_rows[0].version == 1
|
||||
assert updated_provider_history_rows[0].priority == 50
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
|
||||
@freeze_time('2016-01-01 01:00')
|
||||
def test_get_sms_providers_for_update_returns_providers(restore_provider_details):
|
||||
|
||||
@@ -43,6 +43,7 @@ def setup_function(_function):
|
||||
# state of the cache is not shared between tests.
|
||||
send_to_providers.provider_cache.clear()
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
|
||||
def test_provider_to_use_should_return_random_provider(mocker, notify_db_session):
|
||||
mmg = get_provider_details_by_identifier('mmg')
|
||||
@@ -72,6 +73,7 @@ def test_provider_to_use_should_cache_repeated_calls(mocker, notify_db_session):
|
||||
assert all(result == results[0] for result in results)
|
||||
assert len(mock_choices.call_args_list) == 1
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
|
||||
@pytest.mark.parametrize('international_provider_priority', (
|
||||
# Since there’s only one international provider it should always
|
||||
@@ -592,6 +594,7 @@ def test_should_not_update_notification_if_research_mode_on_exception(
|
||||
assert persisted_notification.billable_units == 0
|
||||
assert update_mock.called
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Update with new providers")
|
||||
@pytest.mark.parametrize("starting_status, expected_status", [
|
||||
("delivered", "delivered"),
|
||||
|
||||
@@ -31,8 +31,8 @@ from tests.app.db import create_notification
|
||||
|
||||
FROZEN_DATE_TIME = "2018-03-14 17:00:00"
|
||||
|
||||
pytest.skip(reason="Skipping letter-related functionality for now", allow_module_level=True)
|
||||
|
||||
@pytest.skip(reason="Skipping letter-related functionality for now", allow_module_level=True)
|
||||
@pytest.fixture(name='sample_precompiled_letter_notification')
|
||||
def _sample_precompiled_letter_notification(sample_letter_notification):
|
||||
sample_letter_notification.template.hidden = True
|
||||
|
||||
@@ -17,6 +17,7 @@ def mmg_post(client, data):
|
||||
data=data,
|
||||
headers=[('Content-Type', 'application/json')])
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Firetext removal")
|
||||
def test_firetext_callback_should_not_need_auth(client, mocker):
|
||||
mocker.patch('app.notifications.notifications_sms_callback.process_sms_client_response')
|
||||
@@ -36,6 +37,7 @@ def test_firetext_callback_should_return_400_if_empty_reference(client, mocker):
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == ['Firetext callback failed: reference missing']
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Firetext removal")
|
||||
def test_firetext_callback_should_return_400_if_no_reference(client, mocker):
|
||||
data = 'mobile=441234123123&status=0&time=2016-03-10 14:17:00'
|
||||
@@ -45,6 +47,7 @@ def test_firetext_callback_should_return_400_if_no_reference(client, mocker):
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == ['Firetext callback failed: reference missing']
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Firetext removal")
|
||||
def test_firetext_callback_should_return_400_if_no_status(client, mocker):
|
||||
data = 'mobile=441234123123&time=2016-03-10 14:17:00&reference=notification_id'
|
||||
@@ -54,6 +57,7 @@ def test_firetext_callback_should_return_400_if_no_status(client, mocker):
|
||||
assert json_resp['result'] == 'error'
|
||||
assert json_resp['message'] == ['Firetext callback failed: status missing']
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Firetext removal")
|
||||
def test_firetext_callback_should_return_200_and_call_task_with_valid_data(client, mocker):
|
||||
mock_celery = mocker.patch(
|
||||
@@ -70,6 +74,7 @@ def test_firetext_callback_should_return_200_and_call_task_with_valid_data(clien
|
||||
queue='sms-callbacks',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: Firetext removal")
|
||||
def test_firetext_callback_including_a_code_should_return_200_and_call_task_with_valid_data(client, mocker):
|
||||
mock_celery = mocker.patch(
|
||||
@@ -86,6 +91,7 @@ def test_firetext_callback_including_a_code_should_return_200_and_call_task_with
|
||||
queue='sms-callbacks',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
|
||||
def test_mmg_callback_should_not_need_auth(client, mocker, sample_notification):
|
||||
mocker.patch('app.notifications.notifications_sms_callback.process_sms_client_response')
|
||||
@@ -98,6 +104,7 @@ def test_mmg_callback_should_not_need_auth(client, mocker, sample_notification):
|
||||
response = mmg_post(client, data)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
|
||||
def test_process_mmg_response_returns_400_for_malformed_data(client):
|
||||
data = json.dumps({"reference": "mmg_reference",
|
||||
@@ -114,6 +121,7 @@ def test_process_mmg_response_returns_400_for_malformed_data(client):
|
||||
assert "{} callback failed: {} missing".format('MMG', 'status') in json_data['message']
|
||||
assert "{} callback failed: {} missing".format('MMG', 'CID') in json_data['message']
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: MMG removal")
|
||||
def test_mmg_callback_should_return_200_and_call_task_with_valid_data(client, mocker):
|
||||
mock_celery = mocker.patch(
|
||||
|
||||
@@ -238,6 +238,7 @@ def test_should_cache_template_lookups_in_memory(mocker, client, sample_template
|
||||
]
|
||||
assert Notification.query.count() == 5
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: cloud.gov redis fails, local docker works, mock redis fails")
|
||||
def test_should_cache_template_and_service_in_redis(mocker, client, sample_template):
|
||||
|
||||
@@ -288,6 +289,7 @@ def test_should_cache_template_and_service_in_redis(mocker, client, sample_templ
|
||||
assert json.loads(templates_call[0][1]) == {'data': template_dict}
|
||||
assert templates_call[1]['ex'] == 604_800
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs updating for TTS: cloud.gov redis fails, local docker works, mock redis fails")
|
||||
def test_should_return_template_if_found_in_redis(mocker, client, sample_template):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user