File size: 1,473 Bytes
985f3ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import unittest
import httpx
from backend.app.core.api import app


class TestAPIEndpoints(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self):
        self.client = httpx.AsyncClient(
            transport=httpx.ASGITransport(app=app),
            base_url="http://test"
        )

    async def asyncTearDown(self):
        await self.client.aclose()

    async def test_health_endpoint(self):
        res = await self.client.get("/health")
        self.assertEqual(res.status_code, 200)
        data = res.json()
        self.assertEqual(data.get("status"), "ok")

    async def test_config_endpoint_default(self):
        res = await self.client.get("/config")
        self.assertEqual(res.status_code, 200)
        data = res.json()
        self.assertIn("frontend_ui_dictionary", data)
        self.assertIn("client_metadata", data)

    async def test_config_endpoint_ed_donner(self):
        res = await self.client.get("/config?tutor=ed_donner")
        self.assertEqual(res.status_code, 200)
        data = res.json()
        self.assertEqual(data.get("tutor_id"), "ed_donner")
        self.assertEqual(data.get("name"), "Ed Donner")

    async def test_chat_history_endpoint(self):
        res = await self.client.get("/chat/history?session_id=test_sess_001")
        self.assertEqual(res.status_code, 200)
        data = res.json()
        self.assertEqual(data.get("session_id"), "test_sess_001")


if __name__ == "__main__":
    unittest.main()