diff --git a/scripts/add_chats.py b/scripts/add_chats.py index c180d8a4..d840888c 100644 --- a/scripts/add_chats.py +++ b/scripts/add_chats.py @@ -20,7 +20,7 @@ def main(): data={ "username": username, "password": os.environ.get( - "AI_PROXY_DEMO_AUTHENTICATION_PASSWORD", username + "RAGNA_DEMO_AUTHENTICATION_PASSWORD", username ), }, ) diff --git a/tests/deploy/api/test_e2e.py b/tests/deploy/api/test_e2e.py index 04994c8e..fab90756 100644 --- a/tests/deploy/api/test_e2e.py +++ b/tests/deploy/api/test_e2e.py @@ -1,31 +1,24 @@ import json import os -import httpx import httpx_sse import pytest +from fastapi.testclient import TestClient -from ragna._utils import timeout_after from ragna.core._utils import default_user from ragna.deploy import Config -from tests.utils import ragna_api +from ragna.deploy._api import app -@pytest.mark.parametrize("database", ["memory", "sqlite"]) @pytest.mark.parametrize("stream_answer", [True, False]) -def test_e2e(tmp_local_root, database, stream_answer): - if database == "memory": - database_url = "memory" - elif database == "sqlite": - database_url = f"sqlite:///{tmp_local_root / 'ragna.db'}" - +def test_e2e(tmp_local_root, stream_answer): config = Config( - local_cache_root=tmp_local_root, api=dict(database_url=database_url) + local_cache_root=tmp_local_root, + api=dict(database_url=f"sqlite:///{tmp_local_root / 'ragna.db'}"), ) check_api(config, stream_answer=stream_answer) -@timeout_after() def check_api(config, *, stream_answer): document_root = config.local_cache_root / "documents" document_root.mkdir() @@ -33,7 +26,7 @@ def check_api(config, *, stream_answer): with open(document_path, "w") as file: file.write("!\n") - with ragna_api(config), httpx.Client(base_url=config.api.url) as client: + with TestClient(app(config)) as client: username = default_user() token = ( client.post( @@ -41,7 +34,7 @@ def check_api(config, *, stream_answer): data={ "username": username, "password": os.environ.get( - "AI_PROXY_DEMO_AUTHENTICATION_PASSWORD", username + "RAGNA_DEMO_AUTHENTICATION_PASSWORD", username ), }, ) diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index fbf07c02..00000000 --- a/tests/utils.py +++ /dev/null @@ -1,49 +0,0 @@ -import contextlib -import socket -import subprocess -import sys -import time - -import httpx - -from ragna._utils import timeout_after - - -@contextlib.contextmanager -def background_subprocess(*args, stdout=sys.stdout, stderr=sys.stdout, **kwargs): - process = subprocess.Popen(*args, stdout=stdout, stderr=stderr, **kwargs) - try: - yield process - finally: - process.kill() - process.communicate() - - -def get_available_port(): - with socket.socket() as s: - s.bind(("", 0)) - return s.getsockname()[1] - - -@contextlib.contextmanager -def ragna_api(config): - config_path = config.local_cache_root / "ragna.toml" - if not config_path.exists(): - config.to_file(config_path) - - cmd = [sys.executable, "-m", "ragna", "api", "--config", str(config_path)] - - with background_subprocess(cmd): - - @timeout_after(message="Unable to start ragna api") - def wait_for_ragna_api(poll=0.1): - url = config.api.url - while True: - with contextlib.suppress(httpx.ConnectError): - response = httpx.get(url) - if response.is_success: - return url - - time.sleep(poll) - - yield wait_for_ragna_api()