Esempio n. 1
0
 def test_case_when_all_have_usable_contact_info(self):
     orgs = [Organization.objects.get(slug=Organizations.ALAMEDA_PUBDEF)]
     subs = []
     for i in range(4):
         applicant = models.Applicant()
         applicant.save()
         subs.append(
             mock.FormSubmissionFactory.create(
                 applicant=applicant,
                 organizations=orgs,
                 answers=self.full_answers(),
             ))
     FollowupsService.send_followup_notifications(subs)
     self.assertEqual(
         FollowupsService.get_submissions_due_for_follow_ups().count(), 0)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     self.assertEqual(len(self.notifications.sms_followup.send.mock_calls),
                      0)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 4)
     followup_events = models.ApplicationEvent.objects.filter(
         name=models.ApplicationEvent.FOLLOWUP_SENT)
     self.assertEqual(followup_events.count(), 4)
     followed_up_app_ids = set(
         followup_events.values_list('applicant_id', flat=True))
     for sub in subs:
         self.assertIn(sub.applicant_id, followed_up_app_ids)
Esempio n. 2
0
 def test_if_some_have_usable_contact_info(self):
     orgs = [Organization.objects.get(slug='a_pubdef')]
     contacted_subs = []
     for i in range(2):
         contacted_subs.append(
             factories.FormSubmissionWithOrgsFactory.create(
                 organizations=orgs, answers=self.full_answers()))
     not_contacted_subs = []
     for i in range(2):
         not_contacted_subs.append(
             factories.FormSubmissionWithOrgsFactory.create(
                 organizations=orgs, answers=self.cant_contact_answers()))
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         FollowupsService.send_followup_notifications(contacted_subs +
                                                      not_contacted_subs)
     self.assertEqual(
         FollowupsService.get_submissions_due_for_follow_ups().count(), 0)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 2)
     self.assertEqual(len(self.notifications.sms_followup.send.mock_calls),
                      0)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 2)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 2})
     for sub in contacted_subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 1})
         self.assertEqual(sub.has_been_sent_followup, True)
     for sub in not_contacted_subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 0})
         self.assertEqual(sub.has_been_sent_followup, False)
Esempio n. 3
0
 def test_if_some_have_usable_contact_info(self):
     orgs = [
         Organization.objects.get(slug=Organizations.ALAMEDA_PUBDEF)]
     contacted_subs = []
     for i in range(2):
         contacted_subs.append(
             factories.FormSubmissionWithOrgsFactory.create(
                 organizations=orgs,
                 answers=self.full_answers()))
     not_contacted_subs = []
     for i in range(2):
         not_contacted_subs.append(
             factories.FormSubmissionWithOrgsFactory.create(
                 organizations=orgs,
                 answers=self.cant_contact_answers()))
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         FollowupsService.send_followup_notifications(
             contacted_subs + not_contacted_subs)
     self.assertEqual(
         FollowupsService.get_submissions_due_for_follow_ups().count(), 0)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 2)
     self.assertEqual(
         len(self.notifications.sms_followup.send.mock_calls), 0)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 2)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 2})
     for sub in contacted_subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 1})
         self.assertEqual(sub.has_been_sent_followup, True)
     for sub in not_contacted_subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 0})
         self.assertEqual(sub.has_been_sent_followup, False)
Esempio n. 4
0
 def test_that_followup_messages_only_include_followup_orgs(self):
     sub = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[self.non_followup_org, self.followup_org])
     sub.answers.update(phone_number='8314207603',
                        contact_preferences=['prefers_sms'])
     sub.save()
     FollowupsService.send_followup_notifications([sub])
     mock_args, mock_kwargs = self.notifications.sms_followup.send.call_args
     self.assertNotIn(self.non_followup_org.short_followup_message,
                      mock_kwargs['followup_messages'])
     self.assertIn(self.followup_org.short_followup_message,
                   mock_kwargs['followup_messages'])
