Example #1
0
 def test_doesnt_notify_on_reported_reports(self, mock_send_to_school, mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user2, 'dummy')
     report2.report.submitted_to_school = datetime.now()
     report2.report.save()
     find_matches()
     mock_send_email.assert_called_once_with(self.user1, report1)
Example #2
0
 def test_both_new_matches_sent_emails(self, mock_send_to_school, mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user2, 'dummy')
     find_matches()
     calls = [call(self.user1, report1), call(self.user2, report2)]
     mock_send_email.assert_has_calls(calls)
     self.assertEqual(mock_send_email.call_count, 2)
    def test_matches_after_encryption(self, mock_process):

        user1 = User.objects.create_user(username="******", password="******")
        Report = self.get_model_before('Report')
        report = Report(owner_id=user1.pk)
        report.save()
        MatchReport = self.get_model_before('MatchReport')
        identifier = "test_identifier"
        phone = "555-1212"
        user_name = "Maggie"
        email = "*****@*****.**"
        perp_name = "Perp"
        MatchReport.objects.create(report=report, identifier=identifier, contact_phone=phone,
                                   contact_name=user_name, contact_email=email,
                                   name=perp_name, seen=True)
        self.assertEqual(MatchReport.objects.count(), 1)

        self.run_migration()

        MatchReport = self.get_model_after('MatchReport')
        MatchReport.objects.first()
        user2 = User.objects.create_user(username="******", password="******")
        Report = self.get_model_after('Report')
        report2 = Report(owner_id=user2.pk)
        report2.save()
        report_content = MatchReportContent(identifier='test_identifier', perp_name='Perperick', contact_name='Rita',
                                            email='*****@*****.**', phone='555-555-1212')
        salt = get_random_string()
        encrypted_report = _pepper(_encrypt_report(salt, identifier, json.dumps(report_content.__dict__)))
        MatchReport.objects.create(report=report2, identifier=identifier, encrypted=encrypted_report,
                                   salt=salt)
        find_matches([identifier])
        # have to use ANY because objects in migration tests are faked
        mock_process.assert_called_once_with([ANY, ANY], 'test_identifier', PDFMatchReport)
Example #4
0
 def test_doesnt_notify_on_reported_reports(self, mock_send_to_school,
                                            mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user2, 'dummy')
     report2.report.submitted_to_school = datetime.now()
     report2.report.save()
     find_matches()
     mock_send_email.assert_called_once_with(self.user1, report1)
Example #5
0
 def test_both_new_matches_sent_emails(self, mock_send_to_school,
                                       mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user2, 'dummy')
     find_matches()
     calls = [call(self.user1, report1), call(self.user2, report2)]
     mock_send_email.assert_has_calls(calls)
     self.assertEqual(mock_send_email.call_count, 2)
Example #6
0
 def test_two_matching_reports_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     mock_process.assert_called_once_with([match1, match2])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #7
0
 def test_non_matching_reports_dont_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
Example #8
0
 def test_two_matching_reports_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     mock_process.assert_called_once_with([match1, match2])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #9
0
 def test_non_matching_reports_dont_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
Example #10
0
 def test_only_new_matches_sent_emails(self, mock_send_to_school, mock_send_email):
     self.create_match(self.user1, 'dummy')
     self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_send_email.called)
     mock_send_email.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     report3 = self.create_match(user3, 'dummy')
     find_matches()
     mock_send_email.assert_called_once_with(user3, report3)
