Skip to content

Commit

Permalink
Add test for Alpine data migration
Browse files Browse the repository at this point in the history
Signed-off-by: Keshav Priyadarshi <[email protected]>
  • Loading branch information
keshav-space committed Jan 13, 2025
1 parent 91e3e1e commit 389eb91
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions vulnerabilities/tests/test_data_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from vulnerabilities.importer import AdvisoryData
from vulnerabilities.importer import AffectedPackage
from vulnerabilities.importer import Reference
from vulnerabilities.utils import purl_to_dict


class TestMigrations(TestCase):
Expand Down Expand Up @@ -922,3 +923,32 @@ def test_update_pysec_created_by_field(self):
== 0
)
assert adv.filter(created_by="alpine_linux_importer").count() == 1


class TestFixAlpinePURLCreatedByField(TestMigrations):
app_name = "vulnerabilities"
migrate_from = "0087_update_alpine_advisory_created_by"
migrate_to = "0088_fix_alpine_purl_type"

def setUpBeforeMigration(self, apps):
Package = apps.get_model("vulnerabilities", "Package")
purl = str(
PackageURL(
type="alpine",
namespace="",
name="curl",
version="7.83.0-r0",
qualifiers="arch=x86",
)
)
package1 = Package.objects.create(
**purl_to_dict(purl=purl), package_url=purl, plain_package_url=purl
)

def test_fix_alpine_purl(self):
Package = apps.get_model("vulnerabilities", "Package")
package = Package.objects.all()
print(package)

assert package.filter(type="alpine").count() == 0
assert package.filter(type="apk").count() == 1

0 comments on commit 389eb91

Please sign in to comment.