def test_blender_verification_request_task_should_not_link_upload_requests_to_unrelated_upload_reports( self): upload_report = UploadReport(path='blender/scene/bad/bad.bad.zip', ) upload_report.full_clean() upload_report.save() blender_verification_request( frames=self.compute_task_def['extra_data']['frames'], subtask_id=self.compute_task_def['subtask_id'], source_package_path=self.source_package_path, result_package_path=self.result_package_path, output_format=BlenderSubtaskDefinition.OutputFormat.JPEG.name, # pylint: disable=no-member scene_file=self.compute_task_def['extra_data']['scene_file'], verification_deadline=self._get_verification_deadline_as_timestamp( get_current_utc_timestamp(), self.report_computed_task.size, ), blender_crop_script_parameters=self.blender_crop_script_parameters, ) self.assertEqual(VerificationRequest.objects.count(), 1) verification_request = VerificationRequest.objects.first() self.assertEqual(verification_request.upload_reports.count(), 0) self.assertFalse( verification_request.upload_reports.filter( path=self.source_package_path).exists()) self.assertIsInstance( verification_request.blender_subtask_definition. blender_crop_script_parameters, BlenderCropScriptParameters)
def test_blender_verification_request_task_should_schedule_upload_finished_task_if_all_related_upload_requests_have_reports( self): upload_report = UploadReport(path=self.source_package_path, ) upload_report.full_clean() upload_report.save() upload_report = UploadReport(path=self.result_package_path, ) upload_report.full_clean() upload_report.save() with mock.patch('conductor.tasks.tasks.transaction.on_commit' ) as transaction_on_commit: blender_verification_request( frames=self.compute_task_def['extra_data']['frames'], subtask_id=self.compute_task_def['subtask_id'], source_package_path=self.source_package_path, result_package_path=self.result_package_path, output_format=BlenderSubtaskDefinition.OutputFormat.JPEG.name, # pylint: disable=no-member scene_file=self.compute_task_def['extra_data']['scene_file'], verification_deadline=self. _get_verification_deadline_as_timestamp( get_current_utc_timestamp(), self.report_computed_task.size, ), blender_crop_script_parameters=self. blender_crop_script_parameters, ) transaction_on_commit.assert_called_once()
def test_that_conductor_should_not_schedule_verification_order_task_if_same_file_was_uploaded_again( self): verification_request = self._prepare_verification_request_with_blender_subtask_definition( ) upload_report = UploadReport( path=verification_request.result_package_path, verification_request=verification_request, ) upload_report.full_clean() upload_report.save() with mock.patch('conductor.views.upload_finished.delay') as mock_task: response = self.client.post( reverse('conductor:report-upload', kwargs={'file_path': self.result_package_path}), content_type='application/octet-stream', ) self.assertEqual(response.status_code, 200) self.assertEqual(UploadReport.objects.count(), 2) mock_task.assert_not_called() verification_request.refresh_from_db() self.assertFalse(verification_request.upload_finished)
def test_conductor_should_schedule_verification_order_task_if_all_related_upload_requests_have_reports( self): verification_request = self._prepare_verification_request_with_blender_subtask_definition( ) upload_report = UploadReport( path=verification_request.result_package_path, verification_request=verification_request, ) upload_report.full_clean() upload_report.save() with mock.patch('conductor.views.transaction.on_commit' ) as mock_transaction_on_commit: response = self.client.post( reverse('conductor:report-upload', kwargs={'file_path': self.source_package_path}), content_type='application/octet-stream', ) self.assertEqual(response.status_code, 200) self.assertEqual(UploadReport.objects.count(), 2) upload_report = UploadReport.objects.last() self.assertEqual(upload_report.path, self.source_package_path) mock_transaction_on_commit.assert_called_once() verification_request.refresh_from_db() self.assertTrue(verification_request.upload_finished)
def report_upload(_request: HttpRequest, file_path: str) -> HttpResponse: log_request_received(logger, file_path, FileTransferToken.Operation.upload) # If there's a corresponding VerificationRequest, the load it and link it to UploadReport. try: verification_request = VerificationRequest.objects.select_for_update( ).get( Q(source_package_path=file_path) | Q(result_package_path=file_path)) except VerificationRequest.DoesNotExist: verification_request = None # The app creates a new instance of UploadReport in the database. upload_report = UploadReport( path=file_path, verification_request=verification_request, ) upload_report.full_clean() upload_report.save() # The app gets the VerificationRequest and checks if both source and result packages have reports. if (verification_request is not None and verification_request.blender_subtask_definition is not None and verification_request.upload_reports.filter( path=verification_request.source_package_path).exists() and verification_request.upload_reports.filter( path=verification_request.result_package_path).exists() and verification_request.upload_reports.filter( path=file_path).count() == 1): assert file_path in [ verification_request.source_package_path, verification_request.result_package_path ] # If all expected files have been uploaded, the app sends upload_finished task to the work queue. upload_finished.delay(verification_request.subtask_id) verification_request.upload_finished = True verification_request.full_clean() verification_request.save() log(logger, 'All expected files have been uploaded', f'Result package path: {verification_request.result_package_path}.' f'Source package path: {verification_request.source_package_path}.', subtask_id=verification_request.subtask_id) # If ResultTransferRequest matching the file exists, report finished upload. result_transfer_request = ResultTransferRequest.objects.filter( result_package_path=file_path).first() if result_transfer_request is not None: update_upload_report( file_path=file_path, result_transfer_request=result_transfer_request, ) return HttpResponse()
def test_that_result_transfer_request_create_result_transfer_request_and_call_update_upload_report_if_related_upload_report_exists( self): upload_report = UploadReport(path=self.path) upload_report.full_clean() upload_report.save() with mock.patch('conductor.tasks.update_upload_report' ) as update_upload_report: result_transfer_request( self.subtask_id, self.path, ) update_upload_report.assert_called_once()
def test_that_update_upload_report_should_update_related_upload_reports( self): upload_report = UploadReport(path=self.path) upload_report.full_clean() upload_report.save() self.result_transfer_request.upload_finished = True self.result_transfer_request.full_clean() self.result_transfer_request.save() with mock.patch('conductor.service.result_upload_finished.delay' ) as result_upload_finished: update_upload_report( self.path, self.result_transfer_request, ) upload_report.refresh_from_db() self.assertEqual(upload_report.result_transfer_request, self.result_transfer_request) result_upload_finished.assert_not_called()