-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from 0b01001001/release
Release 0.5.2
- Loading branch information
Showing
7 changed files
with
138 additions
and
78 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
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 |
---|---|---|
@@ -1,51 +1,50 @@ | ||
import pytest | ||
|
||
from spectree.response import DEFAULT_CODE_DESC, Response | ||
|
||
from .common import DemoModel | ||
|
||
|
||
class NormalClass: | ||
pass | ||
|
||
|
||
def test_init_response(): | ||
for args, kwargs in [ | ||
([200], {}), | ||
(["HTTP_110"], {}), | ||
([], {"HTTP_200": NormalClass}), | ||
]: | ||
with pytest.raises(AssertionError): | ||
Response(*args, **kwargs) | ||
|
||
resp = Response("HTTP_200", HTTP_201=DemoModel) | ||
assert resp.has_model() | ||
assert resp.find_model(201) == DemoModel | ||
assert DemoModel in resp.models | ||
|
||
resp = Response(HTTP_200=None, HTTP_403=DemoModel) | ||
assert resp.has_model() | ||
assert resp.find_model(403) == DemoModel | ||
assert resp.find_model(200) is None | ||
assert DemoModel in resp.models | ||
|
||
assert not Response().has_model() | ||
|
||
|
||
def test_response_spec(): | ||
resp = Response("HTTP_200", HTTP_201=DemoModel) | ||
spec = resp.generate_spec() | ||
assert spec["200"]["description"] == DEFAULT_CODE_DESC["HTTP_200"] | ||
assert spec["201"]["description"] == DEFAULT_CODE_DESC["HTTP_201"] | ||
assert spec["422"]["description"] == DEFAULT_CODE_DESC["HTTP_422"] | ||
assert ( | ||
spec["201"]["content"]["application/json"]["schema"]["$ref"].split("/")[-1] | ||
== "tests.common.DemoModel" | ||
) | ||
assert ( | ||
spec["422"]["content"]["application/json"]["schema"]["$ref"].split("/")[-1] | ||
== "spectree.models.UnprocessableEntity" | ||
) | ||
|
||
assert spec.get(200) is None | ||
assert spec.get(404) is None | ||
import pytest | ||
|
||
from spectree.response import DEFAULT_CODE_DESC, Response | ||
from spectree.utils import get_model_path_key | ||
|
||
from .common import DemoModel | ||
|
||
|
||
class NormalClass: | ||
pass | ||
|
||
|
||
def test_init_response(): | ||
for args, kwargs in [ | ||
([200], {}), | ||
(["HTTP_110"], {}), | ||
([], {"HTTP_200": NormalClass}), | ||
]: | ||
with pytest.raises(AssertionError): | ||
Response(*args, **kwargs) | ||
|
||
resp = Response("HTTP_200", HTTP_201=DemoModel) | ||
assert resp.has_model() | ||
assert resp.find_model(201) == DemoModel | ||
assert DemoModel in resp.models | ||
|
||
resp = Response(HTTP_200=None, HTTP_403=DemoModel) | ||
assert resp.has_model() | ||
assert resp.find_model(403) == DemoModel | ||
assert resp.find_model(200) is None | ||
assert DemoModel in resp.models | ||
|
||
assert not Response().has_model() | ||
|
||
|
||
def test_response_spec(): | ||
resp = Response("HTTP_200", HTTP_201=DemoModel) | ||
spec = resp.generate_spec() | ||
assert spec["200"]["description"] == DEFAULT_CODE_DESC["HTTP_200"] | ||
assert spec["201"]["description"] == DEFAULT_CODE_DESC["HTTP_201"] | ||
assert spec["422"]["description"] == DEFAULT_CODE_DESC["HTTP_422"] | ||
assert spec["201"]["content"]["application/json"]["schema"]["$ref"].split("/")[ | ||
-1 | ||
] == get_model_path_key("tests.common.DemoModel") | ||
assert spec["422"]["content"]["application/json"]["schema"]["$ref"].split("/")[ | ||
-1 | ||
] == get_model_path_key("spectree.models.UnprocessableEntity") | ||
|
||
assert spec.get(200) is None | ||
assert spec.get(404) is None |
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