From 5c970e6cfad2b9e1dfdbef9310a322960087d075 Mon Sep 17 00:00:00 2001 From: Yifan Zhang Date: Wed, 21 Dec 2022 11:26:43 +0300 Subject: [PATCH] bugfix/application (#13) * Add unittest for bug openapi doc failure * Remove obsolete code leftover * Fix bug in applicaiton * test workflow * Add container * Use node container * Update node image version * Remove job container Co-authored-by: Yifan Zhang --- .../pytest-redis-postgres-workflow.yml | 17 ++++++----- apihub/server.py | 4 --- apihub/subscription/router.py | 2 +- tests/test_server.py | 29 +++++++++++++++++++ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pytest-redis-postgres-workflow.yml b/.github/workflows/pytest-redis-postgres-workflow.yml index 748e785..d9353aa 100644 --- a/.github/workflows/pytest-redis-postgres-workflow.yml +++ b/.github/workflows/pytest-redis-postgres-workflow.yml @@ -10,15 +10,14 @@ jobs: matrix: python-version: [3.8] - # Docker Hub image that `container-job` executes in - container: python:3.8-slim - # Service containers to run with `container-job` services: # Label used to access the service container redis: # Docker Hub image image: redis + ports: + - "6379:6379" # Set health checks to wait until redis has started options: >- --health-cmd "redis-cli ping" @@ -29,6 +28,8 @@ jobs: postgres: # Docker Hub image image: postgres + ports: + - "5432:5432" # Provide the password for postgres env: POSTGRES_USER: dbuser @@ -59,7 +60,7 @@ jobs: - name: Install dependencies run: | - poetry install + env LC_ALL=C.UTF-8 LANG=C.UTF-8 LANGUAGE=C.UTF-8 poetry install --verbose - name: Run pytests # Runs a script that creates a Redis client, populates @@ -68,10 +69,10 @@ jobs: poetry run pytest # Environment variable used by the `client.js` script to create a new Redis client. env: - REDIS: redis://redis:6379/1 - IN_REDIS: redis://redis:6379/1 - OUT_REDIS: redis://redis:6379/1 - DB_URI: "postgresql://dbuser:dbpass@postgres:5432/test" + REDIS: redis://localhost:6379/1 + IN_REDIS: redis://localhost:6379/1 + OUT_REDIS: redis://localhost:6379/1 + DB_URI: "postgresql://dbuser:dbpass@localhost:5432/test" JWT_SECRET: "nosecret" SECURITY_TOKEN_EXPIRES_DAYS: 1 SUBSCRIPTION_TOKEN_EXPIRES_DAYS: 1 diff --git a/apihub/server.py b/apihub/server.py index 9930dd4..de2bc67 100644 --- a/apihub/server.py +++ b/apihub/server.py @@ -236,10 +236,6 @@ async def async_service_result( ) -@api.post( - "/sync/{application}", - include_in_schema=False, -) def extract_components(schema, components): definitions = schema.get("definitions") if definitions: diff --git a/apihub/subscription/router.py b/apihub/subscription/router.py index bd59e30..4f1073a 100644 --- a/apihub/subscription/router.py +++ b/apihub/subscription/router.py @@ -41,7 +41,7 @@ class SubscriptionSettings(BaseSettings): @cbv(router) class ApplicationCBV: session: Session = Depends(create_session) - username: str = (Depends(require_admin),) + username: str = Depends(require_admin) @router.post("/application", response_model=ApplicationCreate) def create_application(self, application: ApplicationCreate): diff --git a/tests/test_server.py b/tests/test_server.py index 0bf732b..24e9352 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -96,3 +96,32 @@ def get(self, application): response = client.get("/redoc") assert response.status_code == 200 + +def test_openapi(client, monkeypatch): + monkeypatch.setenv("IN_KIND", "MEM") + monkeypatch.setenv("IN_NAMESPACE", "namespace") + monkeypatch.setenv("OUT_KIND", "MEM") + monkeypatch.setenv("OUT_NAMESPACE", "namespace") + import apihub.server + + class DummyDefinition(BaseModel): + input_schema: Dict[str, Any] + + class Input(BaseModel): + text: str + probability: float + + def _get_definition_manager(): + class DummyDefinitionManager: + def get(self, application): + return DummyDefinition(input_schema=Input.schema()) + + return DummyDefinitionManager() + + monkeypatch.setattr( + apihub.server, "get_definition_manager", _get_definition_manager + ) + + schema = apihub.server.custom_openapi() + + assert schema["info"]["title"] == "APIHub" \ No newline at end of file