test(tasks): add comprehensive tests for per-user cloud scan functions and gmail_apply_labels
Add 68 new unit tests covering: - _scan_user_s3_folder: 10 tests (bucket config, credentials, client creation, pagination, download, cache, file types, delete, error handling) - _scan_user_dropbox_folder: 9 tests (credentials, folder path, auth, listing, download, cache, non-file entries, delete, download failure) - _scan_user_google_drive_folder: 8 tests (credentials JSON, folder ID, auth, download, cache, delete, download/listing failures) - _scan_user_onedrive_folder: 10 tests (credentials, folder path, token exchange, download, folders, cache, download URL, delete, download/listing failures) - _scan_user_nextcloud_folder: 9 tests (settings, PROPFIND, XML parse, download, self-entry, cache, delete, download failure, absolute href) - _scan_user_webdav_folder: 9 tests (URL config, PROPFIND, XML parse, download, directories, cache, delete, download failure, absolute href) - Dispatch tests for google_drive, onedrive, nextcloud, webdav source types - gmail_apply_labels forwarding and default-to-true in IMAP integration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1584,6 +1584,55 @@ class TestPullUserIntegrationImap:
|
||||
assert mock_integ.last_error is None
|
||||
assert mock_integ.last_used_at is not None
|
||||
|
||||
@patch("app.tasks.imap_tasks._get_db_session")
|
||||
@patch("app.tasks.imap_tasks.pull_inbox")
|
||||
def test_passes_gmail_apply_labels_config_to_pull_inbox(self, mock_pull, mock_session_factory):
|
||||
"""gmail_apply_labels config should be forwarded to pull_inbox."""
|
||||
from app.tasks.imap_tasks import _pull_user_integration_imap
|
||||
|
||||
mock_integ = MagicMock()
|
||||
mock_integ.id = 14
|
||||
mock_integ.owner_id = "owner-gmail"
|
||||
mock_integ.config = (
|
||||
'{"host": "imap.gmail.com", "port": 993, "username": "u@gmail.com",'
|
||||
' "use_ssl": true, "gmail_apply_labels": false}'
|
||||
)
|
||||
mock_integ.credentials = "enc:encrypted"
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_db.query.return_value.filter.return_value.all.return_value = [mock_integ]
|
||||
mock_session_factory.return_value = mock_db
|
||||
|
||||
with patch("app.utils.encryption.decrypt_value", return_value='{"password": "p"}'):
|
||||
_pull_user_integration_imap()
|
||||
|
||||
mock_pull.assert_called_once()
|
||||
call_kwargs = mock_pull.call_args
|
||||
assert call_kwargs.kwargs.get("gmail_apply_labels") is False
|
||||
|
||||
@patch("app.tasks.imap_tasks._get_db_session")
|
||||
@patch("app.tasks.imap_tasks.pull_inbox")
|
||||
def test_gmail_apply_labels_defaults_to_true(self, mock_pull, mock_session_factory):
|
||||
"""Config without gmail_apply_labels should default to True."""
|
||||
from app.tasks.imap_tasks import _pull_user_integration_imap
|
||||
|
||||
mock_integ = MagicMock()
|
||||
mock_integ.id = 15
|
||||
mock_integ.owner_id = "owner-gmail2"
|
||||
mock_integ.config = '{"host": "imap.gmail.com", "port": 993, "username": "u@gmail.com", "use_ssl": true}'
|
||||
mock_integ.credentials = "enc:encrypted"
|
||||
|
||||
mock_db = MagicMock()
|
||||
mock_db.query.return_value.filter.return_value.all.return_value = [mock_integ]
|
||||
mock_session_factory.return_value = mock_db
|
||||
|
||||
with patch("app.utils.encryption.decrypt_value", return_value='{"password": "p"}'):
|
||||
_pull_user_integration_imap()
|
||||
|
||||
mock_pull.assert_called_once()
|
||||
call_kwargs = mock_pull.call_args
|
||||
assert call_kwargs.kwargs.get("gmail_apply_labels") is True
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
class TestPullAllInboxesCallsIntegrations:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user