From e9f9c952a617b4dba41ca65118330885ea8e9b32 Mon Sep 17 00:00:00 2001 From: watifee Date: Thu, 25 Jun 2026 13:47:02 +0000 Subject: [PATCH] Add health endpoint tests for ai_agent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - test_health_returns_200 — asserts 200 status code - test_health_response_body — asserts {"status": "ok"} body - test_health_works_without_api_key — verifies endpoint works with OPENAI_API_KEY absent (no mocks) --- apps/ai_agent/pyproject.toml | 9 +++++++++ apps/ai_agent/tests/__init__.py | 0 apps/ai_agent/tests/test_health.py | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 apps/ai_agent/tests/__init__.py create mode 100644 apps/ai_agent/tests/test_health.py diff --git a/apps/ai_agent/pyproject.toml b/apps/ai_agent/pyproject.toml index 080f8d8..02d9e1d 100644 --- a/apps/ai_agent/pyproject.toml +++ b/apps/ai_agent/pyproject.toml @@ -10,3 +10,12 @@ dependencies = [ "openai>=1.0.0", "weaviate-client>=4.0.0", ] + +[dependency-groups] +dev = [ + "pytest>=8.0.0", + "httpx>=0.27.0", +] + +[tool.pytest.ini_options] +pythonpath = ["."] diff --git a/apps/ai_agent/tests/__init__.py b/apps/ai_agent/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/ai_agent/tests/test_health.py b/apps/ai_agent/tests/test_health.py new file mode 100644 index 0000000..01e33a5 --- /dev/null +++ b/apps/ai_agent/tests/test_health.py @@ -0,0 +1,22 @@ +from fastapi.testclient import TestClient + +from main import app + +client = TestClient(app) + + +def test_health_returns_200(): + response = client.get("/health") + assert response.status_code == 200 + + +def test_health_response_body(): + response = client.get("/health") + assert response.json() == {"status": "ok"} + + +def test_health_works_without_api_key(monkeypatch): + monkeypatch.delenv("OPENAI_API_KEY", raising=False) + response = client.get("/health") + assert response.status_code == 200 + assert response.json() == {"status": "ok"}