Skip to content

Commit 69fbfc0

Browse files
committed
partial unittest written
1 parent d89695e commit 69fbfc0

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

unittests/test_duplication_loops.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from dojo.finding.deduplication import set_duplicate
77
from dojo.management.commands.fix_loop_duplicates import fix_loop_duplicates
88
from dojo.models import Engagement, Finding, Product, User, copy_model_util
9+
from dojo.tasks import async_dupe_delete
910

1011
from .dojo_test_case import DojoTestCase
1112

1213
logger = logging.getLogger(__name__)
1314

1415

16+
# tests here
1517
class TestDuplicationLoops(DojoTestCase):
1618
fixtures = ["dojo_testdata.json"]
1719

@@ -373,6 +375,26 @@ def test_list_relations_for_three_reverse(self):
373375
self.assertEqual(self.finding_c.duplicate_finding_set().count(), 2)
374376
self.assertEqual(self.finding_b.duplicate_finding_set().count(), 2)
375377

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+
376398
def test_delete_all_engagements(self):
377399
# make sure there is no exception when deleting all engagements
378400
for engagement in Engagement.objects.all().order_by("id"):

0 commit comments

Comments
 (0)