Example #11
0
 def test_existing_match_still_triggers_on_new(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     match3 = self.create_match(user3, 'dummy')
     find_matches()
     mock_process.assert_called_once_with([match1, match2, match3])
Example #12
0
 def test_existing_match_still_triggers_on_new(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     match3 = self.create_match(user3, 'dummy')
     find_matches()
     mock_process.assert_called_once_with([match1, match2, match3])
Example #13
0
 def test_users_are_deduplicated(self, mock_send_to_school, mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user1, 'dummy')
     find_matches()
     self.assertFalse(mock_send_email.called)
     report3 = self.create_match(self.user2, 'dummy')
     find_matches()
     calls = [call(self.user1, report1), call(self.user2, report3)]
     mock_send_email.assert_has_calls(calls)
     self.assertEqual(mock_send_email.call_count, 2)
Example #14
0
    def handle(self, *args, **options):
        report_class_name = options['report_class']
        if report_class_name:
            module_name, class_name = report_class_name.rsplit(".", 1)
            ReportClass = getattr(importlib.import_module(module_name), class_name)
        else:
            ReportClass = PDFMatchReport

        find_matches(report_class=ReportClass)

        self.stdout.write('Matching run')
Example #15
0
 def test_only_new_matches_sent_emails(self, mock_send_to_school,
                                       mock_send_email):
     self.create_match(self.user1, 'dummy')
     self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_send_email.called)
     mock_send_email.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     report3 = self.create_match(user3, 'dummy')
     find_matches()
     mock_send_email.assert_called_once_with(user3, report3)
Example #16
0
 def test_users_are_deduplicated(self, mock_send_to_school,
                                 mock_send_email):
     report1 = self.create_match(self.user1, 'dummy')
     report2 = self.create_match(self.user1, 'dummy')
     find_matches()
     self.assertFalse(mock_send_email.called)
     report3 = self.create_match(self.user2, 'dummy')
     find_matches()
     calls = [call(self.user1, report1), call(self.user2, report3)]
     mock_send_email.assert_has_calls(calls)
     self.assertEqual(mock_send_email.call_count, 2)
Example #17
0
 def test_matches_only_triggered_by_different_people(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     match3 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
     self.assertFalse(match3.report.match_found)
Example #18
0
 def test_matches_only_triggered_by_different_people(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     match3 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
     self.assertFalse(match3.report.match_found)
Example #19
0
 def test_triggers_new_matches_only(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     self.create_match(user3, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #20
0
 def test_triggers_new_matches_only(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     user3 = User.objects.create_user(username="******", password="******")
     self.create_match(user3, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #21
0
 def test_existing_match_not_retriggered_by_same_reporter(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     match3 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
     self.assertTrue(match3.report.match_found)
Example #22
0
 def test_existing_match_not_retriggered_by_same_reporter(
         self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertTrue(mock_process.called)
     mock_process.reset_mock()
     match3 = self.create_match(self.user2, 'dummy')
     find_matches()
     self.assertFalse(mock_process.called)
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
     self.assertTrue(match3.report.match_found)
Example #23
0
 def test_error_during_processing_means_match_not_seen(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     mock_process.side_effect = [Exception('Boom!'), ()]
     try:
         find_matches()
     except:
         pass
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
     mock_process.reset_mock()
     find_matches()
     mock_process.assert_called_once_with([match1, match2])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #24
0
 def test_error_during_processing_means_match_not_seen(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy')
     mock_process.side_effect = [Exception('Boom!'), ()]
     try:
         find_matches()
     except:
         pass
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertFalse(match2.report.match_found)
     mock_process.reset_mock()
     find_matches()
     mock_process.assert_called_once_with([match1, match2])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     self.assertTrue(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
Example #25
0
 def test_three_way_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     user3 = User.objects.create_user(username="******", password="******")
     match3 = self.create_match(user3, 'dummy1')
     user4 = User.objects.create_user(username="******", password="******")
     match4 = self.create_match(user4, 'dummy1')
     find_matches()
     mock_process.assert_called_once_with([match2, match3, match4])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     match4.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
     self.assertTrue(match3.report.match_found)
     self.assertTrue(match4.report.match_found)
Example #26
0
 def test_three_way_match(self, mock_process):
     match1 = self.create_match(self.user1, 'dummy')
     match2 = self.create_match(self.user2, 'dummy1')
     find_matches()
     self.assertFalse(mock_process.called)
     user3 = User.objects.create_user(username="******", password="******")
     match3 = self.create_match(user3, 'dummy1')
     user4 = User.objects.create_user(username="******", password="******")
     match4 = self.create_match(user4, 'dummy1')
     find_matches()
     mock_process.assert_called_once_with([match2, match3, match4])
     match1.report.refresh_from_db()
     match2.report.refresh_from_db()
     match3.report.refresh_from_db()
     match4.report.refresh_from_db()
     self.assertFalse(match1.report.match_found)
     self.assertTrue(match2.report.match_found)
     self.assertTrue(match3.report.match_found)
     self.assertTrue(match4.report.match_found)
Example #27
0
 def handle(self, *args, **options):
     find_matches()
     self.stdout.write('Matching run')
Example #28
0
 def handle(self, *args, **options):
     find_matches()
     self.stdout.write('Matching run')