Skip to content

Commit 6f09d47

Browse files
authored
use FastAPI test client for testing (#322)
1 parent eccbdf3 commit 6f09d47

File tree

3 files changed

+8
-64
lines changed

3 files changed

+8
-64
lines changed

scripts/add_chats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def main():
2020
data={
2121
"username": username,
2222
"password": os.environ.get(
23-
"AI_PROXY_DEMO_AUTHENTICATION_PASSWORD", username
23+
"RAGNA_DEMO_AUTHENTICATION_PASSWORD", username
2424
),
2525
},
2626
)

tests/deploy/api/test_e2e.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,40 @@
11
import json
22
import os
33

4-
import httpx
54
import httpx_sse
65
import pytest
6+
from fastapi.testclient import TestClient
77

8-
from ragna._utils import timeout_after
98
from ragna.core._utils import default_user
109
from ragna.deploy import Config
11-
from tests.utils import ragna_api
10+
from ragna.deploy._api import app
1211

1312

14-
@pytest.mark.parametrize("database", ["memory", "sqlite"])
1513
@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):
2215
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'}"),
2418
)
2519
check_api(config, stream_answer=stream_answer)
2620

2721

28-
@timeout_after()
2922
def check_api(config, *, stream_answer):
3023
document_root = config.local_cache_root / "documents"
3124
document_root.mkdir()
3225
document_path = document_root / "test.txt"
3326
with open(document_path, "w") as file:
3427
file.write("!\n")
3528

36-
with ragna_api(config), httpx.Client(base_url=config.api.url) as client:
29+
with TestClient(app(config)) as client:
3730
username = default_user()
3831
token = (
3932
client.post(
4033
"/token",
4134
data={
4235
"username": username,
4336
"password": os.environ.get(
44-
"AI_PROXY_DEMO_AUTHENTICATION_PASSWORD", username
37+
"RAGNA_DEMO_AUTHENTICATION_PASSWORD", username
4538
),
4639
},
4740
)

tests/utils.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)