From a74e0395deec2da101bbcc9aa05bdb2a00dd843e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Wersd=C3=B6rfer?= Date: Sat, 2 Sep 2023 08:12:16 +0200 Subject: [PATCH] #105 log that htmx target was None instead of raising a ValueError because on theme change it is and that's ok + test modification --- cast/models/index_pages.py | 2 +- tests/blog_index_test.py | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cast/models/index_pages.py b/cast/models/index_pages.py index 51ca610e..d6e4556b 100644 --- a/cast/models/index_pages.py +++ b/cast/models/index_pages.py @@ -102,7 +102,7 @@ def get_template(self, request: HtmxHttpRequest, *args, **kwargs) -> str: if request.htmx.target is not None: template_name = target_to_template_name[request.htmx.target] else: - raise ValueError("HTMX target is None") + logger.warning("HTMX target is None") template = f"cast/{template_base_dir}/{template_name}" return template diff --git a/tests/blog_index_test.py b/tests/blog_index_test.py index ae93e4ae..16143dc3 100644 --- a/tests/blog_index_test.py +++ b/tests/blog_index_test.py @@ -69,10 +69,9 @@ def test_session_template_base_dir_overwrites_blog_setting(self, simple_request) template = blog.get_template(simple_request) assert chosen_base_dir in template - def test_blog_use_partial_template_for_htmx_request_without_target(self, htmx_request_without_target): - blog = Blog() - with pytest.raises(ValueError, match="HTMX target is None"): - blog.get_template(htmx_request_without_target) + def test_blog_use_partial_template_for_htmx_request_without_target(self, caplog, htmx_request_without_target): + Blog().get_template(htmx_request_without_target) + assert "HTMX target is None" in caplog.text def test_blog_use_partial_template_for_htmx_request(self, htmx_request): blog = Blog()