|
1 | 1 | import json
|
2 | 2 | import os
|
3 | 3 |
|
4 |
| -import httpx |
5 | 4 | import httpx_sse
|
6 | 5 | import pytest
|
| 6 | +from fastapi.testclient import TestClient |
7 | 7 |
|
8 |
| -from ragna._utils import timeout_after |
9 | 8 | from ragna.core._utils import default_user
|
10 | 9 | from ragna.deploy import Config
|
11 |
| -from tests.utils import ragna_api |
| 10 | +from ragna.deploy._api import app |
12 | 11 |
|
13 | 12 |
|
14 |
| -@pytest.mark.parametrize("database", ["memory", "sqlite"]) |
15 | 13 | @pytest.mark.parametrize("stream_answer", [True, False])
|
16 |
| -def test_e2e(tmp_local_root, database, stream_answer): |
17 |
| - if database == "memory": |
18 |
| - database_url = "memory" |
19 |
| - elif database == "sqlite": |
20 |
| - database_url = f"sqlite:///{tmp_local_root / 'ragna.db'}" |
21 |
| - |
| 14 | +def test_e2e(tmp_local_root, stream_answer): |
22 | 15 | config = Config(
|
23 |
| - local_cache_root=tmp_local_root, api=dict(database_url=database_url) |
| 16 | + local_cache_root=tmp_local_root, |
| 17 | + api=dict(database_url=f"sqlite:///{tmp_local_root / 'ragna.db'}"), |
24 | 18 | )
|
25 | 19 | check_api(config, stream_answer=stream_answer)
|
26 | 20 |
|
27 | 21 |
|
28 |
| -@timeout_after() |
29 | 22 | def check_api(config, *, stream_answer):
|
30 | 23 | document_root = config.local_cache_root / "documents"
|
31 | 24 | document_root.mkdir()
|
32 | 25 | document_path = document_root / "test.txt"
|
33 | 26 | with open(document_path, "w") as file:
|
34 | 27 | file.write("!\n")
|
35 | 28 |
|
36 |
| - with ragna_api(config), httpx.Client(base_url=config.api.url) as client: |
| 29 | + with TestClient(app(config)) as client: |
37 | 30 | username = default_user()
|
38 | 31 | token = (
|
39 | 32 | client.post(
|
40 | 33 | "/token",
|
41 | 34 | data={
|
42 | 35 | "username": username,
|
43 | 36 | "password": os.environ.get(
|
44 |
| - "AI_PROXY_DEMO_AUTHENTICATION_PASSWORD", username |
| 37 | + "RAGNA_DEMO_AUTHENTICATION_PASSWORD", username |
45 | 38 | ),
|
46 | 39 | },
|
47 | 40 | )
|
|
0 commit comments