fix(import): fail auto import on drive auth failure
All checks were successful
CD Pipeline / deploy (push) Successful in 1m9s
All checks were successful
CD Pipeline / deploy (push) Successful in 1m9s
This commit is contained in:
@@ -143,3 +143,50 @@ def test_auto_import_does_not_move_drive_file_when_import_fails(monkeypatch, tmp
|
||||
assert result["success"] is False
|
||||
assert result["failed_count"] == 1
|
||||
assert fake_drive.moved_files == []
|
||||
|
||||
|
||||
def test_auto_import_fails_closed_when_drive_auth_fails(monkeypatch, tmp_path):
|
||||
import_service = _load_import_service(monkeypatch, f"sqlite:///{tmp_path / 'momo.db'}")
|
||||
import_service.Base.metadata.create_all(import_service.engine)
|
||||
|
||||
class FakeDriveService:
|
||||
last_error_kind = "authentication_failed"
|
||||
last_error = "could not locate runnable browser"
|
||||
|
||||
def list_files_in_folder(self, folder_path, file_pattern):
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(import_service, "drive_service", FakeDriveService())
|
||||
|
||||
service = import_service.ImportService()
|
||||
result = service.auto_import_from_drive()
|
||||
|
||||
assert result["success"] is False
|
||||
assert result["file_count"] == 0
|
||||
assert result["imported_count"] == 0
|
||||
assert result["failed_count"] == 1
|
||||
assert result["connection_error"] is True
|
||||
assert result["error_kind"] == "authentication_failed"
|
||||
assert "Google Drive" in result["message"]
|
||||
assert "could not locate runnable browser" in result["message"]
|
||||
|
||||
|
||||
def test_auto_import_empty_drive_folder_remains_success(monkeypatch, tmp_path):
|
||||
import_service = _load_import_service(monkeypatch, f"sqlite:///{tmp_path / 'momo.db'}")
|
||||
import_service.Base.metadata.create_all(import_service.engine)
|
||||
|
||||
class FakeDriveService:
|
||||
last_error_kind = None
|
||||
last_error = None
|
||||
|
||||
def list_files_in_folder(self, folder_path, file_pattern):
|
||||
return []
|
||||
|
||||
monkeypatch.setattr(import_service, "drive_service", FakeDriveService())
|
||||
|
||||
service = import_service.ImportService()
|
||||
result = service.auto_import_from_drive()
|
||||
|
||||
assert result["success"] is True
|
||||
assert result["file_count"] == 0
|
||||
assert result["message"] == "沒有找到待匯入的檔案"
|
||||
|
||||
Reference in New Issue
Block a user