mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
Added new tests/code to ensure failure stats recorded
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
import uuid
|
||||
from celery.exceptions import MaxRetriesExceededError
|
||||
|
||||
from mock import ANY, call
|
||||
|
||||
from app import statsd_client, mmg_client
|
||||
from app.celery import provider_tasks
|
||||
from app.celery.provider_tasks import send_sms_to_provider
|
||||
from app.celery.tasks import provider_to_use
|
||||
from app.clients.sms import SmsClientException
|
||||
from app.dao import provider_statistics_dao
|
||||
from datetime import datetime
|
||||
from freezegun import freeze_time
|
||||
from app.dao import notifications_dao, provider_details_dao
|
||||
from notifications_utils.recipients import validate_phone_number, format_phone_number
|
||||
from app.celery.research_mode_tasks import send_sms_response
|
||||
from app.models import Notification, NotificationStatistics, Job
|
||||
|
||||
from tests.app.conftest import (
|
||||
sample_notification
|
||||
@@ -280,7 +283,6 @@ def test_statsd_updates(notify_db, notify_db_session, sample_service, sample_not
|
||||
mocker.patch('app.statsd_client.incr')
|
||||
mocker.patch('app.statsd_client.timing')
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.mmg_client.send_sms')
|
||||
mocker.patch('app.mmg_client.get_name', return_value="mmg")
|
||||
mocker.patch('app.celery.research_mode_tasks.send_sms_response.apply_async')
|
||||
@@ -298,6 +300,44 @@ def test_statsd_updates(notify_db, notify_db_session, sample_service, sample_not
|
||||
])
|
||||
|
||||
|
||||
def test_should_go_into_technical_error_if_exceeds_retries(
|
||||
notify_db,
|
||||
notify_db_session,
|
||||
sample_service,
|
||||
sample_notification,
|
||||
mocker):
|
||||
|
||||
notification = _notification_json(
|
||||
sample_notification.template,
|
||||
to=sample_notification.to
|
||||
)
|
||||
|
||||
mocker.patch('app.statsd_client.incr')
|
||||
mocker.patch('app.statsd_client.timing')
|
||||
mocker.patch('app.encryption.decrypt', return_value=notification)
|
||||
mocker.patch('app.mmg_client.send_sms', side_effect=SmsClientException("EXPECTED"))
|
||||
mocker.patch('app.celery.provider_tasks.send_sms_to_provider.retry', side_effect=MaxRetriesExceededError())
|
||||
|
||||
send_sms_to_provider(
|
||||
sample_notification.service_id,
|
||||
sample_notification.id,
|
||||
"encrypted-in-reality"
|
||||
)
|
||||
|
||||
provider_tasks.send_sms_to_provider.retry.assert_called_with(queue='retry', countdown=60)
|
||||
assert statsd_client.incr.assert_not_called
|
||||
assert statsd_client.timing.assert_not_called
|
||||
|
||||
db_notification = Notification.query.get(sample_notification.id)
|
||||
assert db_notification.status == 'technical-failure'
|
||||
notification_stats = NotificationStatistics.query.filter_by(service_id=sample_notification.service.id).first()
|
||||
assert notification_stats.sms_requested == 1
|
||||
assert notification_stats.sms_failed == 1
|
||||
job = Job.query.get(sample_notification.job.id)
|
||||
assert job.notification_count == 1
|
||||
assert job.notifications_failed == 1
|
||||
|
||||
|
||||
def _notification_json(template, to, personalisation=None, job_id=None, row_number=None):
|
||||
notification = {
|
||||
"template": template.id,
|
||||
|
||||
@@ -2,7 +2,6 @@ import uuid
|
||||
import pytest
|
||||
from flask import current_app
|
||||
from mock import ANY
|
||||
from notifications_utils.recipients import validate_phone_number, format_phone_number
|
||||
|
||||
from app.celery import provider_tasks
|
||||
from app.celery.tasks import (
|
||||
@@ -18,13 +17,9 @@ from app.celery.tasks import (
|
||||
provider_to_use,
|
||||
timeout_notifications
|
||||
)
|
||||
from app.celery.research_mode_tasks import (
|
||||
send_email_response,
|
||||
send_sms_response
|
||||
)
|
||||
from app import (aws_ses_client, encryption, DATETIME_FORMAT, mmg_client, statsd_client)
|
||||
from app.celery.research_mode_tasks import send_email_response
|
||||
from app import (aws_ses_client, encryption, DATETIME_FORMAT, statsd_client)
|
||||
from app.clients.email.aws_ses import AwsSesClientException
|
||||
from app.clients.sms.mmg import MMGClientException
|
||||
from app.dao import notifications_dao, jobs_dao, provider_details_dao
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm.exc import NoResultFound
|
||||
|
||||
Reference in New Issue
Block a user