Skip to content

Commit

Permalink
fix: is_active_endpoint print
Browse files Browse the repository at this point in the history
Remove print statement from is_active_endpoint and fix function coverage
  • Loading branch information
alexrudy committed Dec 31, 2024
1 parent 54c5e4a commit bdf7248
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/bootlace/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,17 @@ def converter(value: str | T) -> T:
def is_active_endpoint(endpoint: str, url_kwargs: Mapping[str, Any], ignore_query: bool = True) -> bool:
"""Check if the current request is for the given endpoint and URL kwargs"""
if request.endpoint != endpoint:
print(f"endpoint: {request.endpoint} != {endpoint}")
return False

if request.url_rule is None: # pragma: no cover
return False

try:
rule_url = request.url_rule.build(url_kwargs, append_unknown=not ignore_query)
except TypeError:
# URL rule does not support the given URL kwargs
except TypeError: # pragma: no cover
return False

if rule_url is None: # pragma: no cover
if rule_url is None:
return False

_, url = rule_url
Expand Down
10 changes: 10 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dominate import tags
from flask import Blueprint
from flask import Flask
from flask import request

from bootlace.util import as_tag
from bootlace.util import is_active_blueprint
Expand Down Expand Up @@ -161,6 +162,15 @@ def test_is_active_endpoint(app: Flask, uri: str, endpoint: str, kwargs: dict[st
assert is_active_endpoint(endpoint, kwargs) is expected


@pytest.mark.usefixtures("bp")
def test_is_active_endpoint_invalid_kwargs(app: Flask) -> None:

with app.test_request_context("/"):
assert request.endpoint == "home"
assert request.url_rule is not None
assert not is_active_endpoint("home", {"id": "a"}, ignore_query=False)


@pytest.mark.usefixtures("bp")
@pytest.mark.parametrize(
"uri,blueprint,expected",
Expand Down

0 comments on commit bdf7248

Please sign in to comment.