예제 #1
0
 def test_doesnt_pair_subs_with_differing_names(self):
     org = Organization.objects.get(slug='a_pubdef')
     a_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabola")
     b_name = dict(
         first_name="Joseph",
         middle_name="H",
         last_name="Conic Intersection")
     factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **a_name),
         organizations=[org],
     )
     factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     dups = SubmissionsService.find_duplicates(
         FormSubmission.objects.all())
     self.assertFalse(dups)
예제 #2
0
 def test_finds_subs_with_similar_names(self):
     org = Organization.objects.get(slug='a_pubdef')
     a_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabola")
     b_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabole")
     a = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **a_name),
         organizations=[org],
     )
     b = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     c = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     dups = SubmissionsService.find_duplicates(
         FormSubmission.objects.all())
     pair = dups[0]
     for sub in (a, b, c):
         self.assertIn(sub, pair)
예제 #3
0
 def test_finds_subs_with_similar_names(self):
     org = Organization.objects.get(slug='a_pubdef')
     a_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabola")
     b_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabole")
     a = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **a_name),
         organizations=[org],
     )
     b = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     c = factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     dups = SubmissionsService.find_duplicates(
         FormSubmission.objects.all())
     pair = dups[0]
     for sub in (a, b, c):
         self.assertIn(sub, pair)
예제 #4
0
 def test_doesnt_pair_subs_with_differing_names(self):
     org = Organization.objects.get(slug='a_pubdef')
     a_name = dict(
         first_name="Joe",
         middle_name="H",
         last_name="Parabola")
     b_name = dict(
         first_name="Joseph",
         middle_name="H",
         last_name="Conic Intersection")
     factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **a_name),
         organizations=[org],
     )
     factories.FormSubmissionWithOrgsFactory.create(
         answers=get_answers_for_orgs(
             [org],
             **b_name),
         organizations=[org],
     )
     dups = SubmissionsService.find_duplicates(
         FormSubmission.objects.all())
     self.assertFalse(dups)
예제 #5
0
 def test_expected_weekday_run(self, is_the_weekend):
     is_the_weekend.return_value = False
     org = Organization.objects.get(slug='ebclc')
     dates = sorted([mock.get_old_date() for i in range(464, 469)])
     for date, pk in zip(dates, range(464, 469)):
         factories.FormSubmissionWithOrgsFactory.create(
             id=pk,
             date_received=date,
             organizations=[org],
             answers=get_answers_for_orgs(
                 [org],
                 contact_preferences=[
                     'prefers_email',
                     'prefers_sms'],
                 phone='4445551111',
                 email='*****@*****.**',
             ))
     command = send_followups.Command()
     command.stdout = Mock()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         command.handle()
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 4})
예제 #6
0
 def test_notifications_slacks_and_logs_for_full_contact_preferences(self):
     applicant = Applicant()
     applicant.save()
     answers = get_answers_for_orgs(
         self.get_orgs(),
         contact_preferences=[
             'prefers_email', 'prefers_sms', 'prefers_voicemail',
             'prefers_snailmail'
         ],
         email='*****@*****.**',
         phone_number='5554442222',
     )
     sub = factories.FormSubmissionWithOrgsFactory.create(
         applicant=applicant,
         organizations=self.get_orgs(),
         answers=answers)
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.email_confirmation.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.sms_confirmation.send.mock_calls), 1)
     self.assertEqual(
         applicant.events.filter(
             name=ApplicationEvent.CONFIRMATION_SENT).count(), 2)
예제 #7
0
 def test_notifications_slacks_and_logs_for_full_contact_preferences(self):
     applicant = factories.ApplicantFactory()
     answers = get_answers_for_orgs(
         self.get_orgs(),
         contact_preferences=[
             'prefers_email',
             'prefers_sms',
             'prefers_voicemail',
             'prefers_snailmail'
         ],
         email='*****@*****.**',
         phone_number='5554442222',
     )
     sub = factories.FormSubmissionWithOrgsFactory.create(
         applicant=applicant,
         organizations=self.get_orgs(),
         answers=answers)
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.email_confirmation.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.sms_confirmation.send.mock_calls), 1)
     assertInLogsCount(logs, {'event_name=app_confirmation_sent': 1})
예제 #8
0
 def test_expected_weekday_run(self, slack, is_the_weekend):
     is_the_weekend.return_value = False
     org = Organization.objects.get(slug='ebclc')
     dates = sorted([mock.get_old_date() for i in range(464, 469)])
     for date, pk in zip(dates, range(464, 469)):
         factories.FormSubmissionWithOrgsFactory.create(
             id=pk,
             date_received=date,
             organizations=[org],
             answers=get_answers_for_orgs(
                 [org],
                 contact_preferences=[
                     'prefers_email',
                     'prefers_sms'],
                 phone='4445551111',
                 email='*****@*****.**',
             ))
     command = send_followups.Command()
     command.stdout = Mock()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         command.handle()
     self.assertEqual(
         len(slack.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 4)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 4})
