|
34 | 34 | from vulnerabilities.models import AdvisorySeverity |
35 | 35 | from vulnerabilities.models import Alias |
36 | 36 | from vulnerabilities.models import Package |
| 37 | +from vulnerabilities.models import PackageV2 |
37 | 38 | from vulnerabilities.models import Patch |
38 | 39 | from vulnerabilities.models import Vulnerability |
39 | 40 | from vulnerabilities.severity_systems import CVSSV3 |
@@ -827,3 +828,38 @@ def test_advisoryv2_duplication_data(self): |
827 | 828 | result = models.AdvisoryV2.objects.count() |
828 | 829 |
|
829 | 830 | self.assertEqual(result, 2) |
| 831 | + |
| 832 | + |
| 833 | +class TestPackageV2BulkCreate(DjangoTestCase): |
| 834 | + def setUp(self): |
| 835 | + PackageV2.objects.get_or_create_from_purl( |
| 836 | + "pkg:deb/ubuntu/linux@6.17.0-19.19?arch=source&distro=questing" |
| 837 | + ) |
| 838 | + PackageV2.objects.get_or_create_from_purl("pkg:pypi/foo@1.2.3") |
| 839 | + PackageV2.objects.get_or_create_from_purl("pkg:npm/foobar@3.2.3") |
| 840 | + PackageV2.objects.get_or_create_from_purl("pkg:maven/foo@1.2.3") |
| 841 | + PackageV2.objects.get_or_create_from_purl( |
| 842 | + "pkg:deb/ubuntu/linux@6.17.0-4.4?arch=source&distro=questing" |
| 843 | + ) |
| 844 | + |
| 845 | + def test_package_bulk_get_or_create_from_purls(self): |
| 846 | + purls = [ |
| 847 | + "pkg:npm/foo@1.2.3", |
| 848 | + "pkg:pypi/foo@1.2.3", |
| 849 | + "pkg:npm/foobar@3.2.3", |
| 850 | + "pkg:maven/foo@1.2.3", |
| 851 | + "pkg:nuget/foo@1.2.3", |
| 852 | + "pkg:deb/ubuntu/linux@6.17.0-22.22?arch=source&distro=questing", |
| 853 | + "pkg:deb/ubuntu/linux@6.17.0-20.20?arch=source&distro=questing", |
| 854 | + "pkg:deb/ubuntu/linux@6.17.0-14.14?arch=source&distro=questing", |
| 855 | + "pkg:deb/ubuntu/linux@6.17.0-12.12?arch=source&distro=questing", |
| 856 | + "pkg:deb/ubuntu/linux@6.17.0-8.8?arch=source&distro=questing", |
| 857 | + "pkg:deb/ubuntu/linux@6.17.0-7.7?arch=source&distro=questing", |
| 858 | + "pkg:deb/ubuntu/linux@6.17.0-6.6?arch=source&distro=questing", |
| 859 | + "pkg:deb/ubuntu/linux@6.17.0-5.5?arch=source&distro=questing", |
| 860 | + "pkg:deb/ubuntu/linux@6.17.0-4.4?arch=source&distro=questing", |
| 861 | + ] |
| 862 | + result_qs = PackageV2.objects.bulk_get_or_create_from_purls(purls) |
| 863 | + result = [p.package_url for p in result_qs] |
| 864 | + |
| 865 | + self.assertCountEqual(result, purls) |
0 commit comments