Skip to content

Commit

Permalink
bugfix/application (#13)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
yifan and Yifan Zhang authored Dec 21, 2022
1 parent 3ee9d49 commit 5c970e6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/pytest-redis-postgres-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -29,6 +28,8 @@ jobs:
postgres:
# Docker Hub image
image: postgres
ports:
- "5432:5432"
# Provide the password for postgres
env:
POSTGRES_USER: dbuser
Expand Down Expand Up @@ -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
Expand All @@ -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
4 changes: 0 additions & 4 deletions apihub/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion apihub/subscription/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 5c970e6

Please sign in to comment.