Skip to content

Commit e0e3212

Browse files
authored
Merge pull request #3 from john0isaac/flask-2.0-warnings
Flask 2.0 warnings
2 parents 9b632b1 + 2266aa4 commit e0e3212

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

requirements-dev.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# Testing Tools
44
pytest
55
ephemeral-port-reserve
6-
pytest-playwright
76
coverage
87
pytest-cov
9-
axe-playwright-python
108

119
pre-commit
1210
pip-tools
1311

1412
# Linters
1513
ruff
16-
black
14+
black

src/flaskapp/app.py

+31-14
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def create_app(test_config=None):
4949

5050
@app.route("/")
5151
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+
)
5355

5456
# ----------------------------------------------------------------------------#
5557
# Test cases.
@@ -94,7 +96,7 @@ def create_test():
9496

9597
@app.route("/tests/<int:test_case_id>", methods=["GET"])
9698
def get_test(test_case_id: int):
97-
test_case = TestCase.query.get(test_case_id)
99+
test_case = TestCase.get(test_case_id)
98100

99101
if not test_case:
100102
abort(404, "The requested test case was not found in the database.")
@@ -107,7 +109,7 @@ def update_test(test_case_id: int):
107109
if "name" not in body:
108110
abort(400, "The request body must contain 'name' field.")
109111

110-
test_case = TestCase.query.get(test_case_id)
112+
test_case = TestCase.get(test_case_id)
111113

112114
if not test_case:
113115
abort(404, "The requested test case was not found in the database.")
@@ -131,14 +133,14 @@ def update_test(test_case_id: int):
131133

132134
@app.route("/tests/<int:test_case_id>", methods=["DELETE"])
133135
def delete_test(test_case_id: int):
134-
test_case = TestCase.query.get(test_case_id)
136+
test_case = TestCase.get(test_case_id)
135137

136138
if not test_case:
137139
abort(404, "The requested test case was not found in the database.")
138140

139141
try:
140142
test_case.delete()
141-
if not TestCase.query.get(test_case_id):
143+
if not TestCase.get(test_case_id):
142144
return jsonify(
143145
{
144146
"success": True,
@@ -155,7 +157,7 @@ def delete_test(test_case_id: int):
155157

156158
@app.route("/executions/<int:asset_id>", methods=["GET"])
157159
def get_executions(asset_id: int):
158-
asset = Asset.query.get(asset_id)
160+
asset = Asset.get(asset_id)
159161
if not asset:
160162
abort(404, "The requested asset was not found in the database.")
161163

@@ -196,7 +198,12 @@ def get_executions(asset_id: int):
196198
@app.route("/executions", methods=["POST"])
197199
def add_execution():
198200
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+
):
200207
abort(
201208
400,
202209
"The request body must contain 'status', 'details', 'asset_id', and 'test_case_id' fields.",
@@ -209,11 +216,11 @@ def add_execution():
209216
req_asset_id = body.get("asset_id")
210217
req_test_case_id = body.get("test_case_id")
211218

212-
asset = Asset.query.get(req_asset_id)
219+
asset = Asset.get(req_asset_id)
213220
if not asset:
214221
abort(404, "The asset was not found in the database.")
215222

216-
test_case = TestCase.query.get(req_test_case_id)
223+
test_case = TestCase.get(req_test_case_id)
217224
if not test_case:
218225
abort(404, "The test case was not found in the database.")
219226

@@ -244,35 +251,45 @@ def add_execution():
244251
@app.errorhandler(400)
245252
def bad_request(error):
246253
return (
247-
jsonify({"success": False, "error": error.code, "message": error.description}),
254+
jsonify(
255+
{"success": False, "error": error.code, "message": error.description}
256+
),
248257
error.code,
249258
)
250259

251260
@app.errorhandler(404)
252261
def not_found(error):
253262
return (
254-
jsonify({"success": False, "error": error.code, "message": error.description}),
263+
jsonify(
264+
{"success": False, "error": error.code, "message": error.description}
265+
),
255266
error.code,
256267
)
257268

258269
@app.errorhandler(405)
259270
def method_not_allowed(error):
260271
return (
261-
jsonify({"success": False, "error": error.code, "message": error.description}),
272+
jsonify(
273+
{"success": False, "error": error.code, "message": error.description}
274+
),
262275
error.code,
263276
)
264277

265278
@app.errorhandler(422)
266279
def unprocessable(error):
267280
return (
268-
jsonify({"success": False, "error": error.code, "message": error.description}),
281+
jsonify(
282+
{"success": False, "error": error.code, "message": error.description}
283+
),
269284
error.code,
270285
)
271286

272287
@app.errorhandler(500)
273288
def internal_server_error(error):
274289
return (
275-
jsonify({"success": False, "error": error.code, "message": error.description}),
290+
jsonify(
291+
{"success": False, "error": error.code, "message": error.description}
292+
),
276293
error.code,
277294
)
278295

src/flaskapp/database/models.py

+12
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def __init__(self, name, description):
6767
self.name = name
6868
self.description = description
6969

70+
@staticmethod
71+
def get(test_case_id: int):
72+
return db.session.get(TestCase, test_case_id)
73+
7074
def insert(self):
7175
db.session.add(self)
7276
db.session.commit()
@@ -94,6 +98,10 @@ class Asset(db.Model):
9498
def __init__(self, name):
9599
self.name = name
96100

101+
@staticmethod
102+
def get(asset_id: int):
103+
return db.session.get(Asset, asset_id)
104+
97105
def insert(self):
98106
db.session.add(self)
99107
db.session.commit()
@@ -129,6 +137,10 @@ def __init__(self, test_case_id, asset_id, status, details):
129137
self.status = status
130138
self.details = details
131139

140+
@staticmethod
141+
def get(execution_id: int):
142+
return db.session.get(Execution, execution_id)
143+
132144
def insert(self):
133145
db.session.add(self)
134146
db.session.commit()

0 commit comments

Comments
 (0)