Skip to content

Commit 16d66b6

Browse files
author
Joel Collins
committed
Finished spec TD coverage
1 parent 3267fc6 commit 16d66b6

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/test_server_spec_td.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import jsonschema
66
from labthings.server import fields
7+
from labthings.server.view import View
78
from labthings.server.spec import td
89

910

@@ -124,3 +125,67 @@ def test_td_action_with_schema(app, thing_description, view_cls, app_ctx, schema
124125
"properties": {"integer": {"type": "integer", "format": "int32"}},
125126
}
126127
validate_thing_description(thing_description, app_ctx, schemas_path)
128+
129+
130+
def test_td_property(app, thing_description, app_ctx, schemas_path):
131+
class Index(View):
132+
def get(self):
133+
return "GET"
134+
135+
app.add_url_rule("/", view_func=Index.as_view("index"))
136+
rules = app.url_map._rules_by_endpoint["index"]
137+
138+
thing_description.property(rules, Index)
139+
140+
with app_ctx.test_request_context():
141+
assert "index" in thing_description.to_dict().get("properties")
142+
validate_thing_description(thing_description, app_ctx, schemas_path)
143+
144+
145+
def test_td_property_with_schema(app, thing_description, app_ctx, schemas_path):
146+
class Index(View):
147+
def get(self):
148+
return "GET"
149+
150+
Index.__apispec__ = {"_propertySchema": {"integer": fields.Int()}}
151+
152+
app.add_url_rule("/", view_func=Index.as_view("index"))
153+
rules = app.url_map._rules_by_endpoint["index"]
154+
155+
thing_description.property(rules, Index)
156+
157+
with app_ctx.test_request_context():
158+
assert "index" in thing_description.to_dict().get("properties")
159+
validate_thing_description(thing_description, app_ctx, schemas_path)
160+
161+
162+
def test_td_property_with_url_param(app, thing_description, app_ctx, schemas_path):
163+
class Index(View):
164+
def get(self):
165+
return "GET"
166+
167+
app.add_url_rule("/path/<int:id>/", view_func=Index.as_view("index"))
168+
rules = app.url_map._rules_by_endpoint["index"]
169+
170+
thing_description.property(rules, Index)
171+
172+
with app_ctx.test_request_context():
173+
assert "index" in thing_description.to_dict().get("properties")
174+
validate_thing_description(thing_description, app_ctx, schemas_path)
175+
176+
177+
def test_td_property_write_only(app, thing_description, app_ctx, schemas_path):
178+
class Index(View):
179+
def post(self):
180+
return "POST"
181+
182+
Index.__apispec__ = {"_propertySchema": fields.Int()}
183+
184+
app.add_url_rule("/", view_func=Index.as_view("index"))
185+
rules = app.url_map._rules_by_endpoint["index"]
186+
187+
thing_description.property(rules, Index)
188+
189+
with app_ctx.test_request_context():
190+
assert "index" in thing_description.to_dict().get("properties")
191+
validate_thing_description(thing_description, app_ctx, schemas_path)

0 commit comments

Comments
 (0)