@@ -49,7 +49,9 @@ def create_app(test_config=None):
49
49
50
50
@app .route ("/" )
51
51
def index ():
52
- return jsonify ({"success" : True , "message" : "Welcome to the test case management API" })
52
+ return jsonify (
53
+ {"success" : True , "message" : "Welcome to the test case management API" }
54
+ )
53
55
54
56
# ----------------------------------------------------------------------------#
55
57
# Test cases.
@@ -94,7 +96,7 @@ def create_test():
94
96
95
97
@app .route ("/tests/<int:test_case_id>" , methods = ["GET" ])
96
98
def get_test (test_case_id : int ):
97
- test_case = TestCase .query . get (test_case_id )
99
+ test_case = TestCase .get (test_case_id )
98
100
99
101
if not test_case :
100
102
abort (404 , "The requested test case was not found in the database." )
@@ -107,7 +109,7 @@ def update_test(test_case_id: int):
107
109
if "name" not in body :
108
110
abort (400 , "The request body must contain 'name' field." )
109
111
110
- test_case = TestCase .query . get (test_case_id )
112
+ test_case = TestCase .get (test_case_id )
111
113
112
114
if not test_case :
113
115
abort (404 , "The requested test case was not found in the database." )
@@ -131,14 +133,14 @@ def update_test(test_case_id: int):
131
133
132
134
@app .route ("/tests/<int:test_case_id>" , methods = ["DELETE" ])
133
135
def delete_test (test_case_id : int ):
134
- test_case = TestCase .query . get (test_case_id )
136
+ test_case = TestCase .get (test_case_id )
135
137
136
138
if not test_case :
137
139
abort (404 , "The requested test case was not found in the database." )
138
140
139
141
try :
140
142
test_case .delete ()
141
- if not TestCase .query . get (test_case_id ):
143
+ if not TestCase .get (test_case_id ):
142
144
return jsonify (
143
145
{
144
146
"success" : True ,
@@ -155,7 +157,7 @@ def delete_test(test_case_id: int):
155
157
156
158
@app .route ("/executions/<int:asset_id>" , methods = ["GET" ])
157
159
def get_executions (asset_id : int ):
158
- asset = Asset .query . get (asset_id )
160
+ asset = Asset .get (asset_id )
159
161
if not asset :
160
162
abort (404 , "The requested asset was not found in the database." )
161
163
@@ -196,7 +198,12 @@ def get_executions(asset_id: int):
196
198
@app .route ("/executions" , methods = ["POST" ])
197
199
def add_execution ():
198
200
body = request .get_json ()
199
- if "status" not in body or "details" not in body or "asset_id" not in body or "test_case_id" not in body :
201
+ if (
202
+ "status" not in body
203
+ or "details" not in body
204
+ or "asset_id" not in body
205
+ or "test_case_id" not in body
206
+ ):
200
207
abort (
201
208
400 ,
202
209
"The request body must contain 'status', 'details', 'asset_id', and 'test_case_id' fields." ,
@@ -209,11 +216,11 @@ def add_execution():
209
216
req_asset_id = body .get ("asset_id" )
210
217
req_test_case_id = body .get ("test_case_id" )
211
218
212
- asset = Asset .query . get (req_asset_id )
219
+ asset = Asset .get (req_asset_id )
213
220
if not asset :
214
221
abort (404 , "The asset was not found in the database." )
215
222
216
- test_case = TestCase .query . get (req_test_case_id )
223
+ test_case = TestCase .get (req_test_case_id )
217
224
if not test_case :
218
225
abort (404 , "The test case was not found in the database." )
219
226
@@ -244,35 +251,45 @@ def add_execution():
244
251
@app .errorhandler (400 )
245
252
def bad_request (error ):
246
253
return (
247
- jsonify ({"success" : False , "error" : error .code , "message" : error .description }),
254
+ jsonify (
255
+ {"success" : False , "error" : error .code , "message" : error .description }
256
+ ),
248
257
error .code ,
249
258
)
250
259
251
260
@app .errorhandler (404 )
252
261
def not_found (error ):
253
262
return (
254
- jsonify ({"success" : False , "error" : error .code , "message" : error .description }),
263
+ jsonify (
264
+ {"success" : False , "error" : error .code , "message" : error .description }
265
+ ),
255
266
error .code ,
256
267
)
257
268
258
269
@app .errorhandler (405 )
259
270
def method_not_allowed (error ):
260
271
return (
261
- jsonify ({"success" : False , "error" : error .code , "message" : error .description }),
272
+ jsonify (
273
+ {"success" : False , "error" : error .code , "message" : error .description }
274
+ ),
262
275
error .code ,
263
276
)
264
277
265
278
@app .errorhandler (422 )
266
279
def unprocessable (error ):
267
280
return (
268
- jsonify ({"success" : False , "error" : error .code , "message" : error .description }),
281
+ jsonify (
282
+ {"success" : False , "error" : error .code , "message" : error .description }
283
+ ),
269
284
error .code ,
270
285
)
271
286
272
287
@app .errorhandler (500 )
273
288
def internal_server_error (error ):
274
289
return (
275
- jsonify ({"success" : False , "error" : error .code , "message" : error .description }),
290
+ jsonify (
291
+ {"success" : False , "error" : error .code , "message" : error .description }
292
+ ),
276
293
error .code ,
277
294
)
278
295
0 commit comments