mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 10:28:55 -04:00
DRY-up logging and metrics for sending SMS
This avoids duplicating it as we add a new provider and means we can test it all in one place (although it wasn't tested before). I'm not sure why the previous code did "super(..)__init__" in a non-init function - it's a bit late! - so I've just replaced it with a call to the new "init_app" function in the parent class.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
|
||||
from app import statsd_client
|
||||
from app.clients.sms import SmsClient, SmsClientResponseException
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_client(notify_api):
|
||||
class FakeSmsClient(SmsClient):
|
||||
@property
|
||||
def name(self):
|
||||
return 'fake'
|
||||
|
||||
fake_client = FakeSmsClient()
|
||||
fake_client.init_app(notify_api, statsd_client)
|
||||
return fake_client
|
||||
|
||||
|
||||
def test_send_sms(fake_client, mocker):
|
||||
mock_send = mocker.patch.object(fake_client, 'try_send_sms')
|
||||
|
||||
fake_client.send_sms(
|
||||
to='to',
|
||||
content='content',
|
||||
reference='reference',
|
||||
international=False,
|
||||
)
|
||||
|
||||
mock_send.assert_called_with(
|
||||
'to', 'content', 'reference', False, None
|
||||
)
|
||||
|
||||
|
||||
def test_send_sms_error(fake_client, mocker):
|
||||
mocker.patch.object(
|
||||
fake_client, 'try_send_sms', side_effect=SmsClientResponseException('error')
|
||||
)
|
||||
|
||||
with pytest.raises(SmsClientResponseException):
|
||||
fake_client.send_sms(
|
||||
to='to',
|
||||
content='content',
|
||||
reference='reference',
|
||||
international=False,
|
||||
)
|
||||
Reference in New Issue
Block a user