def run(self, project: Project, version: ProjectVersion, detector_run: DetectorRun, potential_hits: PotentialHits, version_compile: VersionCompile, detector: Detector): logger = logging.getLogger("tasks.publish_findings.version") logger.info("Publishing findings of %s in %s on %s for upload to %s...", detector, self.experiment_id, version, self.review_site_url) if detector_run.is_success(): logger.info("Uploading %s potential hits.", len(potential_hits.findings)) result = "success" elif detector_run.is_error(): logger.info("Detector produced an error.") result = "error" elif detector_run.is_timeout(): logger.info("Detector timed out.") result = "timeout" else: logger.info("Detector was not run.") result = "not run" run_info = detector_run.get_run_info() postable_potential_hits = [ self.__to_postable_potential_hit(potential_hit, version_compile, detector_run.findings_path, logger) for potential_hit in potential_hits.findings] try: for postable_potential_hits_slice in self.__slice_by_number_of_files_and_post_size(postable_potential_hits): file_paths = self.__get_file_paths(postable_potential_hits_slice) postable_data = self.__to_postable_data(run_info, result, postable_potential_hits_slice) self.__post(project, version, detector, postable_data, file_paths) except RequestException as e: raise PublishFailedException(e)
def test_force_detect_on_new_detector(self, _): uut = DetectorRun(self.detector, self.version, self.findings_path) uut._execute = MagicMock() uut.is_success = lambda: True uut.is_outdated = lambda _: True uut.ensure_executed(self.detector_args, None, False, 0, 0, self.logger) uut._execute.assert_called_with(ANY, None, 0, ANY)
def test_skips_execution_if_previous_run_succeeded(self, _): uut = DetectorRun(self.detector, self.version, self.findings_path) uut._execute = MagicMock() uut.is_outdated = lambda _: False uut.is_error = lambda: False uut.is_success = lambda: True uut.ensure_executed(self.detector_args, None, False, 0, 0, self.logger) uut._execute.assert_not_called()
def test_load(self, read_run_info, _): read_run_info.return_value = { "result": "success", "runtime": "23.42", "message": "-arbitrary text-" } uut = DetectorRun(self.detector, self.version, self.findings_path) assert uut.is_success() assert_equals(uut.runtime, "23.42") assert_equals(uut.message, "-arbitrary text-")