コード例 #1
0
    def test_scanpipe_pipes_scancode_scan_file_and_save_results(self):
        project1 = Project.objects.create(name="Analysis")
        codebase_resource1 = CodebaseResource.objects.create(
            project=project1, path="not available")

        self.assertEqual(0, project1.projecterrors.count())
        scan_results, scan_errors = scancode.scan_file(
            codebase_resource1.location)
        scancode.save_scan_file_results(codebase_resource1, scan_results,
                                        scan_errors)

        codebase_resource1.refresh_from_db()
        self.assertEqual("scanned-with-error", codebase_resource1.status)
        self.assertEqual(4, project1.projecterrors.count())

        copy_inputs([self.data_location / "notice.NOTICE"],
                    project1.codebase_path)
        codebase_resource2 = CodebaseResource.objects.create(
            project=project1, path="notice.NOTICE")
        scan_results, scan_errors = scancode.scan_file(
            codebase_resource2.location)
        scancode.save_scan_file_results(codebase_resource2, scan_results,
                                        scan_errors)
        codebase_resource2.refresh_from_db()
        self.assertEqual("scanned", codebase_resource2.status)
        expected = [
            "apache-2.0",
            "apache-2.0 AND scancode-acknowledgment",
            "apache-2.0",
            "apache-2.0",
        ]
        self.assertEqual(expected, codebase_resource2.license_expressions)
コード例 #2
0
ファイル: compliance.py プロジェクト: vvalorous/scancode.io
def analyze_compliance_licenses(project):
    """
    Scan compliance licenses status for the provided `project`.
    """
    qs = CodebaseResource.objects.project(project).status("compliance-licenses")

    for codebase_resource in qs:
        scan_results, scan_errors = scancode.scan_file(codebase_resource.location)
        codebase_resource.set_scan_results(scan_results, save=True)
コード例 #3
0
ファイル: test_pipes.py プロジェクト: vvalorous/scancode.io
 def test_scanpipe_pipes_scancode_scan_file(self):
     input_location = str(self.data_location / "notice.NOTICE")
     scan_results, scan_errors = scancode.scan_file(input_location)
     expected = [
         "copyrights",
         "holders",
         "authors",
         "licenses",
         "license_expressions",
         "spdx_license_expressions",
         "percentage_of_license_text",
         "emails",
         "urls",
     ]
     self.assertEqual(expected, list(scan_results.keys()))
     self.assertEqual([], scan_errors)
コード例 #4
0
    def test_scanpipe_pipes_scancode_scan_file_timeout(self):
        input_location = str(self.data_location / "notice.NOTICE")

        with mock.patch("scancode.api.get_copyrights") as get_copyrights:
            get_copyrights.side_effect = InterruptTimeoutError
            scan_results, scan_errors = scancode.scan_file(input_location)

        expected_errors = [
            "ERROR: for scanner: copyrights:\n"
            "ERROR: Processing interrupted: timeout after 120 seconds."
        ]
        self.assertEqual(expected_errors, scan_errors)

        expected = [
            "licenses",
            "license_expressions",
            "spdx_license_expressions",
            "percentage_of_license_text",
            "emails",
            "urls",
        ]
        self.assertEqual(sorted(expected), sorted(scan_results.keys()))
コード例 #5
0
    def test_scanpipe_pipes_scancode_scan_file_and_save_results_timeout_error(
            self):
        project1 = Project.objects.create(name="Analysis")
        copy_inputs([self.data_location / "notice.NOTICE"],
                    project1.codebase_path)
        codebase_resource = CodebaseResource.objects.create(
            project=project1, path="notice.NOTICE")

        with mock.patch("scancode.api.get_copyrights") as get_copyrights:
            get_copyrights.side_effect = InterruptTimeoutError
            results, errors = scancode.scan_file(codebase_resource.location)
            scancode.save_scan_file_results(codebase_resource, results, errors)

        codebase_resource.refresh_from_db()
        self.assertEqual("scanned-with-error", codebase_resource.status)
        self.assertEqual(1, project1.projecterrors.count())
        error = project1.projecterrors.latest("created_date")
        self.assertEqual("CodebaseResource", error.model)
        self.assertEqual("", error.traceback)
        expected_message = (
            "ERROR: for scanner: copyrights:\n"
            "ERROR: Processing interrupted: timeout after 120 seconds.")
        self.assertEqual(expected_message, error.message)