|
7 | 7 | # See https://aboutcode.org for more information about nexB OSS projects. |
8 | 8 | # |
9 | 9 |
|
10 | | -from datetime import datetime |
11 | | - |
12 | 10 | from django.apps import apps |
13 | | -from django.db import IntegrityError |
14 | 11 | from django.db import connection |
15 | 12 | from django.db.migrations.executor import MigrationExecutor |
16 | 13 | from django.db.models import Count |
17 | 14 | from django.test import TestCase |
18 | | -from django.utils import timezone |
19 | | -from packageurl import PackageURL |
20 | | -from univers.version_range import VersionRange |
21 | 15 |
|
22 | 16 | from vulnerabilities import severity_systems |
23 | | -from vulnerabilities.utils import purl_to_dict |
24 | 17 |
|
25 | 18 |
|
26 | 19 | class TestMigrations(TestCase): |
@@ -59,83 +52,8 @@ def setUpBeforeMigration(self, apps): |
59 | 52 | pass |
60 | 53 |
|
61 | 54 |
|
62 | | -class TestCodeCommitMigration(TestMigrations): |
63 | | - """ |
64 | | - Tests the migration that introduces the CodeCommit model |
65 | | - and adds new ManyToMany fields to ImpactedPackage ( affecting_commits, fixed_by_commits ). |
66 | | - """ |
67 | | - |
68 | | - app_name = "vulnerabilities" |
69 | | - migrate_from = "0102_alter_impactedpackage_affecting_vers_and_more" |
70 | | - migrate_to = "0103_codecommit_impactedpackage_affecting_commits_and_more" |
71 | | - |
72 | | - def setUpBeforeMigration(self, apps): |
73 | | - """ |
74 | | - Prepare old data before migration — this should be destroyed afterward. |
75 | | - """ |
76 | | - ImpactedPackage = apps.get_model("vulnerabilities", "ImpactedPackage") |
77 | | - AdvisoryV2 = apps.get_model("vulnerabilities", "AdvisoryV2") |
78 | | - |
79 | | - date = datetime.now() |
80 | | - adv = AdvisoryV2.objects.create( |
81 | | - unique_content_id="old_adv", |
82 | | - url="https://old.example.com", |
83 | | - summary="Old advisory", |
84 | | - date_collected=date, |
85 | | - advisory_id="old_adv", |
86 | | - avid="test_pipeline/old_adv", |
87 | | - datasource_id="test_pipeline", |
88 | | - # pipeline_id="test_pipeline_v2", |
89 | | - ) |
90 | | - ImpactedPackage.objects.create(advisory=adv, base_purl="pkg:pypi/oldpkg") |
91 | | - |
92 | | - def test_unique_constraint_on_commit_hash_and_vcs_url(self): |
93 | | - """Ensure the (commit_hash, vcs_url) uniqueness constraint works.""" |
94 | | - CodeCommit = self.apps.get_model("vulnerabilities", "CodeCommit") |
95 | | - |
96 | | - CodeCommit.objects.create( |
97 | | - commit_hash="abc123", |
98 | | - vcs_url="https://github.com/example/repo.git", |
99 | | - commit_rank="0", |
100 | | - commit_author="tester", |
101 | | - commit_message="message 1", |
102 | | - commit_date=datetime.now(), |
103 | | - ) |
104 | | - |
105 | | - with self.assertRaises(IntegrityError): |
106 | | - CodeCommit.objects.create( |
107 | | - commit_hash="abc123", |
108 | | - vcs_url="https://github.com/example/repo.git", |
109 | | - ) |
110 | | - |
111 | | - def test_m2m_relationships_work(self): |
112 | | - """Ensure that the new M2M relationships can store data.""" |
113 | | - ImpactedPackage = self.apps.get_model("vulnerabilities", "ImpactedPackage") |
114 | | - AdvisoryV2 = self.apps.get_model("vulnerabilities", "AdvisoryV2") |
115 | | - CodeCommit = self.apps.get_model("vulnerabilities", "CodeCommit") |
116 | | - |
117 | | - adv = AdvisoryV2.objects.get( |
118 | | - unique_content_id="old_adv", |
119 | | - advisory_id="old_adv", |
120 | | - avid="test_pipeline/old_adv", |
121 | | - datasource_id="test_pipeline", |
122 | | - ) |
123 | | - |
124 | | - impacted = ImpactedPackage.objects.get(advisory=adv, base_purl="pkg:pypi/oldpkg") |
125 | | - commit1 = CodeCommit.objects.create( |
126 | | - commit_hash="def456", |
127 | | - vcs_url="https://example.com/repo.git", |
128 | | - ) |
129 | | - commit2 = CodeCommit.objects.create( |
130 | | - commit_hash="eef456", |
131 | | - vcs_url="https://example.com/repo.git", |
132 | | - ) |
133 | | - |
134 | | - impacted.affecting_commits.add(commit1) |
135 | | - impacted.fixed_by_commits.add(commit2) |
136 | | - |
137 | | - self.assertIn(commit1, impacted.affecting_commits.all()) |
138 | | - self.assertIn(commit2, impacted.fixed_by_commits.all()) |
| 55 | +# TestCodeCommitMigration removed: CodeCommit was deleted in 0105, and migration |
| 56 | +# 0145 irreversibly drops V1 tables so reversing to 0102/0103 is no longer possible. |
139 | 57 |
|
140 | 58 |
|
141 | 59 | class TestLatestAdvisoryV2Migration(TestMigrations): |
@@ -523,7 +441,8 @@ def test_severity_value_cleaned(self): |
523 | 441 |
|
524 | 442 | def test_advisory_content_id_recomputed(self): |
525 | 443 | self.advisory1.refresh_from_db() |
| 444 | + # Hash excludes url/advisory_id (compute_content_id_v2); severity value cleaned to "". |
526 | 445 | self.assertEqual( |
527 | 446 | self.advisory1.unique_content_id, |
528 | | - "a15d4651cb05e3513c12263a11e34bd9103f68833cac8f7ffdbbd71b9cb4cf16", |
| 447 | + "885d5cc15389a644089516b7047dff3716f666a0219befe32938777ae5e686fb", |
529 | 448 | ) |
0 commit comments