Skip to content

Commit 6eb71ed

Browse files
author
Joel Collins
committed
Update tests
1 parent 5ec94ee commit 6eb71ed

File tree

2 files changed

+50
-56
lines changed

2 files changed

+50
-56
lines changed

tests/old_api/test_server_spec_td.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,21 @@ def test_td_action_with_schema(
7474

7575
with app_ctx.test_request_context():
7676
assert "index" in thing_description.to_dict().get("actions")
77-
d = {
78-
"title": "ViewClass",
79-
"description": "",
80-
"links": [{"href": "/"}],
81-
"safe": False,
82-
"idempotent": False,
83-
"forms": [
84-
{"op": ["invokeaction"], "href": "/", "contentType": "application/json"}
85-
],
86-
"input": {
87-
"properties": {
88-
"integer": {
89-
"title": "integer",
90-
"type": "number",
91-
"format": "integer",
92-
}
93-
},
94-
"type": "object",
95-
},
96-
"@type": "ToggleAction",
97-
}
77+
9878
assert thing_description.to_dict().get("actions").get("index") == {
9979
"title": "ViewClass",
10080
"description": "",
10181
"links": [{"href": "/"}],
10282
"safe": False,
10383
"idempotent": False,
10484
"forms": [
105-
{"op": ["invokeaction"], "href": "/", "contentType": "application/json"}
85+
{
86+
"op": ["invokeaction"],
87+
"htv:methodName": "POST",
88+
"href": "/",
89+
"contentType": "application/json",
90+
"response": {"contentType": "application/json"},
91+
}
10692
],
10793
"input": {
10894
"type": "object",
@@ -135,9 +121,7 @@ class Index(View):
135121
def get(self):
136122
return "GET"
137123

138-
Index.__apispec__ = {
139-
"_propertySchema": fields.Int(required=True),
140-
}
124+
Index.schema = fields.Int(required=True)
141125

142126
app.add_url_rule("/", view_func=Index.as_view("index"))
143127
rules = app.url_map._rules_by_endpoint["index"]
@@ -168,10 +152,10 @@ def get(self):
168152

169153
def test_td_property_write_only(helpers, app, thing_description, app_ctx, schemas_path):
170154
class Index(View):
171-
def post(self):
172-
return "POST"
155+
def put(self):
156+
return "PUT"
173157

174-
Index.__apispec__ = {"_propertySchema": fields.Int()}
158+
Index.schema = fields.Int()
175159

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

tests/test_td.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,21 @@ def test_td_action_with_schema(
7474

7575
with app_ctx.test_request_context():
7676
assert "index" in thing_description.to_dict().get("actions")
77-
d = {
78-
"title": "ViewClass",
79-
"description": "",
80-
"links": [{"href": "/"}],
81-
"safe": False,
82-
"idempotent": False,
83-
"forms": [
84-
{"op": ["invokeaction"], "href": "/", "contentType": "application/json"}
85-
],
86-
"input": {
87-
"properties": {
88-
"integer": {
89-
"title": "integer",
90-
"type": "number",
91-
"format": "integer",
92-
}
93-
},
94-
"type": "object",
95-
},
96-
"@type": "ToggleAction",
97-
}
77+
9878
assert thing_description.to_dict().get("actions").get("index") == {
9979
"title": "ViewClass",
10080
"description": "",
10181
"links": [{"href": "/"}],
10282
"safe": False,
10383
"idempotent": False,
10484
"forms": [
105-
{"op": ["invokeaction"], "href": "/", "contentType": "application/json"}
85+
{
86+
"op": ["invokeaction"],
87+
"htv:methodName": "POST",
88+
"href": "/",
89+
"contentType": "application/json",
90+
"response": {"contentType": "application/json"},
91+
}
10692
],
10793
"input": {
10894
"type": "object",
@@ -135,9 +121,7 @@ class Index(View):
135121
def get(self):
136122
return "GET"
137123

138-
Index.__apispec__ = {
139-
"_propertySchema": fields.Int(required=True),
140-
}
124+
Index.schema = fields.Int(required=True)
141125

142126
app.add_url_rule("/", view_func=Index.as_view("index"))
143127
rules = app.url_map._rules_by_endpoint["index"]
@@ -168,10 +152,10 @@ def get(self):
168152

169153
def test_td_property_write_only(helpers, app, thing_description, app_ctx, schemas_path):
170154
class Index(View):
171-
def post(self):
172-
return "POST"
155+
def put(self):
156+
return "PUT"
173157

174-
Index.__apispec__ = {"_propertySchema": fields.Int()}
158+
Index.schema = fields.Int()
175159

176160
app.add_url_rule("/", view_func=Index.as_view("index"))
177161
rules = app.url_map._rules_by_endpoint["index"]
@@ -181,3 +165,29 @@ def post(self):
181165
with app_ctx.test_request_context():
182166
assert "index" in thing_description.to_dict().get("properties")
183167
helpers.validate_thing_description(thing_description, app_ctx, schemas_path)
168+
169+
170+
def test_td_property_post_to_write(
171+
helpers, app, thing_description, app_ctx, schemas_path
172+
):
173+
class Index(View):
174+
def post(self):
175+
return "POST"
176+
177+
app.add_url_rule("/", view_func=Index.as_view("index"))
178+
rules = app.url_map._rules_by_endpoint["index"]
179+
180+
thing_description.property(rules, Index)
181+
182+
with app_ctx.test_request_context():
183+
assert "index" in thing_description.to_dict()["properties"]
184+
assert thing_description.to_dict()["properties"]["index"]["forms"][0]["op"] == [
185+
"writeproperty"
186+
]
187+
assert (
188+
thing_description.to_dict()["properties"]["index"]["forms"][0][
189+
"htv:methodName"
190+
]
191+
== "POST"
192+
)
193+
helpers.validate_thing_description(thing_description, app_ctx, schemas_path)

0 commit comments

Comments
 (0)