Example #1
0
    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()
Example #2
0
    def test_crud_report(self):
        # Create
        report = ReportFactory(title="New Report")

        # Read
        self.assertEqual(report.title, "New Report")
        self.assertEqual(report.pk, report.id)
        self.assertEqual(len(self.Report.objects.all()), 1)
        self.assertEqual(self.Report.objects.first(), report)

        # Update
        report.title = "Updated Report"
        report.save()
        self.assertEqual(report.title, "Updated Report")

        # Delete
        report.delete()
        assert not self.Report.objects.all().exists()