def test_deleted_report_doesnt_delete_sent_match_report(self): match_report = MatchReport(report=self.report, identifier='dummy') match_report.encrypt_match_report("test match report", 'dummy') match_report.save() user2 = User.objects.create_user(username="******", password="******") report2 = Report(owner=user2) report2.encrypt_report("test report 2", "key") report2.save() match_report2 = MatchReport(report=report2, identifier='dummy') match_report2.encrypt_match_report("test match report 2", 'dummy') match_report2.save() sent_match_report = SentMatchReport.objects.create() sent_match_report.reports.add(match_report, match_report2) self.report.match_found = True self.report.save() report2.match_found = True report2.save() self.assertIsNotNone(match_report.sentmatchreport_set.first()) self.assertIsNotNone(match_report2.sentmatchreport_set.first()) self.assertEqual(match_report, SentMatchReport.objects.first().reports.all()[0]) self.assertEqual(match_report2, SentMatchReport.objects.first().reports.all()[1]) self.report.delete() self.assertEqual(Report.objects.count(), 1) self.assertEqual(MatchReport.objects.count(), 1) self.assertEqual(SentMatchReport.objects.first(), sent_match_report) self.assertEqual(SentMatchReport.objects.first().reports.count(), 1) self.assertEqual(SentMatchReport.objects.first().reports.first(), match_report2) self.assertTrue(Report.objects.first().match_found) report2.delete() self.assertEqual(Report.objects.count(), 0) self.assertEqual(SentMatchReport.objects.first(), sent_match_report)