import unittest from fastapi.testclient import TestClient from app import app as fastapi_app from server.app import app class TestServerAPI(unittest.TestCase): def setUp(self): self.client = app.test_client() def test_root_includes_new_endpoints(self): response = self.client.get("/") self.assertEqual(response.status_code, 200) payload = response.get_json() self.assertIn("/tasks", payload["endpoints"]) self.assertIn("/score", payload["endpoints"]) def test_tasks_endpoint(self): response = self.client.get("/tasks") self.assertEqual(response.status_code, 200) payload = response.get_json() self.assertIn("count", payload) self.assertIn("tasks", payload) self.assertGreaterEqual(payload["count"], 10) def test_score_endpoint(self): # Reset first so scoring context exists. self.client.get("/reset") response = self.client.get("/score") self.assertEqual(response.status_code, 200) payload = response.get_json() self.assertIn("task_score", payload) self.assertIn("current_step", payload) self.assertIn("task_id", payload) class TestFastAPIReset(unittest.TestCase): def setUp(self): self.client = TestClient(fastapi_app) def test_post_reset_without_body(self): response = self.client.post("/reset") self.assertEqual(response.status_code, 200) payload = response.json() self.assertIn("observation", payload) self.assertIn("task_description", payload["observation"]) def test_post_reset_with_task_id_body(self): response = self.client.post("/reset", json={"task_id": "bug_detection_easy_1"}) self.assertEqual(response.status_code, 200) payload = response.json() self.assertEqual(payload["observation"]["task_difficulty"], "easy") if __name__ == "__main__": unittest.main()