From 2247115a7e91006b4292e38d26f2bba2d82d71a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 19:07:57 +0000 Subject: [PATCH] test: add coverage for mail_sources_page TemplateResponse fix Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/bf182279-fe6a-4efc-87a5-5eaefabd2e3a Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- backend/app/tests/test_mail_sources.py | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/backend/app/tests/test_mail_sources.py b/backend/app/tests/test_mail_sources.py index 1ad9488..079457a 100644 --- a/backend/app/tests/test_mail_sources.py +++ b/backend/app/tests/test_mail_sources.py @@ -2,6 +2,7 @@ Tests for MailSource model and mail-sources API endpoints. """ +import asyncio from unittest.mock import MagicMock, patch import pytest @@ -494,6 +495,32 @@ class TestSourceToResponse: assert response.password is None +# --------------------------------------------------------------------------- +# HTML page route – mail_sources_page +# --------------------------------------------------------------------------- + + +def test_mail_sources_page_template_response(): + """Verify mail_sources_page uses the new-style TemplateResponse(request, name) API. + + Regression test for the 500 error caused by the old-style + ``TemplateResponse("mail_sources.html", {"request": request})`` call, which + passed a dict as the template name and triggered + ``TypeError: unhashable type: 'dict'`` in Jinja2's LRU cache. + """ + from app.main import mail_sources_page # module-level route function + + mock_request = MagicMock() + with patch("app.main.templates") as mock_templates: + mock_response = MagicMock() + mock_templates.TemplateResponse.return_value = mock_response + + result = asyncio.run(mail_sources_page(mock_request)) + + mock_templates.TemplateResponse.assert_called_once_with(mock_request, "mail_sources.html") + assert result is mock_response + + # --------------------------------------------------------------------------- # Pytest marker to avoid warnings for test methods without assertions # ---------------------------------------------------------------------------