2022-03-25 13:05:23 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from app.clients.sms import SmsClient, SmsClientResponseException
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def fake_client(notify_api):
|
|
|
|
|
class FakeSmsClient(SmsClient):
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
2023-08-29 14:54:30 -07:00
|
|
|
return "fake"
|
2022-03-25 13:05:23 +00:00
|
|
|
|
2024-01-04 09:00:41 -05:00
|
|
|
def init_app(self, current_app, *args, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def send_sms(self, *args, **kwargs):
|
|
|
|
|
pass
|
|
|
|
|
|
2022-03-25 13:05:23 +00:00
|
|
|
fake_client = FakeSmsClient()
|
2023-04-25 07:50:56 -07:00
|
|
|
# fake_client.init_app(notify_api)
|
2022-03-25 13:05:23 +00:00
|
|
|
return fake_client
|
|
|
|
|
|
2022-10-14 14:45:27 +00:00
|
|
|
|
2022-03-25 13:05:23 +00:00
|
|
|
def test_send_sms(fake_client, mocker):
|
2023-08-29 14:54:30 -07:00
|
|
|
mock_send = mocker.patch.object(fake_client, "send_sms")
|
2022-03-25 13:05:23 +00:00
|
|
|
|
|
|
|
|
fake_client.send_sms(
|
2023-08-29 14:54:30 -07:00
|
|
|
to="to",
|
|
|
|
|
content="content",
|
|
|
|
|
reference="reference",
|
2022-03-25 13:05:23 +00:00
|
|
|
international=False,
|
2023-08-29 14:54:30 -07:00
|
|
|
sender="testing",
|
2022-03-25 13:05:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
mock_send.assert_called_with(
|
2023-08-29 14:54:30 -07:00
|
|
|
to="to",
|
|
|
|
|
content="content",
|
|
|
|
|
reference="reference",
|
|
|
|
|
international=False,
|
|
|
|
|
sender="testing",
|
2022-03-25 13:05:23 +00:00
|
|
|
)
|
|
|
|
|
|
2022-10-14 14:45:27 +00:00
|
|
|
|
2022-03-25 13:05:23 +00:00
|
|
|
def test_send_sms_error(fake_client, mocker):
|
|
|
|
|
mocker.patch.object(
|
2023-08-29 14:54:30 -07:00
|
|
|
fake_client, "send_sms", side_effect=SmsClientResponseException("error")
|
2022-03-25 13:05:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(SmsClientResponseException):
|
|
|
|
|
fake_client.send_sms(
|
2023-08-29 14:54:30 -07:00
|
|
|
to="to",
|
|
|
|
|
content="content",
|
|
|
|
|
reference="reference",
|
2022-03-25 13:05:23 +00:00
|
|
|
international=False,
|
2022-03-29 12:37:42 +01:00
|
|
|
sender=None,
|
2022-03-25 13:05:23 +00:00
|
|
|
)
|