trymeapp/tests/test_main.py

45 lines
1.4 KiB
Python

from __future__ import annotations
from pathlib import Path
import yaml
from fastapi.testclient import TestClient
from app.config import read_app_version
def test_healthcheck_and_version(client: TestClient) -> None:
resp = client.get("/health")
assert resp.status_code == 200
data = resp.json()
assert data["status"] == "ok"
assert data["service"] == "trymeapp"
assert data["version"] == read_app_version() == "0.1"
def test_openapi_yaml_and_docs_endpoints(client: TestClient) -> None:
yaml_resp = client.get("/openapi.yaml")
assert yaml_resp.status_code == 200
parsed = yaml.safe_load(yaml_resp.text)
assert parsed["info"]["title"] == "TryMe Gaming App API"
assert parsed["info"]["version"] == "0.1"
assert "/api/v1/quizzes" in parsed["paths"]
root_openapi = Path(__file__).resolve().parent.parent / "openapi.yaml"
assert root_openapi.exists()
root_parsed = yaml.safe_load(root_openapi.read_text(encoding="utf-8"))
assert root_parsed["paths"].keys() == parsed["paths"].keys()
docs_resp = client.get("/docs")
assert docs_resp.status_code == 200
assert "swagger" in docs_resp.text.lower()
def test_brand_logo_serving(client: TestClient) -> None:
resp = client.get("/brand/2dlogo_small_64x64.png")
assert resp.status_code == 200
assert resp.headers["content-type"] == "image/png"
missing = client.get("/brand/does_not_exist.png")
assert missing.status_code == 404