Skip to content

Commit

Permalink
Updated TD tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jun 23, 2020
1 parent 097f506 commit 5d2be38
Showing 1 changed file with 15 additions and 41 deletions.
56 changes: 15 additions & 41 deletions tests/test_server_spec_td.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,6 @@ def thing_description(thing):
return thing.thing_description


def test_find_schema_for_view_readonly():
class ViewClass:
def get(self):
pass

ViewClass.get.__apispec__ = {"_schema": {200: "schema"}}
assert td.find_schema_for_view(ViewClass) == "schema"


def test_find_schema_for_view_writeonly_post():
class ViewClass:
def post(self):
pass

ViewClass.post.__apispec__ = {"_params": "params"}
assert td.find_schema_for_view(ViewClass) == "params"


def test_find_schema_for_view_writeonly_put():
class ViewClass:
def put(self):
pass

ViewClass.put.__apispec__ = {"_params": "params"}
assert td.find_schema_for_view(ViewClass) == "params"


def test_find_schema_for_view_none():
class ViewClass:
pass

assert td.find_schema_for_view(ViewClass) == {}


def test_td_init(helpers, thing_description, app_ctx, schemas_path):
assert thing_description
helpers.validate_thing_description(thing_description, app_ctx, schemas_path)
Expand Down Expand Up @@ -98,10 +64,8 @@ def test_td_action(helpers, app, thing_description, view_cls, app_ctx, schemas_p
def test_td_action_with_schema(
helpers, app, thing_description, view_cls, app_ctx, schemas_path
):
view_cls.post.__apispec__ = {
"_params": {"integer": fields.Int()},
"@type": "ToggleAction",
}
view_cls.args = {"integer": fields.Int()}
view_cls.semtype = "ToggleAction"

app.add_url_rule("/", view_func=view_cls.as_view("index"))
rules = app.url_map._rules_by_endpoint["index"]
Expand All @@ -110,9 +74,19 @@ def test_td_action_with_schema(

with app_ctx.test_request_context():
assert "index" in thing_description.to_dict().get("actions")
assert thing_description.to_dict().get("actions").get("index").get("input") == {
"type": "object",
"properties": {"integer": {"type": "integer", "format": "int32"}},
assert thing_description.to_dict().get("actions").get("index") == {
"title": "ViewClass",
"description": "",
"links": [{"href": "/"}],
"safe": False,
"idempotent": False,
"forms": [
{"op": ["invokeaction"], "href": "/", "contentType": "application/json"}
],
"input": {
"type": "object",
"properties": {"integer": {"type": "integer", "format": "int32"}},
},
"@type": "ToggleAction",
}
helpers.validate_thing_description(thing_description, app_ctx, schemas_path)
Expand Down

0 comments on commit 5d2be38

Please sign in to comment.