Skip to content

Flask 2.0 warnings #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
black
45 changes: 31 additions & 14 deletions src/flaskapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -94,7 +96,7 @@ def create_test():

@app.route("/tests/<int:test_case_id>", 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.")
Expand All @@ -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.")
Expand All @@ -131,14 +133,14 @@ def update_test(test_case_id: int):

@app.route("/tests/<int:test_case_id>", 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,
Expand All @@ -155,7 +157,7 @@ def delete_test(test_case_id: int):

@app.route("/executions/<int:asset_id>", 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.")

Expand Down Expand Up @@ -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.",
Expand All @@ -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.")

Expand Down Expand Up @@ -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,
)

Expand Down
12 changes: 12 additions & 0 deletions src/flaskapp/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading