-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix validation of parameters requiring a body (#467)
- fix `data` and `payload` special keyword arguments so they are allowed when another method than one without a body (HEAD, GET) is available, - validate that if body-less methods are handled, form-like params are optional - validate that if only body-less methods are handled, form-like params are forbidden - fix missing call of the new validation method - fix pytest warnings
- Loading branch information
Showing
6 changed files
with
197 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from typing import Optional, Union | ||
|
||
import pytest | ||
from pydantic import BaseModel | ||
|
||
from esmerald import Esmerald, Form, Request | ||
from esmerald.exceptions import ImproperlyConfigured | ||
from esmerald.routing.gateways import Gateway | ||
from esmerald.routing.handlers import route | ||
from esmerald.testclient import EsmeraldTestClient | ||
|
||
|
||
class Model(BaseModel): | ||
id: str | ||
|
||
|
||
def test_get_and_post(): | ||
@route(methods=["GET", "POST"]) | ||
async def start(request: Request, form: Union[Model, None] = Form()) -> bytes: | ||
return b"hello world" | ||
|
||
app = Esmerald( | ||
debug=True, | ||
routes=[Gateway("/", handler=start)], | ||
) | ||
client = EsmeraldTestClient(app) | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_get_and_post_optional(): | ||
@route(methods=["GET", "POST"]) | ||
async def start(request: Request, form: Optional[Model] = Form()) -> bytes: | ||
return b"hello world" | ||
|
||
app = Esmerald( | ||
debug=True, | ||
routes=[Gateway("/", handler=start)], | ||
) | ||
client = EsmeraldTestClient(app) | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_get_and_head_form(): | ||
with pytest.raises(ImproperlyConfigured): | ||
|
||
@route(methods=["GET", "HEAD"]) | ||
async def start(form: Optional[Model] = Form()) -> bytes: | ||
return b"hello world" |
Oops, something went wrong.