-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix optional data payload encoding validation
- Loading branch information
Showing
11 changed files
with
179 additions
and
45 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,20 @@ | ||
from typing import Any | ||
|
||
from esmerald import params | ||
from esmerald.utils.helpers import is_class_and_subclass | ||
|
||
|
||
def is_requires_scheme(param: Any) -> bool: | ||
""" | ||
Checks if the object is a security scheme. | ||
""" | ||
return is_class_and_subclass(param, params.Requires) | ||
|
||
|
||
def is_security_scheme(param: Any) -> bool: | ||
""" | ||
Checks if the object is a security scheme. | ||
""" | ||
if not param: | ||
return False | ||
return isinstance(param, params.Security) |
This file was deleted.
Oops, something went wrong.
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 Any, Optional | ||
|
||
from pydantic import BaseModel | ||
|
||
from esmerald import Gateway, post | ||
from esmerald.testclient import create_client | ||
|
||
|
||
class User(BaseModel): | ||
username: str | ||
|
||
|
||
@post("/optional") | ||
async def create(data: Optional[User]) -> Any: | ||
return data if data else {} | ||
|
||
|
||
def test_optional(): | ||
with create_client(routes=[Gateway(handler=create)]) as client: | ||
response = client.post("/optional", json={"username": "test"}) | ||
assert response.status_code == 201 | ||
assert response.json() == {"username": "test"} | ||
|
||
response = client.post("/optional", json={}) | ||
assert response.status_code == 201 | ||
assert response.json() == {} | ||
|
||
response = client.post("/optional") | ||
assert response.status_code == 201 | ||
assert response.json() == {} | ||
|
||
|
||
@post("/union") | ||
async def create_union(data: Optional[User]) -> Any: | ||
return data if data else {} | ||
|
||
|
||
def test_union(): | ||
with create_client(routes=[Gateway(handler=create_union)]) as client: | ||
response = client.post("/union", json={"username": "test"}) | ||
assert response.status_code == 201 | ||
assert response.json() == {"username": "test"} | ||
|
||
response = client.post("/union", json={}) | ||
assert response.status_code == 201 | ||
assert response.json() == {} | ||
|
||
response = client.post("/union") | ||
assert response.status_code == 201 | ||
assert response.json() == {} |
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