mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Ensure notifications have billable units and provider if sending fails
If we try to send an SMS to the provider and the provider throws an exception (because they return a 503 status code) the notification should retry. But if we get the callback from the provider before the notification has been retried, the notification will have no billable units or provider set. To avoid this, we now set billable_units and provider even if there has been an exception from our provider.
This commit is contained in:
@@ -117,6 +117,7 @@ def test_send_sms_should_switch_providers_on_provider_failure(sample_notificatio
|
||||
provider_to_use.return_value.send_sms.side_effect = Exception('Error')
|
||||
switch_provider_mock = mocker.patch('app.delivery.send_to_providers.dao_toggle_sms_provider')
|
||||
mocker.patch('app.celery.provider_tasks.deliver_sms.retry')
|
||||
mocker.patch('app.delivery.send_to_providers.update_notification_provider')
|
||||
|
||||
deliver_sms(sample_notification.id)
|
||||
|
||||
|
||||
@@ -562,6 +562,25 @@ def test_should_update_billable_units_according_to_research_mode_and_key_type(
|
||||
assert sample_notification.billable_units == billable_units
|
||||
|
||||
|
||||
def test_should_set_notification_billable_units_and_provider_if_sending_to_provider_fails(
|
||||
notify_db,
|
||||
sample_service,
|
||||
sample_notification,
|
||||
mocker,
|
||||
):
|
||||
mocker.patch('app.mmg_client.send_sms', side_effect=Exception())
|
||||
mocker.patch('app.delivery.send_to_providers.dao_toggle_sms_provider')
|
||||
|
||||
sample_notification.billable_units = 0
|
||||
assert sample_notification.sent_by is None
|
||||
|
||||
with pytest.raises(Exception):
|
||||
send_to_providers.send_sms_to_provider(sample_notification)
|
||||
|
||||
assert sample_notification.billable_units == 1
|
||||
assert sample_notification.sent_by == 'mmg'
|
||||
|
||||
|
||||
def test_should_send_sms_to_international_providers(
|
||||
restore_provider_details,
|
||||
sample_sms_template_with_html,
|
||||
|
||||
Reference in New Issue
Block a user