4
4
from labthings .server import fields
5
5
6
6
7
- def test_dict_to_apispec_operations_no_spec (spec ):
7
+ def test_view_to_apispec_operations_no_spec (spec ):
8
8
class Index (View ):
9
+ """Index docstring"""
10
+
9
11
def get (self ):
10
12
return "GET"
11
13
12
14
def post (self ):
13
15
return "POST"
14
16
15
- assert apispec .dict_to_apispec_operations ( spec_dict [ "_operations" ] , spec ) == {
17
+ assert apispec .view_to_apispec_operations ( Index , spec ) == {
16
18
"get" : {
17
- "responses" : {200 : {"description" : "OK" }},
18
- "description" : "" ,
19
- "summary" : "" ,
20
- "tags" : set (),
19
+ "description" : "Index docstring" ,
20
+ "summary" : "Index docstring" ,
21
+ "tags" : [],
22
+ "responses" : {
23
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
24
+ },
21
25
},
22
26
"post" : {
23
- "responses" : {200 : {"description" : "OK" }},
24
- "description" : "" ,
25
- "summary" : "" ,
26
- "tags" : set (),
27
+ "description" : "Index docstring" ,
28
+ "summary" : "Index docstring" ,
29
+ "tags" : [],
30
+ "responses" : {
31
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
32
+ },
27
33
},
28
34
}
29
35
30
36
31
- def test_dict_to_apispec_operations_params (spec ):
37
+ def test_view_to_apispec_tags (spec ):
32
38
class Index (View ):
39
+ """Index docstring"""
40
+
41
+ tags = ["tag1" , "tag2" ]
42
+
33
43
def get (self ):
34
44
return "GET"
35
45
36
- spec_dict ["_operations" ]["get" ]["_params" ] = {"integer" : fields .Int ()}
46
+ def post (self ):
47
+ return "POST"
48
+
49
+ assert apispec .view_to_apispec_operations (Index , spec ) == {
50
+ "get" : {
51
+ "description" : "Index docstring" ,
52
+ "summary" : "Index docstring" ,
53
+ "tags" : ["tag1" , "tag2" ],
54
+ "responses" : {
55
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
56
+ },
57
+ },
58
+ "post" : {
59
+ "description" : "Index docstring" ,
60
+ "summary" : "Index docstring" ,
61
+ "tags" : ["tag1" , "tag2" ],
62
+ "responses" : {
63
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
64
+ },
65
+ },
66
+ }
67
+
68
+
69
+ def test_dict_to_apispec_operations_params (spec ):
70
+ class Index (View ):
71
+ """Index docstring"""
72
+
73
+ args = {"integer" : fields .Int ()}
74
+
75
+ def put (self ):
76
+ return "GET"
37
77
38
- assert (apispec .dict_to_apispec_operations (spec_dict ["_operations" ], spec ))["get" ][
39
- "requestBody"
40
- ] == {
78
+ assert (apispec .view_to_apispec_operations (Index , spec ))["put" ]["requestBody" ] == {
41
79
"content" : {
42
80
"application/json" : {
43
81
"schema" : {
@@ -51,14 +89,13 @@ def get(self):
51
89
52
90
def test_dict_to_apispec_operations_schema (spec ):
53
91
class Index (View ):
92
+
93
+ schema = {"integer" : fields .Int ()}
94
+
54
95
def get (self ):
55
96
return "GET"
56
97
57
- spec_dict ["_operations" ]["get" ]["_schema" ] = {200 : {"integer" : fields .Int ()}}
58
-
59
- assert (apispec .dict_to_apispec_operations (spec_dict ["_operations" ], spec ))["get" ][
60
- "responses"
61
- ][200 ] == {
98
+ assert apispec .view_to_apispec_operations (Index , spec )["get" ]["responses" ][200 ] == {
62
99
"description" : "OK" ,
63
100
"content" : {
64
101
"application/json" : {
@@ -71,20 +108,10 @@ def get(self):
71
108
}
72
109
73
110
74
- def test_method_to_apispec_operation_extra_fields (spec ):
75
- class Index (View ):
76
- def get (self ):
77
- return "GET"
78
-
79
- spec_dict ["_operations" ]["get" ]["summary" ] = "A summary"
80
-
81
- assert (apispec .dict_to_apispec_operations (spec_dict ["_operations" ], spec ))["get" ][
82
- "summary"
83
- ] == "A summary"
84
-
85
-
86
111
def test_rule_to_apispec_path (app , spec ):
87
112
class Index (View ):
113
+ """Index docstring"""
114
+
88
115
def get (self ):
89
116
return "GET"
90
117
@@ -94,30 +121,33 @@ def post(self):
94
121
app .add_url_rule ("/path" , view_func = Index .as_view ("index" ))
95
122
rule = app .url_map ._rules_by_endpoint ["index" ][0 ]
96
123
97
- assert apispec .rule_to_apispec_path (rule , spec_dict , spec ) == {
124
+ assert apispec .rule_to_apispec_path (rule , Index , spec ) == {
98
125
"path" : "/path" ,
99
126
"operations" : {
100
127
"get" : {
101
- "responses" : {200 : {"description" : "OK" }},
102
- "description" : "" ,
103
- "summary" : "" ,
104
- "tags" : set (),
128
+ "description" : "Index docstring" ,
129
+ "summary" : "Index docstring" ,
130
+ "tags" : [],
131
+ "responses" : {
132
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
133
+ },
105
134
},
106
135
"post" : {
107
- "responses" : {200 : {"description" : "OK" }},
108
- "description" : "" ,
109
- "summary" : "" ,
110
- "tags" : set (),
136
+ "description" : "Index docstring" ,
137
+ "summary" : "Index docstring" ,
138
+ "tags" : [],
139
+ "responses" : {
140
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
141
+ },
111
142
},
112
143
},
113
- "description" : "" ,
114
- "summary" : "" ,
115
- "tags" : set (),
116
144
}
117
145
118
146
119
147
def test_rule_to_apispec_path_params (app , spec ):
120
148
class Index (View ):
149
+ """Index docstring"""
150
+
121
151
def get (self ):
122
152
return "GET"
123
153
@@ -127,14 +157,16 @@ def post(self):
127
157
app .add_url_rule ("/path/<id>/" , view_func = Index .as_view ("index" ))
128
158
rule = app .url_map ._rules_by_endpoint ["index" ][0 ]
129
159
130
- assert apispec .rule_to_apispec_path (rule , spec_dict , spec ) == {
160
+ assert apispec .rule_to_apispec_path (rule , Index , spec ) == {
131
161
"path" : "/path/{id}/" ,
132
162
"operations" : {
133
163
"get" : {
134
- "responses" : {200 : {"description" : "OK" }},
135
- "description" : "" ,
136
- "summary" : "" ,
137
- "tags" : set (),
164
+ "description" : "Index docstring" ,
165
+ "summary" : "Index docstring" ,
166
+ "tags" : [],
167
+ "responses" : {
168
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
169
+ },
138
170
"parameters" : [
139
171
{
140
172
"in" : "path" ,
@@ -145,10 +177,12 @@ def post(self):
145
177
],
146
178
},
147
179
"post" : {
148
- "responses" : {200 : {"description" : "OK" }},
149
- "description" : "" ,
150
- "summary" : "" ,
151
- "tags" : set (),
180
+ "description" : "Index docstring" ,
181
+ "summary" : "Index docstring" ,
182
+ "tags" : [],
183
+ "responses" : {
184
+ 200 : {"description" : "OK" , "content" : {"application/json" : {}}}
185
+ },
152
186
"parameters" : [
153
187
{
154
188
"in" : "path" ,
@@ -159,7 +193,5 @@ def post(self):
159
193
],
160
194
},
161
195
},
162
- "description" : "" ,
163
- "summary" : "" ,
164
- "tags" : set (),
165
196
}
197
+
0 commit comments