Files
GlitchupBot/tests/test_glitchtip_client.py
Verum 03aa7805d1
Some checks failed
CI / Lint (ruff + mypy) (push) Failing after 36s
CI / Run tests (push) Has been skipped
CI / Docker build test (push) Successful in 21s
тесты и фкисы клиента
2026-03-30 17:02:03 +07:00

64 lines
1.8 KiB
Python

import httpx
import pytest
from glitchup_bot.glitchtip_client.client import GlitchTipClient
@pytest.mark.asyncio
async def test_list_issues_retries_without_query_params_on_422() -> None:
attempts: list[dict[str, str | int]] = []
def handler(request: httpx.Request) -> httpx.Response:
attempts.append(dict(request.url.params))
if len(attempts) < 3:
return httpx.Response(422, request=request, json={"detail": "bad query"})
return httpx.Response(
200,
request=request,
json=[
{"id": "1", "status": "unresolved", "title": "keep"},
{"id": "2", "status": "resolved", "title": "drop"},
],
headers={"link": ""},
)
client = GlitchTipClient()
client._client = httpx.AsyncClient(
base_url=client.base_url,
headers=client.headers,
transport=httpx.MockTransport(handler),
)
try:
issues = await client.list_issues("backend-production")
finally:
await client.close()
assert [issue["id"] for issue in issues] == ["1"]
assert attempts == [
{"query": "is:unresolved", "sort": "date", "limit": "100"},
{"query": "is:unresolved", "limit": "100"},
{"limit": "100"},
]
@pytest.mark.asyncio
async def test_list_issues_preserves_non_422_errors() -> None:
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(500, request=request, json={"detail": "server error"})
client = GlitchTipClient()
client._client = httpx.AsyncClient(
base_url=client.base_url,
headers=client.headers,
transport=httpx.MockTransport(handler),
)
try:
with pytest.raises(httpx.HTTPStatusError):
await client.list_issues("backend-production")
finally:
await client.close()