Skip to content

Commit

Permalink
Modify unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
linziyue committed May 13, 2021
1 parent f1b68c9 commit ac337ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 3 additions & 2 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
)
def test_plugin_spec(api):
models = {
m.__name__: m.schema(ref_template="#/components/schemas/{model}")
f"{m.__module__}.{m.__name__}": m.schema(
ref_template="#/components/schemas/{model}")
for m in (Query, JSON, Resp, Cookies, Headers)
}
for name, schema in models.items():
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_plugin_spec(api):
assert user["tags"] == ["API", "test"]
assert (
user["requestBody"]["content"]["application/json"]["schema"]["$ref"]
== "#/components/schemas/JSON"
== "#/components/schemas/tests.common.JSON"
)
assert len(user["responses"]) == 3

Expand Down
4 changes: 2 additions & 2 deletions tests/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def test_response_spec():
assert spec["422"]["description"] == DEFAULT_CODE_DESC["HTTP_422"]
assert (
spec["201"]["content"]["application/json"]["schema"]["$ref"].split("/")[-1]
== "DemoModel"
== "tests.common.DemoModel"
)
assert (
spec["422"]["content"]["application/json"]["schema"]["$ref"].split("/")[-1]
== "UnprocessableEntity"
== "spectree.models.UnprocessableEntity"
)

assert spec.get(200) is None
Expand Down
12 changes: 7 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,26 @@ def test_parse_resp():
assert resp_spec["422"]["description"] == "Unprocessable Entity"
assert (
resp_spec["422"]["content"]["application/json"]["schema"]["$ref"]
== "#/components/schemas/UnprocessableEntity"
== "#/components/schemas/spectree.models.UnprocessableEntity"
)
assert (
resp_spec["200"]["content"]["application/json"]["schema"]["$ref"]
== "#/components/schemas/DemoModel"
== "#/components/schemas/tests.common.DemoModel"
)


def test_parse_request():
assert (
parse_request(demo_func)["content"]["application/json"]["schema"]["$ref"]
== "#/components/schemas/DemoModel"
== "#/components/schemas/tests.common.DemoModel"
)
assert parse_request(demo_class.demo_method) == {}


def test_parse_params():
models = {
"DemoModel": DemoModel.schema(ref_template="#/components/schemas/{model}")
"tests.common.DemoModel": DemoModel.schema(
ref_template="#/components/schemas/{model}")
}
assert parse_params(demo_func, [], models) == []
params = parse_params(demo_class.demo_method, [], models)
Expand All @@ -120,7 +121,8 @@ def test_parse_params():

def test_parse_params_with_route_param_keywords():
models = {
"DemoQuery": DemoQuery.schema(ref_template="#/components/schemas/{model}")
"tests.common.DemoQuery": DemoQuery.schema(
ref_template="#/components/schemas/{model}")
}
params = parse_params(demo_func_with_query, [], models)
assert params == [
Expand Down

0 comments on commit ac337ad

Please sign in to comment.