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)
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_create_sub_with_existing_duplicate(self): applicant = Applicant() applicant.save() answers = mock.fake.all_county_answers() org = Organization.objects.filter(is_receiving_agency=True).first() Form = county_form_selector.get_combined_form_class( counties=ALL_COUNTY_SLUGS) form = Form(answers, validate=True) a = SubmissionsService.create_submission(form, [org], applicant.id) self.assertFalse(a.duplicate_set_id) answers['last_name'] += 's' form = Form(answers, validate=True) b = SubmissionsService.create_submission(form, [org], applicant.id) self.assertTrue(b.duplicate_set_id) dup_set_subs = list(b.duplicate_set.submissions.all()) for sub in (a, b): self.assertIn(sub, dup_set_subs)
def test_can_create_with_form_orgs_and_app_id(self): # given an applicant, some orgs, and a validated form applicant = Applicant() applicant.save() organizations = list(Organization.objects.all()[:2]) Form = county_form_selector.get_combined_form_class( counties=ALL_COUNTY_SLUGS) form = Form(mock.fake.all_county_answers(), validate=True) # make a submission submission = SubmissionsService.create_submission( form, organizations, applicant.id) # assert that the correct event was created events = ApplicationEvent.objects.filter( applicant_id=applicant.id).all() self.assertEqual(len(events), 1) self.assertEqual(events[0].name, ApplicationEvent.APPLICATION_SUBMITTED) self.assertEqual(submission.applicant_id, applicant.id) self.assertEqual(set(submission.organizations.all()), set(organizations))
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)