-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Use an app factory pattern to enable app testing #495
Conversation
@@ -14,14 +14,23 @@ jobs: | |||
fail-fast: false | |||
matrix: | |||
os: ["ubuntu-20.04"] | |||
python_version: ["3.8", "3.9", "3.10", "3.11"] | |||
python_version: ["3.9", "3.10", "3.11"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing 3.8 since we don't currently support it (due to our typing syntax). We can add it back if its an issue for customers.
run: | | ||
cd ./app/frontend | ||
npm install | ||
npm run build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be built since the Flask tests try to hit up index.html
|
||
@bp.route("/assets/<path:path>") | ||
def assets(path): | ||
return send_from_directory("static/assets", path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a security upgrade over the previous route that used send_static_file for arbitrary paths.
def ask(): | ||
if not request.json: | ||
return jsonify({"error": "request must be json"}), 400 | ||
if not request.is_json: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug, caught by the new tests. Calling request.json causes an immediate 415 HTTP error if theres no JSON passed in, thus it's now request.is_json.
Great improvement, this will cause a few merge conflicts with existing PRs, but that can't be avoided |
Use an app factory pattern to enable app testing (Azure-Samples#495)
* Run ruff, add to precommit * Blueprint * Change to blueprint, app factory * Fixing the imports * Build frontend * Update startup * Update startup * Gunicorn command update * Revert yaml change
Purpose
This PR changes app.py to use an app factory pattern (create_app) along with a Flask Blueprint to organize the code. This makes testing much easier and is a general best practice.
This PR is based off the previous PR that ruff-linted the files, so that needs to be merged first to isolate the changes. Then I'll turn the draft into an actual PR.
Does this introduce a breaking change?
Pull Request Type
What kind of change does this Pull Request introduce?
How to Test