def test_scanpipe_pipes_scancode_virtual_codebase(self): project = Project.objects.create(name="asgiref") input_location = self.data_location / "asgiref-3.3.0_scan.json" virtual_codebase = scancode.get_virtual_codebase( project, input_location) self.assertEqual(19, len(virtual_codebase.resources.keys())) scancode.create_codebase_resources(project, virtual_codebase) scancode.create_discovered_packages(project, virtual_codebase) self.assertEqual(18, CodebaseResource.objects.count()) self.assertEqual(1, DiscoveredPackage.objects.count()) # Make sure the root is not created as a CodebaseResource, walk(skip_root=True) self.assertFalse( CodebaseResource.objects.filter(path="codebase").exists()) # Make sure the root is properly stripped, see `.get_path(strip_root=True)` self.assertFalse( CodebaseResource.objects.filter( path__startswith="codebase").exists()) # Make sure the detected package is properly assigned to its codebase resource package = DiscoveredPackage.objects.get() expected = "asgiref-3.3.0-py3-none-any.whl" self.assertEqual(expected, package.codebase_resources.get().path) # The functions can be called again and existing objects are skipped scancode.create_codebase_resources(project, virtual_codebase) scancode.create_discovered_packages(project, virtual_codebase) self.assertEqual(18, CodebaseResource.objects.count()) self.assertEqual(1, DiscoveredPackage.objects.count())
def build_inventory_from_scan(self): """ Process the JSON scan to populate resources and packages. """ project = self.project scanned_codebase = scancode.get_virtual_codebase(project, self.input_location) scancode.create_codebase_resources(project, scanned_codebase) scancode.create_discovered_packages(project, scanned_codebase)
def test_scanpipe_pipes_scancode_virtual_codebase(self): project = Project.objects.create(name="asgiref") input_location = self.data_location / "asgiref-3.3.0_scan.json" virtual_codebase = scancode.get_virtual_codebase(project, input_location) self.assertEqual(19, len(virtual_codebase.resources.keys())) scancode.create_codebase_resources(project, virtual_codebase) scancode.create_discovered_packages(project, virtual_codebase) self.assertEqual(19, CodebaseResource.objects.count()) self.assertEqual(1, DiscoveredPackage.objects.count()) # The functions can be called again and existing objects are skipped scancode.create_codebase_resources(project, virtual_codebase) scancode.create_discovered_packages(project, virtual_codebase) self.assertEqual(19, CodebaseResource.objects.count()) self.assertEqual(1, DiscoveredPackage.objects.count())