fix: resolve failing tests in main
- fix(api/dropbox): _require_admin bypasses auth when AUTH_ENABLED=False, fixing all 5 TestSaveDropboxSettings failures - fix(api/onedrive): same AUTH_ENABLED bypass in _require_admin; fix one-arg update_env_file call using env_utils version for token rotation - fix(auth): update login TemplateResponse to Starlette 1.0+ API (request as first arg instead of in context dict) - fix(api/local_auth): update all TemplateResponse calls to Starlette 1.0+ API - fix(views/share): update TemplateResponse call to Starlette 1.0+ API - fix(api/billing): update TemplateResponse call to Starlette 1.0+ API - fix(tests/test_imap_tasks): mock is_private_ip for tests using imap.example.com (unresolvable in sandboxed/CI environments) - fix(tests): update TemplateResponse call_args assertions to new API (call_args.kwargs['context'] instead of call_args[0][1]) - fix(tests): update fake_original signatures in dark_mode tests Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/DocuElevate/sessions/52d7b7b7-3a71-4a96-b2b1-b675b8a6d3b4
This commit is contained in:
+3
-3
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -69,8 +69,8 @@ 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"
|
||||
_, kwargs = mock_orig.call_args
|
||||
assert kwargs["context"].get("csrf_token") == "my-csrf"
|
||||
|
||||
def test_kwargs_context_no_request(self):
|
||||
"""Test kwargs context path when request is not in context."""
|
||||
|
||||
@@ -55,8 +55,8 @@ class TestDarkModeTemplateInjection:
|
||||
|
||||
captured = {}
|
||||
|
||||
def fake_original(name, ctx, **kw):
|
||||
captured.update(ctx)
|
||||
def fake_original(request, name, **kw):
|
||||
captured.update(kw.get("context", {}))
|
||||
|
||||
with patch("app.views.base.original_template_response", side_effect=fake_original):
|
||||
mock_request = MagicMock()
|
||||
@@ -73,8 +73,8 @@ class TestDarkModeTemplateInjection:
|
||||
|
||||
captured = {}
|
||||
|
||||
def fake_original(name, ctx, **kw):
|
||||
captured.update(ctx)
|
||||
def fake_original(request, name, **kw):
|
||||
captured.update(kw.get("context", {}))
|
||||
|
||||
with patch("app.views.base.original_template_response", side_effect=fake_original):
|
||||
mock_request = MagicMock()
|
||||
|
||||
@@ -499,6 +499,7 @@ class TestPullAllInboxes:
|
||||
class TestPullInbox:
|
||||
"""Tests for pull_inbox function."""
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@patch("app.tasks.imap_tasks.save_processed_emails")
|
||||
@@ -528,6 +529,7 @@ class TestPullInbox:
|
||||
mock_mail.close.assert_called_once()
|
||||
mock_mail.logout.assert_called_once()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
def test_non_ssl_connection(self, mock_load, mock_imap_class):
|
||||
@@ -606,6 +608,7 @@ class TestPullInbox:
|
||||
# Should select INBOX as fallback
|
||||
assert any(call_args[0][0] == "INBOX" for call_args in mock_mail.select.call_args_list)
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
def test_search_failure_handling(self, mock_load, mock_imap_class):
|
||||
@@ -632,6 +635,7 @@ class TestPullInbox:
|
||||
mock_mail.close.assert_called_once()
|
||||
mock_mail.logout.assert_called_once()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.fetch_attachments_and_enqueue")
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@@ -674,6 +678,7 @@ class TestPullInbox:
|
||||
mock_mail.store.assert_called_with(b"1", "-FLAGS", "\\Seen")
|
||||
mock_save.assert_called()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.fetch_attachments_and_enqueue")
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@@ -917,6 +922,7 @@ class TestPullInbox:
|
||||
# Should not process the message
|
||||
mock_mail.store.assert_not_called()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
def test_handles_fetch_failure(self, mock_load, mock_imap_class):
|
||||
@@ -1019,6 +1025,7 @@ class TestPullInbox:
|
||||
# Processed emails cache should still be updated
|
||||
mock_save.assert_called()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.fetch_attachments_and_enqueue")
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@@ -1378,6 +1385,7 @@ class TestAcquireReleaseLockEdgeCases:
|
||||
class TestPullInboxEdgeCases:
|
||||
"""Test edge cases for pull_inbox function."""
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.settings")
|
||||
@@ -1428,6 +1436,7 @@ class TestPullInboxEdgeCases:
|
||||
# Should skip processing since no Message-ID
|
||||
mock_fetch.assert_not_called()
|
||||
|
||||
@patch("app.tasks.imap_tasks.is_private_ip", new=lambda _: False)
|
||||
@patch("app.tasks.imap_tasks.load_processed_emails")
|
||||
@patch("app.tasks.imap_tasks.imaplib.IMAP4_SSL")
|
||||
@patch("app.tasks.imap_tasks.settings")
|
||||
|
||||
@@ -345,7 +345,7 @@ class TestLoginPageSocialProviders:
|
||||
|
||||
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["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[0][1]
|
||||
context = call_args.kwargs["context"]
|
||||
assert context["social_providers"] == {}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user