errors
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import json
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from app.mywhoosh.client import (
|
||||
MyWhooshAuthError,
|
||||
MyWhooshClient,
|
||||
MyWhooshDeviceConflictError,
|
||||
MyWhooshIntegrationError,
|
||||
MyWhooshTransientError,
|
||||
)
|
||||
@@ -44,6 +47,42 @@ async def test_invalid_credentials_raise_auth_error(tmp_path) -> None:
|
||||
await client.login("rider@example.com", "bad")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_device_conflict_message_raises_device_conflict_error(tmp_path) -> None:
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
return httpx.Response(
|
||||
200, json={"Success": False, "Message": "You are already logged in from another device."}
|
||||
)
|
||||
|
||||
client = MyWhooshClient(
|
||||
MyWhooshTokenStore(tmp_path / "mywhoosh.json"),
|
||||
http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)),
|
||||
)
|
||||
with pytest.raises(MyWhooshDeviceConflictError):
|
||||
await client.login("rider@example.com", "secret")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_reuses_stable_device_id_across_calls(tmp_path) -> None:
|
||||
seen_device_ids = []
|
||||
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen_device_ids.append(json.loads(request.content)["DeviceId"])
|
||||
return httpx.Response(
|
||||
200,
|
||||
json={"Success": True, "AccessToken": "access", "RefreshToken": "refresh", "WhooshId": "w-1"},
|
||||
)
|
||||
|
||||
store = MyWhooshTokenStore(tmp_path / "mywhoosh.json")
|
||||
client = MyWhooshClient(store, http_client=httpx.AsyncClient(transport=httpx.MockTransport(handler)))
|
||||
await client.login("rider@example.com", "secret")
|
||||
await client.login("rider@example.com", "secret")
|
||||
|
||||
assert len(seen_device_ids) == 2
|
||||
assert seen_device_ids[0] == seen_device_ids[1]
|
||||
assert seen_device_ids[0] == store.get_or_create_device_id()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_login_returns_json_array_raises_integration_error(tmp_path) -> None:
|
||||
async def handler(request: httpx.Request) -> httpx.Response:
|
||||
|
||||
Reference in New Issue
Block a user