def test_scanpipe_pipes_scancode_scan_for_files(self, mock_scan_file): scan_results = {"license_expressions": ["mit"]} scan_errors = [] mock_scan_file.return_value = scan_results, scan_errors project1 = Project.objects.create(name="Analysis") sha1 = "51d28a27d919ce8690a40f4f335b9d591ceb16e9" resource1 = CodebaseResource.objects.create( project=project1, path="dir1/file.ext", sha1=sha1, ) resource2 = CodebaseResource.objects.create( project=project1, path="dir2/file.ext", sha1=sha1, ) scancode.scan_for_files(project1) # The scan_file is only called once as the cache is used for the second # duplicated resource. mock_scan_file.assert_called_once() for resource in [resource1, resource2]: resource.refresh_from_db() self.assertEqual("scanned", resource.status) self.assertEqual(["mit"], resource.license_expressions)
def test_scanpipe_pipes_scancode_scan_for_files(self, mock_scan_resource): scan_results = {"license_expressions": ["mit"]} scan_errors = [] mock_scan_resource.return_value = scan_results, scan_errors project1 = Project.objects.create(name="Analysis") sha1 = "51d28a27d919ce8690a40f4f335b9d591ceb16e9" resource1 = CodebaseResource.objects.create( project=project1, path="dir1/file.ext", sha1=sha1, ) resource2 = CodebaseResource.objects.create( project=project1, path="dir2/file.ext", sha1=sha1, ) scancode.scan_for_files(project1) resource1.refresh_from_db() self.assertEqual("scanned", resource1.status) self.assertEqual(["mit"], resource1.license_expressions) resource2.refresh_from_db() self.assertEqual("scanned", resource2.status) self.assertEqual(["mit"], resource2.license_expressions) resource3 = CodebaseResource.objects.create( project=project1, path="dir3/file.ext", sha1=sha1, ) scan_results = {"copyrights": ["copy"]} scan_errors = ["ERROR"] mock_scan_resource.return_value = scan_results, scan_errors scancode.scan_for_files(project1) resource3.refresh_from_db() self.assertEqual("scanned-with-error", resource3.status) self.assertEqual([], resource3.license_expressions) self.assertEqual(["copy"], resource3.copyrights)
def scan_for_files(self): """ Scan unknown resources for copyrights, licenses, emails, and urls. """ scancode.scan_for_files(self.project)