2025-07-07 11:55:30 -07:00
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
2025-07-07 12:27:11 -07:00
|
|
|
import pytest
|
2025-07-07 11:55:30 -07:00
|
|
|
from aiohttp import ClientError
|
|
|
|
|
|
|
|
|
|
from app.clients.pinpoint.aws_pinpoint import AwsPinpointClient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_validate_phone_number_success():
|
2025-07-07 13:38:11 -07:00
|
|
|
phone = "+1234567890"
|
2025-07-07 11:55:30 -07:00
|
|
|
mock_response = {
|
|
|
|
|
"NumberValidateResponse": {
|
|
|
|
|
"PhoneType": "MOBILE",
|
2025-07-07 13:38:11 -07:00
|
|
|
"CleansedPhoneNumberE164": phone,
|
2025-07-07 11:55:30 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
client_instance = AwsPinpointClient()
|
|
|
|
|
client_instance._client = MagicMock()
|
|
|
|
|
client_instance._client.phone_number_validate.return_value = mock_response
|
|
|
|
|
|
2025-07-07 13:38:11 -07:00
|
|
|
result = client_instance.validate_phone_number("US", phone)
|
2025-07-07 12:06:18 -07:00
|
|
|
assert result is not None
|
2025-07-07 11:55:30 -07:00
|
|
|
client_instance._client.phone_number_validate.assert_called_once_with(
|
2025-07-07 13:38:11 -07:00
|
|
|
NumberValidateRequest={"IsoCountryCode": "US", "PhoneNumber": phone}
|
2025-07-07 11:55:30 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_validate_phone_number_client_error():
|
|
|
|
|
client_instance = AwsPinpointClient()
|
|
|
|
|
client_instance._client = MagicMock()
|
|
|
|
|
client_instance._client.phone_number_validate.side_effect = ClientError(
|
|
|
|
|
{"Error": {"Code": "BadRequest1", "MEssage": "Invalid phone"}},
|
|
|
|
|
"phone number validate",
|
|
|
|
|
)
|
|
|
|
|
|
2025-07-07 12:27:11 -07:00
|
|
|
with pytest.raises(ClientError):
|
|
|
|
|
client_instance.validate_phone_number("US", "bad-number")
|