diff --git a/tasks/tests/unit/test_upload_processing_task.py b/tasks/tests/unit/test_upload_processing_task.py index 7cafdd534..2f22fa7e5 100644 --- a/tasks/tests/unit/test_upload_processing_task.py +++ b/tasks/tests/unit/test_upload_processing_task.py @@ -8,11 +8,16 @@ from shared.reports.enums import UploadState from shared.reports.resources import Report, ReportFile, ReportLine, ReportTotals from shared.storage.exceptions import FileNotInStorageError +from shared.torngit.exceptions import TorngitObjectNotFoundError from shared.upload.constants import UploadErrorCode from database.models import CommitReport, ReportDetails, UploadError from database.tests.factories import CommitFactory, UploadFactory -from helpers.exceptions import ReportEmptyError, ReportExpiredException +from helpers.exceptions import ( + ReportEmptyError, + ReportExpiredException, + RepositoryWithoutValidBotError, +) from helpers.parallel import ParallelProcessing from rollouts import USE_LABEL_INDEX_IN_REPORT_PROCESSING_BY_REPO_ID from services.archive import ArchiveService @@ -22,7 +27,11 @@ SessionAdjustmentResult, UploadProcessingResult, ) -from tasks.upload_processor import UploadProcessorTask, save_report_results +from tasks.upload_processor import ( + UploadProcessorTask, + load_commit_diff, + save_report_results, +) here = Path(__file__) @@ -1036,6 +1045,29 @@ def test_save_report_results_apply_diff_not_there( } assert report.diff_totals is None + def test_load_commit_diff_no_diff( + self, mocker, mock_configuration, dbsession, mock_repo_provider + ): + commit = CommitFactory.create() + dbsession.add(commit) + dbsession.flush() + mock_repo_provider.get_commit_diff.side_effect = TorngitObjectNotFoundError( + "response", "message" + ) + diff = load_commit_diff(commit, None, None) + assert diff is None + + def test_load_commit_diff_no_bot(self, mocker, mock_configuration, dbsession): + commit = CommitFactory.create() + dbsession.add(commit) + dbsession.flush() + mock_get_repo_service = mocker.patch( + "tasks.upload_processor.get_repo_provider_service" + ) + mock_get_repo_service.side_effect = RepositoryWithoutValidBotError() + diff = load_commit_diff(commit, None, None) + assert diff is None + def test_save_report_results_apply_diff_valid( self, mocker, mock_configuration, dbsession, mock_storage ):