-
-
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 click typing and added test for bad responses
- Loading branch information
Showing
11 changed files
with
79 additions
and
13 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
terminal = Terminal() | ||
|
||
|
||
@click.option( | ||
@click.option( # type: ignore | ||
"-p", | ||
"--port", | ||
type=int, | ||
|
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
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,47 @@ | ||
from typing import Dict, Union | ||
|
||
import pytest | ||
from pydantic import BaseModel | ||
|
||
from esmerald import Gateway, get | ||
from esmerald.exceptions import OpenAPIException | ||
from esmerald.openapi.datastructures import OpenAPIResponse | ||
from esmerald.testclient import create_client | ||
|
||
|
||
class Item(BaseModel): | ||
sku: Union[int, str] | ||
|
||
|
||
async def test_invalid_response(test_client_factory): | ||
with pytest.raises(OpenAPIException) as raised: | ||
|
||
@get("/test", responses={"hello": {"description": "Not a valid response"}}) | ||
def read_people() -> Dict[str, str]: | ||
return {"id": "foo"} | ||
|
||
with create_client( | ||
routes=[ | ||
Gateway(handler=read_people), | ||
] | ||
) as client: | ||
client.get("/openapi.json") | ||
|
||
assert raised.value.detail == "An additional response must be an instance of OpenAPIResponse." | ||
|
||
|
||
async def test_invalid_response_status(test_client_factory): | ||
with pytest.raises(OpenAPIException) as raised: | ||
|
||
@get("/test", responses={"hello": OpenAPIResponse(model=Item)}) | ||
def read_people() -> Dict[str, str]: | ||
return {"id": "foo"} | ||
|
||
with create_client( | ||
routes=[ | ||
Gateway(handler=read_people), | ||
] | ||
) as client: | ||
client.get("/openapi.json") | ||
|
||
assert raised.value.detail == "The status is not a valid OpenAPI status response." |