2
2
3
3
from labthings import fields
4
4
from labthings .views import ActionView , PropertyView , View , op
5
+ from apispec .utils import validate_spec
5
6
6
7
7
8
@pytest .fixture
8
9
def thing_description (thing ):
9
10
return thing .thing_description
10
11
11
12
12
- def test_td_init (helpers , thing_description , app_ctx , schemas_path ):
13
+ def test_td_init (helpers , thing , thing_description , app_ctx , schemas_path ):
13
14
assert thing_description
14
15
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
16
+ validate_spec (thing .spec )
15
17
16
18
17
- def test_td_add_link (helpers , thing_description , view_cls , app_ctx , schemas_path ):
19
+ def test_td_add_link (helpers , thing , thing_description , view_cls , app_ctx , schemas_path ):
20
+ thing .add_view (view_cls , "/test_view_cls" )
18
21
thing_description .add_link (view_cls , "rel" )
19
22
assert {
20
23
"rel" : "rel" ,
@@ -24,9 +27,10 @@ def test_td_add_link(helpers, thing_description, view_cls, app_ctx, schemas_path
24
27
} in thing_description ._links
25
28
26
29
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
30
+ validate_spec (thing .spec )
27
31
28
32
29
- def test_td_add_link_options (thing_description , view_cls ):
33
+ def test_td_add_link_options (thing , thing_description , view_cls ):
30
34
thing_description .add_link (
31
35
view_cls , "rel" , kwargs = {"kwarg" : "kvalue" }, params = {"param" : "pvalue" }
32
36
)
@@ -36,9 +40,10 @@ def test_td_add_link_options(thing_description, view_cls):
36
40
"params" : {"param" : "pvalue" },
37
41
"kwargs" : {"kwarg" : "kvalue" },
38
42
} in thing_description ._links
43
+ validate_spec (thing .spec )
39
44
40
45
41
- def test_td_links (thing_description , app_ctx , view_cls ):
46
+ def test_td_links (thing , thing_description , app_ctx , view_cls ):
42
47
thing_description .add_link (
43
48
view_cls , "rel" , kwargs = {"kwarg" : "kvalue" }, params = {"param" : "pvalue" }
44
49
)
@@ -47,9 +52,10 @@ def test_td_links(thing_description, app_ctx, view_cls):
47
52
assert {"rel" : "rel" , "href" : "" , "kwarg" : "kvalue" } in (
48
53
thing_description .links
49
54
)
55
+ validate_spec (thing .spec )
50
56
51
57
52
- def test_td_action (helpers , app , thing_description , app_ctx , schemas_path ):
58
+ def test_td_action (helpers , thing , app , thing_description , app_ctx , schemas_path ):
53
59
class Index (ActionView ):
54
60
def post (self ):
55
61
return "POST"
@@ -62,9 +68,10 @@ def post(self):
62
68
with app_ctx .test_request_context ():
63
69
assert "index" in thing_description .to_dict ().get ("actions" )
64
70
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
71
+ validate_spec (thing .spec )
65
72
66
73
67
- def test_td_action_with_schema (helpers , app , thing_description , app_ctx , schemas_path ):
74
+ def test_td_action_with_schema (helpers , thing , app , thing_description , app_ctx , schemas_path ):
68
75
class Index (ActionView ):
69
76
args = {"integer" : fields .Int ()}
70
77
semtype = "ToggleAction"
@@ -80,9 +87,11 @@ def post(self):
80
87
with app_ctx .test_request_context ():
81
88
assert "index" in thing_description .to_dict ().get ("actions" )
82
89
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
90
+
91
+ validate_spec (thing .spec )
83
92
84
93
85
- def test_td_property (helpers , app , thing_description , app_ctx , schemas_path ):
94
+ def test_td_property (helpers , app , thing , thing_description , app_ctx , schemas_path ):
86
95
class Index (PropertyView ):
87
96
def get (self ):
88
97
return "GET"
@@ -95,10 +104,11 @@ def get(self):
95
104
with app_ctx .test_request_context ():
96
105
assert "index" in thing_description .to_dict ().get ("properties" )
97
106
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
107
+ validate_spec (thing .spec )
98
108
99
109
100
110
def test_td_property_with_schema (
101
- helpers , app , thing_description , app_ctx , schemas_path
111
+ helpers , app , thing , thing_description , app_ctx , schemas_path
102
112
):
103
113
class Index (PropertyView ):
104
114
schema = fields .Int (required = True )
@@ -114,10 +124,11 @@ def get(self):
114
124
with app_ctx .test_request_context ():
115
125
assert "index" in thing_description .to_dict ().get ("properties" )
116
126
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
127
+ validate_spec (thing .spec )
117
128
118
129
119
130
def test_td_property_with_url_param (
120
- helpers , app , thing_description , app_ctx , schemas_path
131
+ helpers , app , thing , thing_description , app_ctx , schemas_path
121
132
):
122
133
class Index (PropertyView ):
123
134
def get (self ):
@@ -131,9 +142,10 @@ def get(self):
131
142
with app_ctx .test_request_context ():
132
143
assert "index" in thing_description .to_dict ().get ("properties" )
133
144
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
145
+ validate_spec (thing .spec )
134
146
135
147
136
- def test_td_property_write_only (helpers , app , thing_description , app_ctx , schemas_path ):
148
+ def test_td_property_write_only (helpers , app , thing , thing_description , app_ctx , schemas_path ):
137
149
class Index (PropertyView ):
138
150
schema = fields .Int ()
139
151
@@ -148,10 +160,12 @@ def put(self):
148
160
with app_ctx .test_request_context ():
149
161
assert "index" in thing_description .to_dict ().get ("properties" )
150
162
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
163
+
164
+ validate_spec (thing .spec )
151
165
152
166
153
167
def test_td_property_post_to_write (
154
- helpers , app , thing_description , app_ctx , schemas_path
168
+ helpers , app , thing , thing_description , app_ctx , schemas_path
155
169
):
156
170
class Index (PropertyView ):
157
171
@op .writeproperty
@@ -177,10 +191,11 @@ def post(self):
177
191
== "POST"
178
192
)
179
193
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
194
+ validate_spec (thing .spec )
180
195
181
196
182
197
def test_td_property_different_content_type (
183
- helpers , app , thing_description , app_ctx , schemas_path
198
+ helpers , app , thing , thing_description , app_ctx , schemas_path
184
199
):
185
200
class Index (PropertyView ):
186
201
content_type = "text/plain; charset=us-ascii"
@@ -198,10 +213,11 @@ def put(self):
198
213
for form in thing_description .to_dict ()["properties" ]["index" ]["forms" ]:
199
214
assert form ["contentType" ] == "text/plain; charset=us-ascii"
200
215
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
216
+ validate_spec (thing .spec )
201
217
202
218
203
219
def test_td_action_different_response_type (
204
- helpers , app , thing_description , app_ctx , schemas_path
220
+ helpers , app , thing , thing_description , app_ctx , schemas_path
205
221
):
206
222
class Index (ActionView ):
207
223
schema = fields .Int ()
@@ -220,3 +236,4 @@ def post(self):
220
236
for form in thing_description .to_dict ()["actions" ]["index" ]["forms" ]:
221
237
assert form ["response" ]["contentType" ] == "text/plain; charset=us-ascii"
222
238
helpers .validate_thing_description (thing_description , app_ctx , schemas_path )
239
+ validate_spec (thing .spec )
0 commit comments