Skip to content

Commit

Permalink
Add external app not include to openapi testing
Browse files Browse the repository at this point in the history
* Add linting to ci
  • Loading branch information
tarsil committed Jul 12, 2023
1 parent fc3d2a5 commit f9b2168
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@ jobs:
- name: "Install dependencies"
if: steps.cache.outputs.cache-hit != 'true'
run: "scripts/install"
- name: "Run lint"
run: "scripts/lint"
- name: "Run tests"
run: "scripts/test"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dependencies = [
"pydantic>=2.0.1,<3.0.0",
"pydantic-extra-types>=2.0.0,<3.0.0",
"pydantic-settings>=2.0.0,<3.0.0",
"polyfactory>=2.5.0,<3.0.0",
"python-multipart>=0.0.5,<0.0.7",
"openapi-schemas-pydantic>=2.0.0",
"rich>=13.3.1,<14.0.0",
Expand Down Expand Up @@ -110,6 +109,7 @@ test = [
"freezegun>=1.2.2,<2.0.0",
"mock==5.0.1",
"passlib==1.7.4",
"polyfactory>=2.5.0,<3.0.0",
"python-jose>=3.3.0,<4",
"orjson>=3.8.5,<4.0.0",
"saffier[postgres]>=0.14.0",
Expand Down
74 changes: 74 additions & 0 deletions tests/openapi/test_external_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from typing import Dict, Union

from flask import Flask, request
from markupsafe import escape
from pydantic import BaseModel

from esmerald import JSON, Gateway, Include, get
from esmerald.middleware import WSGIMiddleware
from esmerald.openapi.datastructures import OpenAPIResponse
from esmerald.testclient import create_client

flask_app = Flask(__name__)


@flask_app.route("/")
def flask_main():
name = request.args.get("name", "Esmerald")
return f"Hello, {escape(name)} from Flask!"


class Item(BaseModel):
sku: Union[int, str]


@get()
def read_people() -> Dict[str, str]:
return {"id": "foo"}


@get(
"/item",
description="Read an item",
responses={200: OpenAPIResponse(model=Item, description="The SKU information of an item")},
)
async def read_item() -> JSON:
return JSON(content={"id": 1})


def test_external_app_not_include_in_schema(test_client_factory):
with create_client(
routes=[
Gateway(handler=read_people),
Include("/child", app=WSGIMiddleware(flask_app)),
]
) as client:
response = client.get("/openapi.json")
assert response.status_code == 200, response.text

assert response.json() == {
"openapi": "3.1.0",
"info": {
"title": "Esmerald",
"summary": "Esmerald application",
"description": "test_client",
"contact": {"name": "admin", "email": "[email protected]"},
"version": client.app.version,
},
"servers": [{"url": "/"}],
"paths": {
"/": {
"get": {
"summary": "Read People",
"operationId": "read_people__get",
"responses": {
"200": {
"description": "Successful response",
"content": {"application/json": {"schema": {}}},
}
},
"deprecated": False,
}
},
},
}

0 comments on commit f9b2168

Please sign in to comment.