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_create_applicant_with_existing_visitor_and_applicant(self): existing_applicant = factories.ApplicantFactory() self.set_session(visitor_id=existing_applicant.visitor.id) response = self.client.fill_form( reverse('intake-apply'), counties=['alameda', 'contracosta']) self.assertEqual( response.wsgi_request.applicant, existing_applicant)
def test_there_can_be_only_one_applicant_per_visitor(self): # aka highlander test applicant = factories.ApplicantFactory() visitor = applicant.visitor second_applicant = models.Applicant(visitor_id=visitor.id) with self.assertRaises(IntegrityError): second_applicant.save() self.assertEqual(visitor.applicant, applicant)
def test_can_create_with_form_orgs_and_app_id(self): # given an applicant, some orgs, and a validated form applicant = factories.ApplicantFactory() 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) self.assertEqual(submission.applicant_id, applicant.id) self.assertEqual(set(submission.organizations.all()), set(organizations))
def test_filters_out_subs_with_previous_followups(self): # given old submissions, some with old followups no_followup = factories.FormSubmissionWithOrgsFactory.create( date_received=get_old_date(), organizations=[self.followup_org]) applicant = factories.ApplicantFactory() sub_w_followup = factories.FormSubmissionWithOrgsFactory.create( date_received=get_old_date(), applicant=applicant, organizations=[self.followup_org], has_been_sent_followup=True) # if we grab subs that need followups results = FollowupsService.get_submissions_due_for_follow_ups() results_set = set(results) # we should only have ones that have not received followups self.assertIn(no_followup, results_set) self.assertNotIn(sub_w_followup, results_set)
def test_create_sub_with_existing_duplicate(self): applicant = factories.ApplicantFactory() 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_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_can_start_at_particular_id_to_create_time_interval(self): # assume we have 4 old subs, 1 new sub old_subs = sorted([ factories.FormSubmissionWithOrgsFactory.create( date_received=get_old_date(), organizations=[self.followup_org]) for i in range(4) ], key=lambda s: s.date_received) new_sub = factories.FormSubmissionWithOrgsFactory.create( date_received=get_newer_date(), organizations=[self.followup_org]) # but we only want ones after the second oldest sub second_oldest_id = old_subs[1].id # and within the old subs, we still don't want ones that already # received followups applicant = factories.ApplicantFactory() followed_up_sub = old_subs[2] followed_up_sub.applicant = applicant followed_up_sub.has_been_sent_followup = True followed_up_sub.save() # when we get submissions due for follow ups, results = list( FollowupsService.get_submissions_due_for_follow_ups( after_id=second_oldest_id)) # we should only receive two: self.assertEqual(len(results), 2) # the second oldest self.assertIn(old_subs[1], results) # and not-as-old one that did not have a follow up self.assertIn(old_subs[3], results) # we should not receive # the oldest sub self.assertNotIn(old_subs[0], results) # the one with the follow up self.assertNotIn(followed_up_sub, results) # or the new sub self.assertNotIn(new_sub, results)
def test_expected_success(self): applicant = factories.ApplicantFactory() for i in range(2): factories.FormSubmissionFactory(applicant=applicant) results = ApplicantServices.get_applicants_with_multiple_submissions() self.assertListEqual(list(results), [applicant])
def test_doesnt_fail_if_visitor_has_applicant(self): existing_applicant = factories.ApplicantFactory() mock_request = mock_utils.SimpleMock( visitor=existing_applicant.visitor, session={}) applicant = ApplicantServices.create_new_applicant(mock_request) self.assertEqual(applicant, existing_applicant)