def test_does_notify_on_reported_reports(self): with patch.object(CustomNotificationApi, 'log_action') as api_logging: self.create_match(self.user1, 'test1') match_report = self.create_match(self.user2, 'test1', alert=False) match_report.report.submitted_to_school = timezone.now() match_report.report.save() MatchingApi.find_matches('test1') self.assertNotEqual(api_logging.call_count, 2) # old behavior self.assertEqual(api_logging.call_count, 3) # new behavior
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 = security.pepper( _legacy_encrypt_report( salt, identifier, json.dumps( report_content.__dict__))) match_report = MatchReport.objects.create( report=report2, identifier=identifier, encrypted=encrypted_report, salt=salt) MatchingApi.find_matches('test_identifier') # have to use ANY because objects in migration tests are faked mock_process.assert_called_once_with([ANY, ANY], 'test_identifier')
def create_match(self, user, identifier): self.most_recent_report = Report(owner=user) self.most_recent_report.encrypt_record("test report 1", "key") match_report = MatchReport(report=self.most_recent_report) match_report_content = MatchReportContent( identifier=identifier, perp_name=identifier, email='*****@*****.**', phone="123", ) match_report.encrypt_match_report( json.dumps(match_report_content.__dict__), identifier, ) matches = MatchingApi.find_matches(identifier) return matches
def create_match(self, user, identifier): self.most_recent_report = Report(owner=user) self.most_recent_report.encrypt_record("test report 1", "key") match_report = MatchReport(report=self.most_recent_report) match_report_content = MatchReportContent( identifier=identifier, perp_name=identifier, email="*****@*****.**", phone="123", ) match_report.encrypt_match_report( json.dumps(match_report_content.__dict__), identifier) matches = MatchingApi.find_matches(identifier) return matches
def _get_matches(self, identifier): return MatchingApi.find_matches(identifier)
def test_abritrary_method_names_can_be_used(self): self.assertEqual( MatchingApi.send_claws_to_scratch_couch(), None, )
def test_overridden_api_call(self, mock_process): MatchingApi.find_matches('arg1') mock_process.assert_called_once_with('arg1')
def test_abritrary_method_names_can_be_used(self): self.assertEqual(MatchingApi.send_claws_to_scratch_couch(), None)
def test_overridden_api_call(self, mock_process): MatchingApi.find_matches("arg1") mock_process.assert_called_once_with("arg1")