diff --git a/app/main.py b/app/main.py index 3e2ee632..b11b3148 100644 --- a/app/main.py +++ b/app/main.py @@ -424,9 +424,7 @@ async def http_exception_handler(request: Request, exc: HTTPException): # For frontend routes, return appropriate HTML templates # Handle 404 errors with a custom template if exc.status_code == 404: - return _error_templates.TemplateResponse( - request, "404.html", status_code=status.HTTP_404_NOT_FOUND - ) + return _error_templates.TemplateResponse(request, "404.html", status_code=status.HTTP_404_NOT_FOUND) # For other HTTP errors, we could create specific templates or use a generic one # For now, return a simple error page diff --git a/app/views/base.py b/app/views/base.py index 0c4d2684..f3ffa157 100644 --- a/app/views/base.py +++ b/app/views/base.py @@ -174,17 +174,18 @@ def template_response_with_version(*args, **kwargs): name = args[0] if len(args) >= 2 and isinstance(args[1], dict): context = args[1] - remaining_args = args[2:] + # Old-style may have status_code as 3rd positional arg + if len(args) >= 3 and "status_code" not in kwargs: + kwargs["status_code"] = args[2] else: context = kwargs.pop("context", {}) - remaining_args = args[1:] request_obj = context.pop("request", None) if request_obj is not None: context["request"] = request_obj _inject_global_context(context) if request_obj is not None: - return original_template_response(request_obj, name, context=context, *remaining_args, **kwargs) - return original_template_response(name, context=context, *remaining_args, **kwargs) + return original_template_response(request_obj, name, context=context, **kwargs) + return original_template_response(name, context=context, **kwargs) # New-style call: (request, name, context=..., ...) if "context" in kwargs and isinstance(kwargs["context"], dict): diff --git a/tests/test_auth.py b/tests/test_auth.py index 85e047e8..d3af75ca 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -430,8 +430,8 @@ class TestLoginFunction: # Verify TemplateResponse was called with correct context mock_templates.TemplateResponse.assert_called_once() call_args = mock_templates.TemplateResponse.call_args - assert call_args[0][0] == "login.html" - context = call_args[0][1] + assert call_args[0][1] == "login.html" + context = call_args.kwargs["context"] assert context["error"] == "Test error" assert context["message"] == "Test message" @@ -450,7 +450,7 @@ class TestLoginFunction: mock_templates.TemplateResponse.assert_called_once() call_args = mock_templates.TemplateResponse.call_args - context = call_args[0][1] + context = call_args.kwargs["context"] assert context["error"] is None assert context["message"] is None diff --git a/tests/test_auth_module.py b/tests/test_auth_module.py index 233dfd5e..ba41b756 100644 --- a/tests/test_auth_module.py +++ b/tests/test_auth_module.py @@ -281,7 +281,7 @@ class TestLoginEndpoint: # Verify template was rendered with OAuth enabled mock_templates.TemplateResponse.assert_called_once() call_args = mock_templates.TemplateResponse.call_args - context = call_args[0][1] + context = call_args.kwargs["context"] assert context["show_oauth"] is True assert context["oauth_provider_name"] == "Test SSO" diff --git a/tests/test_coverage_remaining_gaps.py b/tests/test_coverage_remaining_gaps.py index b4bf96ec..e68fdb93 100644 --- a/tests/test_coverage_remaining_gaps.py +++ b/tests/test_coverage_remaining_gaps.py @@ -69,8 +69,9 @@ class TestViewsBase: context = {"request": req} template_response_with_version("template.html", context) - args, _ = mock_orig.call_args - assert args[1].get("csrf_token") == "my-csrf" + args, kwargs = mock_orig.call_args + context = kwargs.get("context", {}) + assert context.get("csrf_token") == "my-csrf" def test_kwargs_context_no_request(self): """Test kwargs context path when request is not in context.""" diff --git a/tests/test_social_login.py b/tests/test_social_login.py index f46c874f..b4b330bc 100644 --- a/tests/test_social_login.py +++ b/tests/test_social_login.py @@ -345,7 +345,7 @@ class TestLoginPageSocialProviders: mock_templates.TemplateResponse.assert_called_once() call_args = mock_templates.TemplateResponse.call_args - context = call_args.kwargs.get("context") or call_args[0][2] if len(call_args[0]) > 2 else {} + context = call_args.kwargs.get("context", {}) assert context["social_providers"] == mock_providers @pytest.mark.asyncio @@ -371,7 +371,7 @@ class TestLoginPageSocialProviders: mock_templates.TemplateResponse.assert_called_once() call_args = mock_templates.TemplateResponse.call_args - context = call_args.kwargs.get("context") or call_args[0][2] if len(call_args[0]) > 2 else {} + context = call_args.kwargs.get("context", {}) assert context["social_providers"] == {}