From baae2fddeb549e93421ff78b9798e340a81a9cf5 Mon Sep 17 00:00:00 2001 From: Thephaseless Date: Fri, 13 Sep 2024 18:28:36 +0000 Subject: [PATCH] use fastapi to test --- Dockerfile | 5 +++-- tests/main_test.py | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7e43e77..842b769 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,8 @@ COPY novnc.sh . RUN ./novnc.sh ENV DISPLAY=:1.0 -COPY . . +COPY fix_nodriver.py ./ RUN . /app/.venv/bin/activate && python fix_nodriver.py - +COPY . . +RUN /usr/local/share/desktop-init.sh && poetry run pytest CMD /usr/local/share/desktop-init.sh && . /app/.venv/bin/activate && python main.py \ No newline at end of file diff --git a/tests/main_test.py b/tests/main_test.py index 421fb87..f6050f5 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -1,18 +1,25 @@ -import pytest +from http import HTTPStatus -from main import read_item +import pytest +from starlette.testclient import TestClient + +from main import app from src.models.requests import LinkRequest +client = TestClient(app) + test_websites = [ "https://ext.to/", "https://btmet.com/", "https://extratorrent.st/", "https://idope.se/", ] -pytest_plugins = ("pytest_asyncio",) @pytest.mark.parametrize("website", test_websites) -@pytest.mark.asyncio -async def test_bypass(website: str): - await read_item(LinkRequest(url=website, maxTimeout=5, cmd="")) +def test_bypass(website: str): + response = client.post( + "/v1", + json=LinkRequest(url=website, maxTimeout=60, cmd="request.get").model_dump(), + ) + assert response.status_code == HTTPStatus.OK