Skip to content

Commit b2e4c2b

Browse files
Maffoochclaude
andcommitted
test(vuln-id): make setUpTestData valid under full model validation
The rest-framework CI matrix runs a V3_FEATURE_LOCATIONS=True leg where base save() calls full_clean(). The new vuln-id test classes created Product/Test without the required description / scan_type / environment, so all 7 setUpClass hooks errored with ValidationError under that leg (they passed the False leg). Provide the required fields (Finding creation already skips validation via skip_validation=True, so it's unaffected). Reproduced locally with V3_FEATURE_LOCATIONS=True: 14 tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cabe493 commit b2e4c2b

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

unittests/test_migrations.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from dojo.finding.vulnerability_id import resolve_vulnerability_id_type
1010
from dojo.models import (
11+
Development_Environment,
1112
Engagement,
1213
Finding,
1314
FindingVulnerabilityReference,
@@ -198,12 +199,17 @@ class TestVulnerabilityIdBackfill(TestCase):
198199
def setUpTestData(cls):
199200
now = timezone.now()
200201
prod_type = Product_Type.objects.create(name="vulnid-pt")
201-
product = Product.objects.create(prod_type=prod_type, name="vulnid-prod")
202+
# description / scan_type / environment are required under full model validation
203+
# (base save full_clean when V3_FEATURE_LOCATIONS is on — the CI "(true)" matrix leg).
204+
product = Product.objects.create(prod_type=prod_type, name="vulnid-prod", description="vuln-id backfill test")
202205
engagement = Engagement.objects.create(product=product, target_start=now, target_end=now)
203206
test_type = Test_Type.objects.create(name="vulnid-tt")
207+
environment = Development_Environment.objects.get_or_create(name="Development")[0]
204208
test = Test.objects.create(
205209
engagement=engagement,
206210
test_type=test_type,
211+
scan_type="vulnid-tt",
212+
environment=environment,
207213
target_start=now,
208214
target_end=now,
209215
)

unittests/test_vulnerability_id.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from dojo.finding.api.serializer import VulnerabilityIdsField
1616
from dojo.finding.helper import save_vulnerability_ids
1717
from dojo.models import (
18+
Development_Environment,
1819
Engagement,
1920
Finding,
2021
FindingVulnerabilityReference,
@@ -36,11 +37,17 @@ class VulnerabilityIdDualWriteTestCase(TestCase):
3637
@classmethod
3738
def setUpTestData(cls):
3839
cls.prod_type = Product_Type.objects.create(name="vulnid-dw-pt")
39-
cls.product = Product.objects.create(prod_type=cls.prod_type, name="vulnid-dw-prod")
40+
# description / scan_type / environment are required under full model validation
41+
# (base save full_clean when V3_FEATURE_LOCATIONS is on — the CI "(true)" matrix leg).
42+
cls.product = Product.objects.create(
43+
prod_type=cls.prod_type, name="vulnid-dw-prod", description="vuln-id dual-write tests",
44+
)
4045
cls.engagement = Engagement.objects.create(product=cls.product, target_start=now(), target_end=now())
4146
cls.test_type = Test_Type.objects.create(name="vulnid-dw-tt")
47+
cls.environment = Development_Environment.objects.get_or_create(name="Development")[0]
4248
cls.test = Test.objects.create(
43-
engagement=cls.engagement, test_type=cls.test_type, target_start=now(), target_end=now(),
49+
engagement=cls.engagement, test_type=cls.test_type, scan_type="vulnid-dw-tt",
50+
environment=cls.environment, target_start=now(), target_end=now(),
4451
)
4552
cls.user = get_user_model().objects.create(username="vulnid-dw-user")
4653

0 commit comments

Comments
 (0)