|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.asyncio |
| 7 | +async def test_index(test_client): |
| 8 | + """test the index route""" |
| 9 | + response = test_client.get("/") |
| 10 | + |
| 11 | + html_index_file_path = "src/static/index.html" |
| 12 | + with open(html_index_file_path, "rb") as f: |
| 13 | + html_index_file = f.read() |
| 14 | + |
| 15 | + assert response.status_code == 200 |
| 16 | + assert response.headers["Content-Type"] == "text/html; charset=utf-8" |
| 17 | + assert response.headers["Content-Length"] == str(len(html_index_file)) |
| 18 | + assert html_index_file == response.content |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.asyncio |
| 22 | +async def test_favicon(test_client): |
| 23 | + """test the favicon route""" |
| 24 | + response = test_client.get("/favicon.ico") |
| 25 | + |
| 26 | + favicon_file_path = "src/static/favicon.ico" |
| 27 | + with open(favicon_file_path, "rb") as f: |
| 28 | + favicon_file = f.read() |
| 29 | + |
| 30 | + assert response.status_code == 200 |
| 31 | + assert response.headers["Content-Type"] == "image/vnd.microsoft.icon" |
| 32 | + assert response.headers["Content-Length"] == str(len(favicon_file)) |
| 33 | + assert favicon_file == response.content |
| 34 | + |
| 35 | + |
| 36 | +@pytest.mark.asyncio |
| 37 | +async def test_assets_non_existent_404(test_client): |
| 38 | + """test the assets route with a non-existent file""" |
| 39 | + response = test_client.get("/assets/manifest.json") |
| 40 | + |
| 41 | + assert response.status_code == 404 |
| 42 | + assert response.headers["Content-Type"] == "application/json" |
| 43 | + assert response.headers["Content-Length"] == "22" |
| 44 | + assert b'{"detail":"Not Found"}' in response.content |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.asyncio |
| 48 | +async def test_assets(test_client): |
| 49 | + """test the assets route with an existing file""" |
| 50 | + assets_dir_path = "src/static/assets" |
| 51 | + assets_file_path = os.listdir(assets_dir_path)[0] |
| 52 | + |
| 53 | + with open(os.path.join(assets_dir_path, assets_file_path), "rb") as f: |
| 54 | + assets_file = f.read() |
| 55 | + |
| 56 | + response = test_client.get(f"/assets/{assets_file_path}") |
| 57 | + |
| 58 | + assert response.status_code == 200 |
| 59 | + assert response.headers["Content-Length"] == str(len(assets_file)) |
| 60 | + assert assets_file == response.content |
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.asyncio |
| 64 | +async def test_chat_non_json_415(test_client): |
| 65 | + """test the chat route with a non-json request""" |
| 66 | + response = test_client.post("/chat") |
| 67 | + |
| 68 | + assert response.status_code == 422 |
| 69 | + assert response.headers["Content-Type"] == "application/json" |
| 70 | + assert response.headers["Content-Length"] == "82" |
| 71 | + assert b'{"detail":[{"type":"missing"' in response.content |
0 commit comments