1
+ import pytest
2
+
1
3
from labthings .server .view import builder
2
4
from labthings .server import fields
3
5
6
+ from labthings .server .semantics .base import Semantic
7
+
4
8
5
9
def test_property_of_no_schema (app , client ):
6
10
obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
@@ -77,6 +81,50 @@ def test_property_of_name_description():
77
81
assert GeneratedClass .summary == "property description"
78
82
79
83
84
+ def test_property_of_semtype_string ():
85
+ obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
86
+ GeneratedClass = builder .property_of (
87
+ obj , "property_name" , name = "property_name" , semtype = "SemanticType"
88
+ )
89
+
90
+ assert GeneratedClass .semtype == "SemanticType"
91
+
92
+
93
+ def test_property_of_semtype_semantic ():
94
+ obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
95
+
96
+ semantic_annotation = Semantic ()
97
+
98
+ GeneratedClass = builder .property_of (
99
+ obj , "property_name" , name = "property_name" , semtype = semantic_annotation
100
+ )
101
+
102
+ assert GeneratedClass .semtype == "Semantic"
103
+
104
+
105
+ def test_property_of_semtype_invalid ():
106
+ obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
107
+
108
+ semantic_annotation = object
109
+
110
+ with pytest .raises (TypeError ):
111
+ GeneratedClass = builder .property_of (
112
+ obj , "property_name" , name = "property_name" , semtype = semantic_annotation
113
+ )
114
+
115
+
116
+ def test_action_from (debug_app , debug_client ):
117
+ def f ():
118
+ return "response"
119
+
120
+ GeneratedClass = builder .action_from (f )
121
+ debug_app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
122
+
123
+ with debug_client as c :
124
+ response = c .post ("/" ).json
125
+ assert "status" in response
126
+
127
+
80
128
def test_action_from_with_args (app , client ):
81
129
def f (arg1 , arg2 = 0 ):
82
130
return {"arg1" : arg1 , "arg2" : arg2 }
@@ -93,19 +141,20 @@ def f(arg1, arg2=0):
93
141
assert response ["input" ] == input_json
94
142
95
143
96
- def test_action_from ( debug_app , debug_client ):
144
+ def test_action_from_with_schema ( app , client ):
97
145
def f ():
98
146
return "response"
99
147
100
- GeneratedClass = builder .action_from (f )
101
- debug_app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
148
+ GeneratedClass = builder .action_from (f , schema = fields . String () )
149
+ app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
102
150
103
- with debug_client as c :
151
+ with client as c :
104
152
response = c .post ("/" ).json
105
153
assert "status" in response
154
+ assert response ["output" ] == "response"
106
155
107
156
108
- def test_action_from_options (app ):
157
+ def test_action_from_with_options (app ):
109
158
def f ():
110
159
return "response"
111
160
@@ -118,6 +167,36 @@ def f():
118
167
)
119
168
120
169
170
+ def test_action_from_semtype_string ():
171
+ def f ():
172
+ return "response"
173
+
174
+ GeneratedClass = builder .action_from (f , semtype = "SemanticType" )
175
+
176
+ assert GeneratedClass .semtype == "SemanticType"
177
+
178
+
179
+ def test_action_from_semtype_semantic ():
180
+ def f ():
181
+ return "response"
182
+
183
+ semantic_annotation = Semantic ()
184
+
185
+ GeneratedClass = builder .action_from (f , semtype = semantic_annotation )
186
+
187
+ assert GeneratedClass .semtype == "Semantic"
188
+
189
+
190
+ def test_action_from_semtype_invalid ():
191
+ def f ():
192
+ return "response"
193
+
194
+ semantic_annotation = object
195
+
196
+ with pytest .raises (TypeError ):
197
+ GeneratedClass = builder .action_from (f , semtype = semantic_annotation )
198
+
199
+
121
200
def test_static_from (app , client , app_ctx , static_path ):
122
201
123
202
GeneratedClass = builder .static_from (static_path ,)
0 commit comments