3
3
from labthings .server .view import builder
4
4
5
5
6
- def test_property_of (app ):
6
+ def test_property_of (app , client ):
7
7
obj = type ("obj" , (object ,), {"property_name" : "propertyValue" })
8
8
9
9
GeneratedClass = builder .property_of (obj , "property_name" )
10
10
app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
11
11
12
- with app . test_client () as c :
12
+ with client as c :
13
13
assert c .get ("/" ).data == b"propertyValue"
14
14
assert c .post ("/" , data = b"newPropertyValue" ).data == b"newPropertyValue"
15
15
assert c .get ("/" ).data == b"newPropertyValue"
16
16
17
17
18
- def test_property_of_dict (app ):
18
+ def test_property_of_dict (app , client ):
19
19
obj = type (
20
20
"obj" ,
21
21
(object ,),
@@ -30,7 +30,7 @@ def test_property_of_dict(app):
30
30
GeneratedClass = builder .property_of (obj , "properties" )
31
31
app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
32
32
33
- with app . test_client () as c :
33
+ with client as c :
34
34
assert (
35
35
c .get ("/" ).data
36
36
== b'{"property_name":"propertyValue","property_name_2":"propertyValue2"}\n '
@@ -64,25 +64,25 @@ def test_property_of_name_description():
64
64
assert GeneratedClass .__apispec__ .get ("summary" ) == "property description"
65
65
66
66
67
- def test_action_from (app ):
67
+ def test_action_from (app , client ):
68
68
def f (arg : int , kwarg : str = "default" ):
69
69
return {"arg" : arg , "kwarg" : kwarg }
70
70
71
71
GeneratedClass = builder .action_from (f )
72
72
app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
73
73
74
- with app . test_client () as c :
74
+ with client as c :
75
75
assert c .post ("/" , json = {"arg" : 5 }).data == b'{"arg":5,"kwarg":"default"}\n '
76
76
77
77
78
- def test_action_from_task (app ):
78
+ def test_action_from_task (app , client ):
79
79
def f (arg : int , kwarg : str = "default" ):
80
80
return {"arg" : arg , "kwarg" : kwarg }
81
81
82
82
GeneratedClass = builder .action_from (f , task = True ,)
83
83
app .add_url_rule ("/" , view_func = GeneratedClass .as_view ("index" ))
84
84
85
- with app . test_client () as c :
85
+ with client as c :
86
86
response = c .post ("/" , json = {"arg" : 5 }).json
87
87
# Check we get back a Task representation
88
88
assert isinstance (response , dict )
@@ -103,15 +103,15 @@ def f(arg: int, kwarg: str = "default"):
103
103
)
104
104
105
105
106
- def test_static_from (app , app_ctx , static_path ):
106
+ def test_static_from (app , client , app_ctx , static_path ):
107
107
108
108
GeneratedClass = builder .static_from (static_path ,)
109
109
app .add_url_rule ("/static" , view_func = GeneratedClass .as_view ("index" ))
110
110
111
111
with app_ctx .test_request_context ():
112
112
assert GeneratedClass ().get ("text" ).status_code == 200
113
113
114
- with app . test_client () as c :
114
+ with client as c :
115
115
assert c .get ("/static/text" ).data == b"text"
116
116
117
117
0 commit comments