"""Runtime black-box integration tests executed over the container network.""" from __future__ import annotations import json import os import urllib.error import urllib.request import pytest BACKEND_BASE_URL = os.getenv("INTEGRATION_BACKEND_URL", "http://backend:8000").rstrip( "/" ) pytestmark = pytest.mark.integration def _fetch(path: str) -> tuple[int, str]: """Fetch an endpoint and return status code and body text.""" url = f"{BACKEND_BASE_URL}{path}" request = urllib.request.Request(url=url, method="GET") try: with urllib.request.urlopen(request, timeout=5) as response: body = response.read().decode("utf-8", errors="replace") return response.status, body except urllib.error.HTTPError as exc: body = exc.read().decode("utf-8", errors="replace") return exc.code, body def test_root_endpoint_runtime() -> None: """Runtime root endpoint should return backend API message.""" status, body = _fetch("/") assert status == 200 payload = json.loads(body) assert payload == {"message": "Plex Playlist Backend API"} def test_health_endpoint_runtime() -> None: """Runtime health endpoint should report healthy database connectivity.""" status, body = _fetch("/health") assert status == 200 payload = json.loads(body) assert payload.get("status") == "healthy" assert payload.get("database") == "connected" def test_compatibility_endpoint_runtime() -> None: """Runtime compatibility endpoint should report policy check success.""" status, body = _fetch("/compatibility") assert status == 200 payload = json.loads(body) assert payload.get("ok") is True