def setUpTestData(cls): cls.group_1 = GroupFactory(name="Group 1") cls.group_2 = GroupFactory(name="Group 2") cls.user = UserFactory(password=PASSWORD, groups=(cls.group_1, )) cls.project = ProjectFactory() cls.report = ReportFactory(project=cls.project) cls.num_of_findings = 3 ReportFindingLinkFactory.create_batch(cls.num_of_findings, report=cls.report, assigned_to=cls.user) cls.uri = reverse("home:dashboard")
def test_model_cleaning_severity_and_positon_changes(self): report = ReportFactory() num_of_findings = 5 findings = [] for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.critical_severity), ) for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.high_severity), ) # Bounce findings around to shuffle positions several times findings[8].severity = self.critical_severity findings[8].position = 2 findings[8].save() findings[5].severity = self.critical_severity findings[5].position = 1 findings[5].save() findings[3].severity = self.high_severity findings[3].position = 2 findings[3].save() cleaned_findings = [] for f in findings: f.refresh_from_db() cleaned_findings.append(f) # Assert ``severity`` and ``position`` changes committed correctly self.assertEqual(cleaned_findings[8].severity, self.critical_severity) self.assertEqual(cleaned_findings[8].position, 3) self.assertEqual(cleaned_findings[5].severity, self.critical_severity) self.assertEqual(cleaned_findings[5].position, 1) self.assertEqual(cleaned_findings[3].severity, self.high_severity) self.assertEqual(cleaned_findings[3].position, 2) # Assert the ``position`` values updated properly for "Critical" self.assertEqual(cleaned_findings[5].position, 1) self.assertEqual(cleaned_findings[0].position, 2) self.assertEqual(cleaned_findings[8].position, 3) self.assertEqual(cleaned_findings[1].position, 4) self.assertEqual(cleaned_findings[2].position, 5) self.assertEqual(cleaned_findings[4].position, 6) # Assert the ``position`` values updated properly for "High" self.assertEqual(cleaned_findings[5].position, 1) self.assertEqual(cleaned_findings[3].position, 2) self.assertEqual(cleaned_findings[7].position, 3) self.assertEqual(cleaned_findings[9].position, 4)
def setUpTestData(cls): cls.user = UserFactory(password=PASSWORD) cls.Project = ProjectFactory._meta.model cls.ProjectAssignment = ProjectAssignmentFactory._meta.model cls.ReportFindingLink = ReportFindingLinkFactory._meta.model cls.current_project = ProjectFactory( start_date=date.today() - timedelta(days=14), end_date=date.today(), complete=True ) cls.future_project = ProjectFactory( start_date=date.today() + timedelta(days=14), end_date=date.today() + timedelta(days=28), complete=False ) ProjectAssignmentFactory( project=cls.current_project, operator=cls.user, start_date=date.today(), end_date=date.today() + timedelta(days=14), ) ProjectAssignmentFactory( project=cls.future_project, operator=cls.user, start_date=date.today() + timedelta(days=14), end_date=date.today() + timedelta(days=28), ) cls.report = ReportFactory(project=cls.current_project) ReportFindingLinkFactory.create_batch(3, report=cls.report, assigned_to=cls.user) cls.user_tasks = ( cls.ReportFindingLink.objects.select_related("report", "report__project") .filter( Q(assigned_to=cls.user) & Q(report__complete=False) & Q(complete=False) ) .order_by("report__project__end_date")[:10] ) cls.user_projects = cls.ProjectAssignment.objects.select_related( "project", "project__client", "role" ).filter(Q(operator=cls.user)) cls.active_projects = cls.ProjectAssignment.objects.select_related( "project", "project__client", "role" ).filter(Q(operator=cls.user) & Q(project__complete=False)) cls.uri = reverse("home:dashboard")
def test_model_cleaning_position(self): report = ReportFactory() num_of_findings = 10 findings = [] for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.critical_severity) ) # New position values first_pos = 1 second_pos = 2 # Bump first finding from ``1`` to new value findings[0].position = second_pos findings[0].save() cleaned_findings = [] for f in findings: f.refresh_from_db() cleaned_findings.append(f) # Assert first finding is now in second position self.assertEqual(cleaned_findings[0].position, second_pos) # Assert second finding has moved into first positon self.assertEqual(cleaned_findings[1].position, first_pos) # Test triggering ``clean()`` method when parent ``Report`` is deleted report.delete()
def setUpTestData(cls): cls.finding = ReportFindingLinkFactory() cls.user = UserFactory(password=PASSWORD) cls.uri = reverse("reporting:convert_finding", kwargs={"pk": cls.finding.pk}) cls.redirect_uri = reverse( "reporting:finding_detail", kwargs={"pk": cls.finding.pk} )
def test_position_set_to_zero(self): report = ReportFactory() finding = ReportFindingLinkFactory(report=report, severity=self.critical_severity) finding.position = -10 finding.save() finding.refresh_from_db() # Assert the other ``position`` values updated properly self.assertEqual(finding.position, 1)
def setUpTestData(cls): cls.report = ReportFactory() cls.ReportFindingLink = ReportFindingLinkFactory._meta.model cls.user = UserFactory(password=PASSWORD) cls.num_of_findings = 10 cls.findings = [] for finding_id in range(cls.num_of_findings): title = f"Finding {finding_id}" cls.findings.append(ReportFindingLinkFactory(title=title, report=cls.report)) cls.uri = reverse("reporting:report_clone", kwargs={"pk": cls.report.pk})
def test_position_set_higher_than_count(self): report = ReportFactory() num_of_findings = 10 findings = [] for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.critical_severity)) findings[0].position = 100 findings[0].save() findings[0].refresh_from_db() # Assert the other ``position`` values updated properly self.assertEqual(findings[0].position, num_of_findings)
def setUpTestData(cls): cls.finding = ReportFindingLinkFactory() cls.evidence = EvidenceFactory(finding=cls.finding) cls.user = UserFactory(password=PASSWORD) cls.uri = reverse("reporting:upload_evidence", kwargs={"pk": cls.finding.pk}) cls.modal_uri = reverse( "reporting:upload_evidence_modal", kwargs={"pk": cls.finding.pk, "modal": "modal"}, ) cls.success_uri = reverse( "reporting:report_detail", args=(cls.finding.report.pk,) ) cls.modal_success_uri = reverse("reporting:upload_evidence_modal_success")
def test_position_change_on_delete(self): report = ReportFactory() num_of_findings = 5 findings = [] for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.critical_severity), ) for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.high_severity), ) # Delete several findings to create gaps in the severity groups # Need to use atomic because ``TestCase`` and a ``post_delete`` Signal with transaction.atomic(): findings[3].delete() findings[5].delete() findings[8].delete() cleaned_findings = [] for f in findings: try: f.refresh_from_db() cleaned_findings.append(f) except self.ReportFindingLink.DoesNotExist: pass # Assert the ``position`` values updated properly for "Critical" self.assertEqual(cleaned_findings[0].position, 1) self.assertEqual(cleaned_findings[1].position, 2) self.assertEqual(cleaned_findings[2].position, 3) self.assertEqual(cleaned_findings[3].position, 4) # Assert the ``position`` values updated properly for "High" self.assertEqual(cleaned_findings[4].position, 1) self.assertEqual(cleaned_findings[5].position, 2) self.assertEqual(cleaned_findings[6].position, 3)
def setUpTestData(cls): cls.report = ReportFactory( docx_template=ReportDocxTemplateFactory(), pptx_template=ReportPptxTemplateFactory(), ) cls.high_severity = SeverityFactory(severity="High", weight=1) cls.critical_severity = SeverityFactory(severity="Critical", weight=0) cls.user = UserFactory(password=PASSWORD) cls.new_user = UserFactory(password=PASSWORD) cls.num_of_findings = 10 cls.findings = [] for finding_id in range(cls.num_of_findings): title = f"Finding {finding_id}" cls.findings.append(ReportFindingLinkFactory(title=title, report=cls.report)) cls.uri = reverse("reporting:local_edit", kwargs={"pk": cls.findings[0].pk})
def test_crud_report_finding(self): # Create finding = ReportFindingLinkFactory(title="Attached Finding") # Read self.assertEqual(finding.title, "Attached Finding") self.assertEqual(finding.pk, finding.id) self.assertEqual(len(self.ReportFindingLink.objects.all()), 1) self.assertEqual(self.ReportFindingLink.objects.first(), finding) # Update finding.title = "Updated Finding" finding.save() self.assertEqual(finding.title, "Updated Finding") # Delete finding.delete() assert not self.ReportFindingLink.objects.all().exists()
def test_model_cleaning_severity_change(self): report = ReportFactory() num_of_findings = 10 findings = [] for finding_id in range(num_of_findings): findings.append( ReportFindingLinkFactory(report=report, severity=self.critical_severity)) # Bump the first half of the findings to the new severity in reverse order for f in reversed(range(5)): findings[f].severity = self.high_severity findings[f].save() cleaned_findings = [] for f in findings: f.refresh_from_db() cleaned_findings.append(f) # Assert severity was properly updated self.assertEqual(cleaned_findings[0].severity, self.high_severity) # Assert the positions were set properly self.assertEqual(cleaned_findings[5].position, 1) self.assertEqual(cleaned_findings[9].position, 5) self.assertEqual(cleaned_findings[0].position, 1) self.assertEqual(cleaned_findings[4].position, 5)
def setUpTestData(cls): cls.ReportFindingLink = ReportFindingLinkFactory._meta.model cls.report = ReportFactory() for x in range(3): ReportFindingLinkFactory(report=cls.report)
def test_prop_count_findings(self): project = ProjectFactory() report = ReportFactory(project=project) for x in range(3): ReportFindingLinkFactory(report=report) self.assertEqual(project.count_findings(), 3)
def setUpTestData(cls): cls.finding = ReportFindingLinkFactory()