Skip to content

Commit

Permalink
Fix falcon async test (#221)
Browse files Browse the repository at this point in the history
* fix async falcon

* release 0.9.2
  • Loading branch information
kemingy authored Apr 26, 2022
1 parent 23d16e2 commit 7ff3541
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name="spectree",
version="0.9.1",
version="0.9.2",
license="Apache-2.0",
author="Keming Yang",
author_email="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ class NoResponseView:
resp=Response(HTTP_200=None), # response is None
)
def on_get(self, req, resp):
return {}
pass

@api.validate(
json=JSON, # resp is missing completely
)
def on_post(self, req, resp, json: JSON):
return {}
pass


app = App()
Expand Down
42 changes: 36 additions & 6 deletions tests/test_plugin_falcon_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from .common import JSON, Cookies, Headers, Query, Resp, StrDict, api_tag

App = pytest.importorskip("falcon.asgi.App", reason="Missing required Falcon 3.0")
pytest.importorskip("falcon", minversion="3.0.0", reason="Missing required Falcon 3.0")
from falcon.asgi import App # noqa: E402


def before_handler(req, resp, err, instance):
Expand Down Expand Up @@ -86,10 +87,28 @@ async def on_post(
resp.media = {"name": req.context.json.name, "score": score}


class NoResponseView:

name = "no response view"

@api.validate(
resp=Response(HTTP_200=None), # response is None
)
async def on_get(self, req, resp):
pass

@api.validate(
json=JSON, # resp is missing completely
)
async def on_post(self, req, resp, json: JSON):
pass


app = App()
app.add_route("/ping", Ping())
app.add_route("/api/user/{name}", UserScore())
app.add_route("/api/user_annotated/{name}", UserScoreAnnotated())
app.add_route("/api/no_response", NoResponseView())
api.register(app)


Expand All @@ -98,6 +117,21 @@ def client():
return testing.TestClient(app)


def test_falcon_no_response(client):
resp = client.simulate_request(
"GET",
"/api/no_response",
)
assert resp.status_code == 200

resp = client.simulate_request(
"POST",
"/api/no_response",
json=dict(name="foo", limit=1),
)
assert resp.status_code == 200


def test_falcon_validate(client):
resp = client.simulate_request(
"GET", "/ping", headers={"Content-Type": "text/plain"}
Expand Down Expand Up @@ -162,11 +196,7 @@ def test_client_and_api(request):
class Ping:
name = "health check"

@api.validate(
headers=Headers,
tags=["test", "health"],
validation_error_status=request.param["validation_error_status_override"],
)
@api.validate(**endpoint_kwargs)
async def on_get(self, req, resp):
"""summary
Expand Down

0 comments on commit 7ff3541

Please sign in to comment.