Esempio n. 5
0
 def test_that_followup_messages_only_include_followup_orgs(self):
     sub = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[self.non_followup_org, self.followup_org])
     sub.answers.update(
         phone_number='8314207603', contact_preferences=['prefers_sms'])
     sub.save()
     FollowupsService.send_followup_notifications([sub])
     mock_args, mock_kwargs = self.notifications.sms_followup.send.call_args
     self.assertNotIn(
         self.non_followup_org.short_followup_message,
         mock_kwargs['followup_messages'])
     self.assertIn(
         self.followup_org.short_followup_message,
         mock_kwargs['followup_messages'])
Esempio n. 6
0
 def test_that_followup_messages_arent_sent_for_apps_w_updates(self):
     org_a, org_b = Organization.objects.filter(
         is_receiving_agency=True)[:2]
     sub = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[org_a, org_b])
     sub.answers.update(phone_number='8314207603',
                        contact_preferences=['prefers_sms'])
     sub.save()
     updated_app = sub.applications.filter(organization_id=org_a.id).first()
     author = org_a.profiles.first().user
     factories.StatusUpdateWithNotificationFactory.create(
         application=updated_app, author=author)
     FollowupsService.send_followup_notifications([sub])
     mock_args, mock_kwargs = self.notifications.sms_followup.send.call_args
     self.assertNotIn(org_a.short_followup_message,
                      mock_kwargs['followup_messages'])
Esempio n. 7
0
 def test_that_followup_messages_arent_sent_for_apps_w_updates(self):
     org_a, org_b = Organization.objects.filter(
         is_receiving_agency=True)[:2]
     sub = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[org_a, org_b])
     sub.answers.update(
         phone_number='8314207603', contact_preferences=['prefers_sms'])
     sub.save()
     updated_app = sub.applications.filter(organization_id=org_a.id).first()
     author = org_a.profiles.first().user
     factories.StatusUpdateWithNotificationFactory.create(
         application=updated_app, author=author)
     FollowupsService.send_followup_notifications([sub])
     mock_args, mock_kwargs = self.notifications.sms_followup.send.call_args
     self.assertNotIn(
         org_a.short_followup_message, mock_kwargs['followup_messages'])
Esempio n. 8
0
 def test_case_when_all_have_usable_contact_info(self):
     orgs = [
         Organization.objects.get(slug='a_pubdef')]
     subs = []
     for i in range(4):
         subs.append(factories.FormSubmissionWithOrgsFactory.create(
             organizations=orgs,
             answers=self.full_answers(),
         ))
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         FollowupsService.send_followup_notifications(subs)
     self.assertEqual(
         FollowupsService.get_submissions_due_for_follow_ups().count(), 0)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     self.assertEqual(
         len(self.notifications.sms_followup.send.mock_calls), 0)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 4})
     for sub in subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 1})
         self.assertEqual(sub.has_been_sent_followup, True)
Esempio n. 9
0
 def test_case_when_all_have_usable_contact_info(self):
     orgs = [Organization.objects.get(slug=Organizations.ALAMEDA_PUBDEF)]
     subs = []
     for i in range(4):
         subs.append(
             factories.FormSubmissionWithOrgsFactory.create(
                 organizations=orgs,
                 answers=self.full_answers(),
             ))
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         FollowupsService.send_followup_notifications(subs)
     self.assertEqual(
         FollowupsService.get_submissions_due_for_follow_ups().count(), 0)
     self.assertEqual(
         len(self.notifications.email_followup.send.mock_calls), 4)
     self.assertEqual(len(self.notifications.sms_followup.send.mock_calls),
                      0)
     self.assertEqual(
         len(self.notifications.slack_notification_sent.send.mock_calls), 4)
     assertInLogsCount(logs, {'event_name=app_followup_sent': 4})
     for sub in subs:
         assertInLogsCount(logs, {'distinct_id=' + sub.get_uuid(): 1})
         self.assertEqual(sub.has_been_sent_followup, True)