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})
def test_notifications_slacks_and_logs_for_full_contact_preferences(self): applicant = Applicant() applicant.save() answers = mock.fake.alameda_pubdef_answers( contact_preferences=[ 'prefers_email', 'prefers_sms', 'prefers_voicemail', 'prefers_snailmail' ], email='*****@*****.**', phone_number='5554442222', ) sub = mock.FormSubmissionFactory.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)
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})
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)
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)
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 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 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 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 finalize_application(self, form): organizations = self.get_receiving_organizations(form) submission = SubmissionsService.create_submission( form, organizations, self.applicant.id) EventsService.form_submitted(self, submission) SubmissionsService.send_to_newapps_bundle_if_needed( submission, organizations=organizations) sent_confirmations = \ SubmissionsService.send_confirmation_notifications(submission) main_success_message = _("You have applied for help in " ) + oxford_comma(self.formatted_county_names) MessagesService.flash_success(self.request, main_success_message, *sent_confirmations)
def finalize_application(self, form): organizations = self.get_receiving_organizations(form) submission = SubmissionsService.create_submission( form, organizations, self.applicant.id) EventsService.form_submitted(self, submission) SubmissionsService.send_to_newapps_bundle_if_needed( submission, organizations=organizations) sent_confirmations = \ SubmissionsService.send_confirmation_notifications(submission) main_success_message = _( "You have applied for help in ") + oxford_comma( self.formatted_county_names) MessagesService.flash_success( self.request, main_success_message, *sent_confirmations)
def create_confirmations_for_user(self, submission): """Sends texts/emails to user and adds flash messages """ county_list = [ name + " County" for name in submission.get_nice_counties() ] joined_county_list = oxford_comma(county_list) full_message = _("You have applied for help in ") + joined_county_list messages.success(self.request, full_message) # send emails and texts sent_confirmations = \ SubmissionsService.send_confirmation_notifications(submission) for message in sent_confirmations: messages.success(self.request, message)
def test_notifications_slacks_and_logs_for_no_contact_preferences(self): applicant = Applicant() applicant.save() answers = get_answers_for_orgs( self.get_orgs(), contact_preferences=[], 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), 0) self.assertEqual( len(self.notifications.email_confirmation.send.mock_calls), 0) self.assertEqual( len(self.notifications.sms_confirmation.send.mock_calls), 0) self.assertEqual( applicant.events.filter( name=ApplicationEvent.CONFIRMATION_SENT).count(), 0)
def finalize_application(self, form): organizations = self.get_receiving_organizations(form) submission = SubmissionsService.create_submission( form, organizations, self.applicant.id) SubmissionsService.fill_pdfs_for_submission( submission, organizations=organizations) number = models.FormSubmission.objects.count() notifications.slack_new_submission.send(submission=submission, request=self.request, submission_count=number) sent_confirmations = \ SubmissionsService.send_confirmation_notifications(submission) main_success_message = _("You have applied for help in " ) + oxford_comma(self.formatted_county_names) MessagesService.flash_success(self.request, main_success_message, *sent_confirmations)
def finalize_application(self, form): organizations = self.get_receiving_organizations(form) submission = SubmissionsService.create_submission( form, organizations, self.applicant.id) EventsService.form_submitted(submission) SubmissionsService.fill_pdfs_for_submission( submission, organizations=organizations) number = models.FormSubmission.objects.count() notifications.slack_new_submission.send( submission=submission, request=self.request, submission_count=number) sent_confirmations = \ SubmissionsService.send_confirmation_notifications(submission) main_success_message = _( "You have applied for help in ") + oxford_comma( self.formatted_county_names) MessagesService.flash_success( self.request, main_success_message, *sent_confirmations)