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 # ---------------------------------------------------------------------------