test: cover auth and SMS flows

This commit is contained in:
2026-07-14 09:33:16 +03:30
parent 0bf7268d9c
commit 2264b7fc95
6 changed files with 344 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import httpx
import pytest
from gapido_auth.domain.errors import ExternalServiceError
from gapido_auth.infrastructure.kavenegar_client import KavenegarSmsClient
@pytest.mark.asyncio
async def test_kavenegar_success() -> None:
def handler(request: httpx.Request) -> httpx.Response:
assert request.url.path == "/v1/test-key/verify/lookup.json"
form = dict(item.split("=") for item in request.content.decode().split("&"))
assert form["receptor"] == "989120000000"
assert form["template"] == "login-otp"
return httpx.Response(200, json={"return": {"status": 200}})
client = KavenegarSmsClient("test-key", transport=httpx.MockTransport(handler))
await client.send_otp("989120000000", "123456", "login-otp")
@pytest.mark.asyncio
async def test_kavenegar_api_error() -> None:
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(200, json={"return": {"status": 418}})
client = KavenegarSmsClient("test-key", transport=httpx.MockTransport(handler))
with pytest.raises(ExternalServiceError):
await client.send_otp("989120000000", "123456", "login-otp")