feat(sms): add selectable provider strategy

This commit is contained in:
2026-07-14 09:45:40 +03:30
parent 2264b7fc95
commit e382c4f93a
10 changed files with 171 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ import pytest
from gapido_auth.domain.errors import ExternalServiceError
from gapido_auth.infrastructure.kavenegar_client import KavenegarSmsClient
from gapido_auth.infrastructure.sms_ir_client import SmsIrSmsClient
@pytest.mark.asyncio
@@ -28,3 +29,29 @@ async def test_kavenegar_api_error() -> None:
with pytest.raises(ExternalServiceError):
await client.send_otp("989120000000", "123456", "login-otp")
@pytest.mark.asyncio
async def test_sms_ir_success() -> None:
def handler(request: httpx.Request) -> httpx.Response:
assert request.url == "https://api.sms.ir/v1/send/verify"
assert request.headers["x-api-key"] == "sms-ir-key"
payload = request.read()
assert b'"mobile":"989120000000"' in payload
assert b'"templateId":570574' in payload
assert b'"name":"OTP"' in payload
assert b'"value":"123456"' in payload
return httpx.Response(200, json={"status": "1"})
client = SmsIrSmsClient("sms-ir-key", transport=httpx.MockTransport(handler))
await client.send_otp("989120000000", "123456", "570574")
@pytest.mark.asyncio
async def test_sms_ir_api_error() -> None:
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(200, json={"status": "0"})
client = SmsIrSmsClient("sms-ir-key", transport=httpx.MockTransport(handler))
with pytest.raises(ExternalServiceError):
await client.send_otp("989120000000", "123456", "570574")