From e67375770f22474368a35dde4299f0fd11eea64c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 18:24:03 +0000 Subject: [PATCH 1/3] Initial plan From d2a557354f83d2a9cbf93eede5ee6a2bb88436af Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 29 Mar 2026 18:26:49 +0000 Subject: [PATCH 2/3] fix: correct TemplateResponse call in mail_sources_page to use new Starlette API Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/16838094-12d6-4279-9c94-58b7fb4ad3d7 Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- backend/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/main.py b/backend/app/main.py index 5a9876a..e27b1fc 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -345,7 +345,7 @@ async def settings_page(request: Request): @app.get("/mail-sources", response_class=HTMLResponse) async def mail_sources_page(request: Request): - return templates.TemplateResponse("mail_sources.html", {"request": request}) + return templates.TemplateResponse(request, "mail_sources.html") @app.get("/upload", response_class=HTMLResponse) 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 3/3] 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 # ---------------------------------------------------------------------------