feat(tests): add comprehensive test coverage for 9 modules (complete)
Complete implementation of comprehensive pytest test coverage for PR #273: Enhanced test files: - test_upload_email.py: 20+ tests for email upload (get_email_template, extract_metadata, attach_logo, prepare_recipients, send_email, task execution) - test_api_settings.py: 15+ tests for settings API (require_admin, all endpoints, Pydantic models) - test_upload_google_drive.py: 25+ tests (OAuth, service account, metadata handling, truncation, error cases) - test_views_settings.py: 15+ tests (require_admin_access decorator, settings page logic, source determination, masking) - test_upload_ftp_additional.py: 18+ tests (FTPS/plaintext, security, directory creation, error handling) - test_security_headers.py: 20+ tests (middleware initialization, dispatch, all headers, configuration) - test_check_credentials.py: 20+ tests (MockRequest, failure state, sync wrappers, full task logic, notifications, recovery) - test_views_status.py: 20+ tests (status dashboard, env debug, Docker detection, Git SHA, container info) - test_api_azure_comprehensive.py: 30+ tests (connection success/failure, all error types, operations parsing) Total: ~180+ new tests added across 9 modules Target: Reach ≥80% coverage for each module Known issue: Celery task mocking pattern needs final adjustment for bound tasks (self parameter handling) Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
+15
-20
@@ -283,11 +283,10 @@ class TestUploadToEmailTask:
|
||||
mock_send_email.return_value = None
|
||||
|
||||
# Create a mock task with request context
|
||||
task = upload_to_email
|
||||
task.request = Mock()
|
||||
task.request.id = "test-task-id"
|
||||
mock_self = Mock()
|
||||
mock_self.request.id = "test-task-id"
|
||||
|
||||
result = task("/tmp/test.pdf", recipients=["recipient@example.com"])
|
||||
result = upload_to_email(mock_self, "/tmp/test.pdf", recipients=["recipient@example.com"])
|
||||
|
||||
assert result["status"] == "Completed"
|
||||
assert result["file"] == "/tmp/test.pdf"
|
||||
@@ -299,12 +298,11 @@ class TestUploadToEmailTask:
|
||||
"""Test raises error when file not found."""
|
||||
mock_exists.return_value = False
|
||||
|
||||
task = upload_to_email
|
||||
task.request = Mock()
|
||||
task.request.id = "test-task-id"
|
||||
mock_self = Mock()
|
||||
mock_self.request.id = "test-task-id"
|
||||
|
||||
with pytest.raises(FileNotFoundError):
|
||||
task("/nonexistent/file.pdf")
|
||||
upload_to_email(mock_self, "/nonexistent/file.pdf")
|
||||
|
||||
@patch("app.tasks.upload_to_email.log_task_progress")
|
||||
@patch("app.tasks.upload_to_email.os.path.exists")
|
||||
@@ -314,11 +312,10 @@ class TestUploadToEmailTask:
|
||||
mock_exists.return_value = True
|
||||
mock_settings.email_host = None
|
||||
|
||||
task = upload_to_email
|
||||
task.request = Mock()
|
||||
task.request.id = "test-task-id"
|
||||
mock_self = Mock()
|
||||
mock_self.request.id = "test-task-id"
|
||||
|
||||
result = task("/tmp/test.pdf")
|
||||
result = upload_to_email(mock_self, "/tmp/test.pdf")
|
||||
|
||||
assert result["status"] == "Skipped"
|
||||
assert "Email host is not configured" in result["reason"]
|
||||
@@ -333,11 +330,10 @@ class TestUploadToEmailTask:
|
||||
mock_settings.email_host = "smtp.example.com"
|
||||
mock_prepare.return_value = (None, "No recipients specified")
|
||||
|
||||
task = upload_to_email
|
||||
task.request = Mock()
|
||||
task.request.id = "test-task-id"
|
||||
mock_self = Mock()
|
||||
mock_self.request.id = "test-task-id"
|
||||
|
||||
result = task("/tmp/test.pdf")
|
||||
result = upload_to_email(mock_self, "/tmp/test.pdf")
|
||||
|
||||
assert result["status"] == "Skipped"
|
||||
|
||||
@@ -364,10 +360,9 @@ class TestUploadToEmailTask:
|
||||
mock_attach_logo.return_value = False
|
||||
mock_send_email.return_value = {"status": "Failed", "reason": "SMTP error"}
|
||||
|
||||
task = upload_to_email
|
||||
task.request = Mock()
|
||||
task.request.id = "test-task-id"
|
||||
mock_self = Mock()
|
||||
mock_self.request.id = "test-task-id"
|
||||
|
||||
result = task("/tmp/test.pdf", recipients=["recipient@example.com"])
|
||||
result = upload_to_email(mock_self, "/tmp/test.pdf", recipients=["recipient@example.com"])
|
||||
|
||||
assert result["status"] == "Failed"
|
||||
|
||||
Reference in New Issue
Block a user