From 81fe4f95996d849775897e5c6dc724252a2d329d Mon Sep 17 00:00:00 2001 From: John Aziz Date: Wed, 20 Mar 2024 23:05:55 +0200 Subject: [PATCH 1/2] remove playright --- requirements-dev.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 7baff0d..179dd51 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,14 +3,12 @@ # Testing Tools pytest ephemeral-port-reserve -pytest-playwright coverage pytest-cov -axe-playwright-python pre-commit pip-tools # Linters ruff -black \ No newline at end of file +black From 2266aa47b3b0e1e298f453d8522bd269e0581738 Mon Sep 17 00:00:00 2001 From: John Aziz Date: Thu, 21 Mar 2024 00:32:37 +0200 Subject: [PATCH 2/2] use session.get() to stop 2.0 warnings --- src/flaskapp/app.py | 45 +++++++++++++++++++++++---------- src/flaskapp/database/models.py | 12 +++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/flaskapp/app.py b/src/flaskapp/app.py index 2ef2fa2..a46387e 100644 --- a/src/flaskapp/app.py +++ b/src/flaskapp/app.py @@ -49,7 +49,9 @@ def create_app(test_config=None): @app.route("/") def index(): - return jsonify({"success": True, "message": "Welcome to the test case management API"}) + return jsonify( + {"success": True, "message": "Welcome to the test case management API"} + ) # ----------------------------------------------------------------------------# # Test cases. @@ -94,7 +96,7 @@ def create_test(): @app.route("/tests/", methods=["GET"]) def get_test(test_case_id: int): - test_case = TestCase.query.get(test_case_id) + test_case = TestCase.get(test_case_id) if not test_case: abort(404, "The requested test case was not found in the database.") @@ -107,7 +109,7 @@ def update_test(test_case_id: int): if "name" not in body: abort(400, "The request body must contain 'name' field.") - test_case = TestCase.query.get(test_case_id) + test_case = TestCase.get(test_case_id) if not test_case: abort(404, "The requested test case was not found in the database.") @@ -131,14 +133,14 @@ def update_test(test_case_id: int): @app.route("/tests/", methods=["DELETE"]) def delete_test(test_case_id: int): - test_case = TestCase.query.get(test_case_id) + test_case = TestCase.get(test_case_id) if not test_case: abort(404, "The requested test case was not found in the database.") try: test_case.delete() - if not TestCase.query.get(test_case_id): + if not TestCase.get(test_case_id): return jsonify( { "success": True, @@ -155,7 +157,7 @@ def delete_test(test_case_id: int): @app.route("/executions/", methods=["GET"]) def get_executions(asset_id: int): - asset = Asset.query.get(asset_id) + asset = Asset.get(asset_id) if not asset: abort(404, "The requested asset was not found in the database.") @@ -196,7 +198,12 @@ def get_executions(asset_id: int): @app.route("/executions", methods=["POST"]) def add_execution(): body = request.get_json() - if "status" not in body or "details" not in body or "asset_id" not in body or "test_case_id" not in body: + if ( + "status" not in body + or "details" not in body + or "asset_id" not in body + or "test_case_id" not in body + ): abort( 400, "The request body must contain 'status', 'details', 'asset_id', and 'test_case_id' fields.", @@ -209,11 +216,11 @@ def add_execution(): req_asset_id = body.get("asset_id") req_test_case_id = body.get("test_case_id") - asset = Asset.query.get(req_asset_id) + asset = Asset.get(req_asset_id) if not asset: abort(404, "The asset was not found in the database.") - test_case = TestCase.query.get(req_test_case_id) + test_case = TestCase.get(req_test_case_id) if not test_case: abort(404, "The test case was not found in the database.") @@ -244,35 +251,45 @@ def add_execution(): @app.errorhandler(400) def bad_request(error): return ( - jsonify({"success": False, "error": error.code, "message": error.description}), + jsonify( + {"success": False, "error": error.code, "message": error.description} + ), error.code, ) @app.errorhandler(404) def not_found(error): return ( - jsonify({"success": False, "error": error.code, "message": error.description}), + jsonify( + {"success": False, "error": error.code, "message": error.description} + ), error.code, ) @app.errorhandler(405) def method_not_allowed(error): return ( - jsonify({"success": False, "error": error.code, "message": error.description}), + jsonify( + {"success": False, "error": error.code, "message": error.description} + ), error.code, ) @app.errorhandler(422) def unprocessable(error): return ( - jsonify({"success": False, "error": error.code, "message": error.description}), + jsonify( + {"success": False, "error": error.code, "message": error.description} + ), error.code, ) @app.errorhandler(500) def internal_server_error(error): return ( - jsonify({"success": False, "error": error.code, "message": error.description}), + jsonify( + {"success": False, "error": error.code, "message": error.description} + ), error.code, ) diff --git a/src/flaskapp/database/models.py b/src/flaskapp/database/models.py index f4b1b06..3e49fab 100644 --- a/src/flaskapp/database/models.py +++ b/src/flaskapp/database/models.py @@ -67,6 +67,10 @@ def __init__(self, name, description): self.name = name self.description = description + @staticmethod + def get(test_case_id: int): + return db.session.get(TestCase, test_case_id) + def insert(self): db.session.add(self) db.session.commit() @@ -94,6 +98,10 @@ class Asset(db.Model): def __init__(self, name): self.name = name + @staticmethod + def get(asset_id: int): + return db.session.get(Asset, asset_id) + def insert(self): db.session.add(self) db.session.commit() @@ -129,6 +137,10 @@ def __init__(self, test_case_id, asset_id, status, details): self.status = status self.details = details + @staticmethod + def get(execution_id: int): + return db.session.get(Execution, execution_id) + def insert(self): db.session.add(self) db.session.commit()