From bdf7248984849843566dd12d0096b06401f7a70d Mon Sep 17 00:00:00 2001 From: Alex Rudy Date: Tue, 31 Dec 2024 16:22:51 +0000 Subject: [PATCH] fix: is_active_endpoint print Remove print statement from is_active_endpoint and fix function coverage --- src/bootlace/util.py | 6 ++---- tests/test_util.py | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/bootlace/util.py b/src/bootlace/util.py index 1bb1b37..c7a945e 100644 --- a/src/bootlace/util.py +++ b/src/bootlace/util.py @@ -277,7 +277,6 @@ 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 @@ -285,11 +284,10 @@ def is_active_endpoint(endpoint: str, url_kwargs: Mapping[str, Any], ignore_quer 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 diff --git a/tests/test_util.py b/tests/test_util.py index 2ae0619..37a83ec 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -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 @@ -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",