Skip to content

Commit

Permalink
Fix unittests
Browse files Browse the repository at this point in the history
Create blueprint with routes together in register routes function
  • Loading branch information
buehlefs committed Feb 19, 2024
1 parent 6342dde commit 11c81e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
35 changes: 18 additions & 17 deletions muse_for_music/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,6 @@
from .user_api import register_user_api
from .api import register_api

UI_BP = Blueprint("ui_blueprint", __name__, url_prefix="/")


@UI_BP.before_request
def before_requests():
nonce = getattr(g, 'nonce', '')
if not nonce:
g.nonce = token_urlsafe(32)


@UI_BP.after_request
def inject_csp_headers(response: Response):
nonce = getattr(g, 'nonce', '')
script_nonce = f"'nonce-{nonce}'" if nonce else ""
response.headers["Content-Security-Policy"] = f"default-src 'self'; script-src {script_nonce} 'self'; style-src 'self' 'unsafe-inline'"
return response


def register_routes(app: Flask, flask_static_digest):

Expand All @@ -33,6 +16,24 @@ def register_routes(app: Flask, flask_static_digest):
register_debug_routes(app)


UI_BP = Blueprint("ui_blueprint", __name__, url_prefix="/")


@UI_BP.before_request
def before_requests():
nonce = getattr(g, 'nonce', '')
if not nonce:
g.nonce = token_urlsafe(32)


@UI_BP.after_request
def inject_csp_headers(response: Response):
nonce = getattr(g, 'nonce', '')
script_nonce = f"'nonce-{nonce}'" if nonce else ""
response.headers["Content-Security-Policy"] = f"default-src 'self'; script-src {script_nonce} 'self'; style-src 'self' 'unsafe-inline'"
return response


@UI_BP.route('/', defaults={'path': ''})
@UI_BP.route('/<path:path>')
def index(path: str):
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ sphinx-click = "^2.5.0"
line-length = 90
include = '\.pyi?$'

[tool.pytest.ini_options]
pythonpath=[
".",
]
testpaths=[
"tests",
]

[tool.sphinx]
copyright-year = 2021
enable-autodoc = true
Expand Down

0 comments on commit 11c81e6

Please sign in to comment.