예제 #9
0
 def test_notifications_slacks_and_logs_for_full_contact_preferences(self):
     applicant = factories.ApplicantFactory()
     answers = get_answers_for_orgs(
         self.get_orgs(),
         contact_preferences=[
             'prefers_email',
             'prefers_sms'
         ],
         email='*****@*****.**',
         phone_number='4152124848',
     )
     sub = factories.FormSubmissionWithOrgsFactory.create(
         applicant=applicant,
         organizations=self.get_orgs(),
         answers=answers)
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.email_confirmation.send.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.sms_confirmation.send.mock_calls), 1)
     assertInLogsCount(logs, {'event_name=app_confirmation_sent': 1})
예제 #10
0
 def cant_contact_answers(self):
     org = Organization.objects.get(slug=Organizations.ALAMEDA_PUBDEF)
     return get_answers_for_orgs(
         [org],
         contact_preferences=['prefers_voicemail', 'prefers_snailmail'],
         email='*****@*****.**',
         phone_number='5554443333')
예제 #11
0
 def test_expected_weekday_run(self, slack, is_the_weekend):
     is_the_weekend.return_value = False
     org = Organization.objects.get(slug='ebclc')
     dates = sorted([mock.get_old_date() for i in range(464, 469)])
     for date, pk in zip(dates, range(464, 469)):
         applicant = Applicant()
         applicant.save()
         factories.FormSubmissionWithOrgsFactory.create(
             id=pk,
             applicant=applicant,
             date_received=date,
             organizations=[org],
             answers=get_answers_for_orgs(
                 [org],
                 contact_preferences=[
                     'prefers_email',
                     'prefers_sms'],
                 phone='4445551111',
                 email='*****@*****.**',
             ))
     command = send_followups.Command()
     command.stdout = Mock()
     command.handle()
     self.assertEqual(
         len(slack.mock_calls), 1)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 4)
예제 #12
0
 def cant_contact_answers(self):
     org = Organization.objects.get(slug='a_pubdef')
     return get_answers_for_orgs(
         [org],
         contact_preferences=['prefers_voicemail', 'prefers_snailmail'],
         email='*****@*****.**',
         phone_number='4152124848')
예제 #13
0
 def cant_contact_answers(self):
     org = Organization.objects.get(slug='a_pubdef')
     return get_answers_for_orgs(
         [org],
         contact_preferences=[
             'prefers_voicemail',
             'prefers_snailmail'],
         email='*****@*****.**',
         phone_number='4152124848'
     )
예제 #14
0
 def cant_contact_answers(self):
     org = Organization.objects.get(slug=Organizations.ALAMEDA_PUBDEF)
     return get_answers_for_orgs(
         [org],
         contact_preferences=[
             'prefers_voicemail',
             'prefers_snailmail'],
         email='*****@*****.**',
         phone_number='5554443333'
     )
예제 #15
0
 def test_notifications_with_only_partner_counties(self, send):
     orgs = [Organization.objects.get(slug='cc_pubdef')]
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=orgs,
         answers=get_answers_for_orgs(
             orgs, contact_preferences=['prefers_email', 'prefers_sms']))
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(len(send.mock_calls), 2)
     sms_body, email_body = get_notification_bodies(send)
     self.assertIn(orgs[0].short_confirmation_message, sms_body)
     self.assertIn(orgs[0].long_confirmation_message, email_body)
     self.assertNotIn("we'll contact you in the next week", sms_body)
     self.assertNotIn("We will contact you in the next week", email_body)
예제 #16
0
 def test_notifications_with_only_partner_counties(self, send):
     orgs = [Organization.objects.get(slug='cc_pubdef')]
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=orgs,
         answers=get_answers_for_orgs(
             orgs, contact_preferences=['prefers_email', 'prefers_sms']))
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(len(send.mock_calls), 2)
     sms_body, email_body = get_notification_bodies(send)
     self.assertIn(orgs[0].short_confirmation_message, sms_body)
     self.assertIn(orgs[0].long_confirmation_message, email_body)
     self.assertNotIn("we'll contact you in the next week", sms_body)
     self.assertNotIn("We will contact you in the next week", email_body)
