-
-
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.
* Add missing types * Update internal for generics * Add compatibility for list and object in query * Add fix for dict in query string * Add hashing for unique types * Add tests for OpenAPI types * Fix dependency tests and logic
- Loading branch information
Showing
8 changed files
with
469 additions
and
65 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
Empty file.
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,109 @@ | ||
from esmerald import Gateway, JSONResponse, get | ||
from esmerald.testclient import create_client | ||
|
||
|
||
@get("/bool") | ||
async def check_bool(a_value: bool) -> JSONResponse: | ||
return JSONResponse({"value": a_value}) | ||
|
||
|
||
def test_query_param(test_client_factory): | ||
with create_client(routes=Gateway(handler=check_bool)) as client: | ||
|
||
response = client.get("/bool?a_value=true") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == {"value": True} | ||
|
||
response = client.get("/bool?a_value=1") | ||
assert response.json() == {"value": True} | ||
|
||
response = client.get("/bool?a_value=0") | ||
assert response.json() == {"value": False} | ||
|
||
response = client.get("/bool?a_value=false") | ||
assert response.json() == {"value": False} | ||
|
||
|
||
def test_open_api(test_app_client_factory): | ||
with create_client(routes=Gateway(handler=check_bool)) 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": "Highly scalable, performant, easy to learn and for every application.", | ||
"contact": {"name": "admin", "email": "[email protected]"}, | ||
"version": client.app.version, | ||
}, | ||
"servers": [{"url": "/"}], | ||
"paths": { | ||
"/bool": { | ||
"get": { | ||
"summary": "Check Bool", | ||
"operationId": "check_bool_bool_get", | ||
"parameters": [ | ||
{ | ||
"name": "a_value", | ||
"in": "query", | ||
"required": True, | ||
"deprecated": False, | ||
"allowEmptyValue": False, | ||
"allowReserved": False, | ||
"schema": {"type": "boolean", "title": "A Value"}, | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "Successful response", | ||
"content": {"application/json": {"schema": {"type": "string"}}}, | ||
}, | ||
"422": { | ||
"description": "Validation Error", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HTTPValidationError" | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
"deprecated": False, | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"HTTPValidationError": { | ||
"properties": { | ||
"detail": { | ||
"items": {"$ref": "#/components/schemas/ValidationError"}, | ||
"type": "array", | ||
"title": "Detail", | ||
} | ||
}, | ||
"type": "object", | ||
"title": "HTTPValidationError", | ||
}, | ||
"ValidationError": { | ||
"properties": { | ||
"loc": { | ||
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, | ||
"type": "array", | ||
"title": "Location", | ||
}, | ||
"msg": {"type": "string", "title": "Message"}, | ||
"type": {"type": "string", "title": "Error Type"}, | ||
}, | ||
"type": "object", | ||
"required": ["loc", "msg", "type"], | ||
"title": "ValidationError", | ||
}, | ||
} | ||
}, | ||
} |
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,102 @@ | ||
from typing import Any, Dict | ||
|
||
from esmerald import Gateway, JSONResponse, get | ||
from esmerald.testclient import create_client | ||
|
||
|
||
@get("/dict") | ||
async def check_dict(a_value: Dict[str, Any]) -> JSONResponse: | ||
return JSONResponse({"value": a_value}) | ||
|
||
|
||
def test_query_param(test_client_factory): | ||
with create_client(routes=Gateway(handler=check_dict)) as client: | ||
response = client.get("/dict?a_value=true&b_value=false&c_value=test") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == { | ||
"value": {"a_value": "true", "b_value": "false", "c_value": "test"} | ||
} | ||
|
||
|
||
def test_open_api(test_app_client_factory): | ||
with create_client(routes=Gateway(handler=check_dict)) 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": "Highly scalable, performant, easy to learn and for every application.", | ||
"contact": {"name": "admin", "email": "[email protected]"}, | ||
"version": client.app.version, | ||
}, | ||
"servers": [{"url": "/"}], | ||
"paths": { | ||
"/dict": { | ||
"get": { | ||
"summary": "Check Dict", | ||
"operationId": "check_dict_dict_get", | ||
"parameters": [ | ||
{ | ||
"name": "a_value", | ||
"in": "query", | ||
"required": True, | ||
"deprecated": False, | ||
"allowEmptyValue": False, | ||
"allowReserved": False, | ||
"schema": {"type": "object", "title": "A Value"}, | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "Successful response", | ||
"content": {"application/json": {"schema": {"type": "string"}}}, | ||
}, | ||
"422": { | ||
"description": "Validation Error", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HTTPValidationError" | ||
} | ||
} | ||
}, | ||
}, | ||
}, | ||
"deprecated": False, | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"HTTPValidationError": { | ||
"properties": { | ||
"detail": { | ||
"items": {"$ref": "#/components/schemas/ValidationError"}, | ||
"type": "array", | ||
"title": "Detail", | ||
} | ||
}, | ||
"type": "object", | ||
"title": "HTTPValidationError", | ||
}, | ||
"ValidationError": { | ||
"properties": { | ||
"loc": { | ||
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]}, | ||
"type": "array", | ||
"title": "Location", | ||
}, | ||
"msg": {"type": "string", "title": "Message"}, | ||
"type": {"type": "string", "title": "Error Type"}, | ||
}, | ||
"type": "object", | ||
"required": ["loc", "msg", "type"], | ||
"title": "ValidationError", | ||
}, | ||
} | ||
}, | ||
} |
Oops, something went wrong.