-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable json_schema for other types, add tests for this where not redu…
…ndant, update README
- Loading branch information
1 parent
4c6aa5e
commit 80ef751
Showing
10 changed files
with
177 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,19 @@ def test_str_alias(client): | |
assert r.json["value"] == "abc" | ||
|
||
|
||
def test_str_json_schema(client): | ||
url = "/form/str/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, data={"v": "[email protected]"}) | ||
assert "v" in r.json | ||
assert r.json["v"] == "[email protected]" | ||
# Test that input failing schema yields error | ||
r = client.post(url, data={"v": "not an email"}) | ||
assert "error" in r.json | ||
|
||
|
||
|
||
|
||
# Int Validation | ||
def test_required_int(client): | ||
url = "/form/int/required" | ||
|
@@ -258,6 +271,17 @@ def test_int_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_int_json_schema(client): | ||
url = "/form/int/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, data={"v": 10}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 10 | ||
# Test that input failing schema yields error | ||
r = client.post(url, data={"v": 100}) | ||
assert "error" in r.json | ||
|
||
|
||
# Bool Validation | ||
def test_required_bool(client): | ||
url = "/form/bool/required" | ||
|
@@ -382,6 +406,17 @@ def test_float_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_float_json_schema(client): | ||
url = "/form/float/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, data={"v": 3.14}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 3.14 | ||
# Test that input failing schema yields error | ||
r = client.post(url, data={"v": 3.141592}) | ||
assert "error" in r.json | ||
|
||
|
||
# datetime Validation | ||
def test_required_datetime(client): | ||
url = "/form/datetime/required" | ||
|
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 |
---|---|---|
|
@@ -146,6 +146,17 @@ def test_str_alias(client): | |
assert r.json["value"] == "abc" | ||
|
||
|
||
def test_str_json_schema(client): | ||
url = "/json/str/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, json={"v": "[email protected]"}) | ||
assert "v" in r.json | ||
assert r.json["v"] == "[email protected]" | ||
# Test that input failing schema yields error | ||
r = client.post(url, json={"v": "not an email"}) | ||
assert "error" in r.json | ||
|
||
|
||
# Int Validation | ||
def test_required_int(client): | ||
url = "/json/int/required" | ||
|
@@ -236,6 +247,17 @@ def test_int_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_int_json_schema(client): | ||
url = "/json/int/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, json={"v": 10}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 10 | ||
# Test that input failing schema yields error | ||
r = client.post(url, json={"v": 100}) | ||
assert "error" in r.json | ||
|
||
|
||
# Bool Validation | ||
def test_required_bool(client): | ||
url = "/json/bool/required" | ||
|
@@ -360,6 +382,17 @@ def test_float_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_float_json_schema(client): | ||
url = "/json/float/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.post(url, json={"v": 3.14}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 3.14 | ||
# Test that input failing schema yields error | ||
r = client.post(url, json={"v": 3.141592}) | ||
assert "error" in r.json | ||
|
||
|
||
# datetime Validation | ||
def test_required_datetime(client): | ||
url = "/json/datetime/required" | ||
|
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 |
---|---|---|
|
@@ -406,6 +406,17 @@ def test_str_alias_async_decorator(client): | |
assert r.json["value"] == "abc" | ||
|
||
|
||
def test_str_json_schema(client): | ||
url = "/query/str/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.get(url, query_string={"v": "[email protected]"}) | ||
assert "v" in r.json | ||
assert r.json["v"] == "[email protected]" | ||
# Test that input failing schema yields error | ||
r = client.get(url, query_string={"v": "not an email"}) | ||
assert "error" in r.json | ||
|
||
|
||
# Int Validation | ||
def test_required_int(client): | ||
url = "/query/int/required" | ||
|
@@ -524,6 +535,17 @@ def test_int_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_int_json_schema(client): | ||
url = "/query/int/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.get(url, query_string={"v": 10}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 10 | ||
# Test that input failing schema yields error | ||
r = client.get(url, query_string={"v": 100}) | ||
assert "error" in r.json | ||
|
||
|
||
# Bool Validation | ||
def test_required_bool(client): | ||
url = "/query/bool/required" | ||
|
@@ -736,6 +758,16 @@ def test_float_func(client): | |
assert "error" in r.json | ||
|
||
|
||
def test_float_json_schema(client): | ||
url = "/query/float/json_schema" | ||
# Test that input matching schema yields input | ||
r = client.get(url, query_string={"v": 3.14}) | ||
assert "v" in r.json | ||
assert r.json["v"] == 3.14 | ||
# Test that input failing schema yields error | ||
r = client.get(url, query_string={"v": 3.141592}) | ||
assert "error" in r.json | ||
|
||
# datetime Validation | ||
def test_required_datetime(client): | ||
url = "/query/datetime/required" | ||
|
Oops, something went wrong.