예제 #17
0
 def create(cls, *args, **kwargs):
     if 'organizations' not in kwargs:
         kwargs['organizations'] = OrganizationFactory.sample()
     # set answers based on the designated organizations
     if 'answers' not in kwargs:
         kwargs['answers'] = get_answers_for_orgs(kwargs['organizations'])
     submission = super().create(*args, **kwargs)
     # adjust created and updated dates of applications to match
     # the form submission's faked date
     for app in submission.applications.all():
         app.created = submission.date_received
         app.save()
     return submission
예제 #18
0
 def test_notifications_with_only_unlisted_counties(self, send):
     orgs = [Organization.objects.get(slug='cfa')]
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=orgs,
         answers=get_answers_for_orgs(
             orgs, unlisted_counties="O‘Duinn County",
             contact_preferences=['prefers_email', 'prefers_sms']))
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(len(send.mock_calls), 2)
     sms_body, email_body = get_notification_bodies(send)
     self.assertIn("O‘Duinn County", sms_body)
     self.assertIn("O‘Duinn County", email_body)
     self.assertIn("we'll contact you in the next week", sms_body)
     self.assertIn("We will contact you in the next week", email_body)
 def create(cls, *args, **kwargs):
     if 'organizations' not in kwargs:
         kwargs['organizations'] = ExistingOrganizationFactory.sample(
             random.randint(1, 3))
     # set answers based on the designated organizations
     if 'answers' not in kwargs:
         kwargs['answers'] = get_answers_for_orgs(kwargs['organizations'])
     submission = super().create(*args, **kwargs)
     # adjust created and updated dates of applications to match
     # the form submission's faked date
     for app in submission.applications.all():
         app.created = submission.date_received
         app.save()
     return submission
예제 #20
0
 def test_notifications_with_only_unlisted_counties(self, send):
     orgs = [Organization.objects.get(slug='cfa')]
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=orgs,
         answers=get_answers_for_orgs(
             orgs, unlisted_counties="O‘Duinn County",
             contact_preferences=['prefers_email', 'prefers_sms']))
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(len(send.mock_calls), 2)
     sms_body, email_body = get_notification_bodies(send)
     self.assertIn("O‘Duinn County", sms_body)
     self.assertIn("O‘Duinn County", email_body)
     self.assertIn("we'll contact you in the next week", sms_body)
     self.assertIn("We will contact you in the next week", email_body)
예제 #21
0
 def make_full_submission(self, orgs, **answer_overrides):
     answers = get_answers_for_orgs(
         orgs,
         first_name="Hubert",
         contact_preferences=[
             'prefers_email', 'prefers_sms', 'prefers_voicemail',
             'prefers_snailmail'
         ],
         email='*****@*****.**',
         phone_number='5554442222',
     )
     answers.update(answer_overrides)
     return factories.FormSubmissionWithOrgsFactory.create(
         date_received=get_old_date(),
         anonymous_name="Cerulean Beetle",
         organizations=orgs,
         answers=answers)
예제 #22
0
 def test_notifications_and_logs_for_no_contact_preferences(self):
     applicant = factories.ApplicantFactory()
     answers = get_answers_for_orgs(
         self.get_orgs(),
         contact_preferences=[],
         email='*****@*****.**',
         phone_number='4152124848',
     )
     sub = factories.FormSubmissionWithOrgsFactory.create(
         applicant=applicant,
         organizations=self.get_orgs(),
         answers=answers)
     # does not log so no logs
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(
         len(self.notifications.email_confirmation.send.mock_calls), 0)
     self.assertEqual(
         len(self.notifications.sms_confirmation.send.mock_calls), 0)
예제 #23
0
 def test_notifications_and_logs_for_no_contact_preferences(self):
     applicant = factories.ApplicantFactory()
     answers = get_answers_for_orgs(
         self.get_orgs(),
         contact_preferences=[],
         email='*****@*****.**',
         phone_number='4152124848',
     )
     sub = factories.FormSubmissionWithOrgsFactory.create(
         applicant=applicant,
         organizations=self.get_orgs(),
         answers=answers)
     # does not log so no logs
     SubmissionsService.send_confirmation_notifications(sub)
     self.assertEqual(
         len(self.notifications.email_confirmation.send.mock_calls), 0)
     self.assertEqual(
         len(self.notifications.sms_confirmation.send.mock_calls), 0)
 def make_full_submission(self, orgs, **answer_overrides):
     answers = get_answers_for_orgs(
         orgs,
         first_name="Hubert",
         contact_preferences=[
             'prefers_email',
             'prefers_sms',
             'prefers_voicemail',
             'prefers_snailmail'
         ],
         email='*****@*****.**',
         phone_number='5554442222',
     )
     answers.update(answer_overrides)
     return factories.FormSubmissionWithOrgsFactory.create(
         date_received=get_old_date(),
         anonymous_name="Cerulean Beetle",
         organizations=orgs,
         answers=answers
     )