test: cover auth and SMS flows
This commit is contained in:
30
tests/test_kavenegar_client.py
Normal file
30
tests/test_kavenegar_client.py
Normal 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")
|
||||
|
||||
Reference in New Issue
Block a user