Skip to content

Commit

Permalink
Finished spec TD coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Apr 16, 2020
1 parent 3267fc6 commit 16d66b6
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/test_server_spec_td.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import jsonschema
from labthings.server import fields
from labthings.server.view import View
from labthings.server.spec import td


Expand Down Expand Up @@ -124,3 +125,67 @@ def test_td_action_with_schema(app, thing_description, view_cls, app_ctx, schema
"properties": {"integer": {"type": "integer", "format": "int32"}},
}
validate_thing_description(thing_description, app_ctx, schemas_path)


def test_td_property(app, thing_description, app_ctx, schemas_path):
class Index(View):
def get(self):
return "GET"

app.add_url_rule("/", view_func=Index.as_view("index"))
rules = app.url_map._rules_by_endpoint["index"]

thing_description.property(rules, Index)

with app_ctx.test_request_context():
assert "index" in thing_description.to_dict().get("properties")
validate_thing_description(thing_description, app_ctx, schemas_path)


def test_td_property_with_schema(app, thing_description, app_ctx, schemas_path):
class Index(View):
def get(self):
return "GET"

Index.__apispec__ = {"_propertySchema": {"integer": fields.Int()}}

app.add_url_rule("/", view_func=Index.as_view("index"))
rules = app.url_map._rules_by_endpoint["index"]

thing_description.property(rules, Index)

with app_ctx.test_request_context():
assert "index" in thing_description.to_dict().get("properties")
validate_thing_description(thing_description, app_ctx, schemas_path)


def test_td_property_with_url_param(app, thing_description, app_ctx, schemas_path):
class Index(View):
def get(self):
return "GET"

app.add_url_rule("/path/<int:id>/", view_func=Index.as_view("index"))
rules = app.url_map._rules_by_endpoint["index"]

thing_description.property(rules, Index)

with app_ctx.test_request_context():
assert "index" in thing_description.to_dict().get("properties")
validate_thing_description(thing_description, app_ctx, schemas_path)


def test_td_property_write_only(app, thing_description, app_ctx, schemas_path):
class Index(View):
def post(self):
return "POST"

Index.__apispec__ = {"_propertySchema": fields.Int()}

app.add_url_rule("/", view_func=Index.as_view("index"))
rules = app.url_map._rules_by_endpoint["index"]

thing_description.property(rules, Index)

with app_ctx.test_request_context():
assert "index" in thing_description.to_dict().get("properties")
validate_thing_description(thing_description, app_ctx, schemas_path)

0 comments on commit 16d66b6

Please sign in to comment.