Files
stack/tests/api/conftest.py
kert 9e111e889f
All checks were successful
ci/woodpecker/push/infra-ci Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful
scaffold API client modules for homelab services
Base client extracted from bcda/client.py retry/auth pattern with
MockTransport injection for testing. Four service clients: Gitea,
Woodpecker, RustFS (S3 + admin), and Zotero — each with auth
headers and domain method stubs. 36 tests passing.
2026-02-28 20:01:29 -05:00

52 lines
1.3 KiB
Python

"""Shared fixtures for API client tests."""
from __future__ import annotations
import json
import httpx
import pytest
@pytest.fixture()
def json_response():
"""Factory for httpx.MockTransport handlers returning JSON."""
def _factory(body: object = None, status: int = 200):
payload = json.dumps(body or {}).encode()
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(
status,
content=payload,
headers={"Content-Type": "application/json"},
)
return httpx.MockTransport(handler)
return _factory
@pytest.fixture()
def capture_transport():
"""Transport that records the request and returns a JSON 200."""
class Capture:
def __init__(self):
self.requests: list[httpx.Request] = []
def transport(self, body: object = None, status: int = 200):
payload = json.dumps(body or {}).encode()
def handler(request: httpx.Request) -> httpx.Response:
self.requests.append(request)
return httpx.Response(
status,
content=payload,
headers={"Content-Type": "application/json"},
)
return httpx.MockTransport(handler)
return Capture()