|
6 | 6 | from dojo.finding.deduplication import set_duplicate |
7 | 7 | from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates |
8 | 8 | from dojo.models import Engagement, Finding, Product, User, copy_model_util |
| 9 | +from dojo.tasks import async_dupe_delete |
9 | 10 |
|
10 | 11 | from .dojo_test_case import DojoTestCase |
11 | 12 |
|
12 | 13 | logger = logging.getLogger(__name__) |
13 | 14 |
|
14 | 15 |
|
| 16 | +# tests here |
15 | 17 | class TestDuplicationLoops(DojoTestCase): |
16 | 18 | fixtures = ["dojo_testdata.json"] |
17 | 19 |
|
@@ -373,6 +375,26 @@ def test_list_relations_for_three_reverse(self): |
373 | 375 | self.assertEqual(self.finding_c.duplicate_finding_set().count(), 2) |
374 | 376 | self.assertEqual(self.finding_b.duplicate_finding_set().count(), 2) |
375 | 377 |
|
| 378 | + # Test that Delete Duplicate Findings & Maximum Duplicate is correctly deleting olding finding first based off of finding date value |
| 379 | + @override_settings(DELETE_DUPLICATE_FINDINGS=True) |
| 380 | + @override_settings(MAXIMUM_DUPLICATES=1) |
| 381 | + def test_delete_duplicate_order(self): |
| 382 | + self.finding_b.date = "2023-01-01" |
| 383 | + self.finding_c.date = "2024-01-01" |
| 384 | + set_duplicate(self.finding_b, self.finding_a) |
| 385 | + set_duplicate(self.finding_c, self.finding_a) |
| 386 | + |
| 387 | + async_dupe_delete() |
| 388 | + |
| 389 | + # Finding b should be deleted because it is the older finding |
| 390 | + |
| 391 | + # I think this is how you would access it from the database |
| 392 | + Finding.objects.get(id=self.finding_b.id) |
| 393 | + # Why am I still able to access finding b. It should be deleted??? |
| 394 | + |
| 395 | + self.assertEqual(self.finding_a.duplicate_finding_set().count(), 2) |
| 396 | + self.assertEqual(self.finding_a.duplicate_finding_set().first().id, self.finding_b.id) |
| 397 | + |
376 | 398 | def test_delete_all_engagements(self): |
377 | 399 | # make sure there is no exception when deleting all engagements |
378 | 400 | for engagement in Engagement.objects.all().order_by("id"): |
|
0 commit comments