def test_anonymous_user_can_submit_county_selection(self):
     self.be_anonymous()
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         response = self.client.fill_form(
             reverse('intake-apply'),
             counties=['contracosta'],
             headers={'HTTP_USER_AGENT': 'tester'})
     self.assertRedirects(response, reverse('intake-county_application'))
     applicant_id = self.client.session.get('applicant_id')
     self.assertTrue(applicant_id)
     applicant = models.Applicant.objects.get(id=applicant_id)
     self.assertTrue(applicant)
     self.assertTrue(applicant.visitor_id)
     visitor = models.Visitor.objects.get(id=applicant.visitor_id)
     self.assertTrue(visitor)
     self.assertEqual(len(logs.output), 4)
     assertInLogsCount(
         logs, {
             'event_name=site_entered': 1,
             'event_name=page_viewed': 1,
             'event_name=application_started': 1,
             'event_name=application_page_complete': 1,
             'call_to_mixpanel': 4,
             'distinct_id=' + visitor.get_uuid(): 4,
         })
     assertInLogs(logs, 'user_agent', 'referrer', 'source', 'counties',
                  'contracosta')
Пример #2
0
 def test_logs_to_mixpanel(self):
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.post(
             reverse('partnerships-contact'), self.valid_post_data())
     assertInLogsCount(
         logs, {'event_name=partnership_interest_submitted': 1})
Пример #3
0
 def test_logs_to_mixpanel(self):
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.post(reverse('partnerships-contact'),
                          self.valid_post_data())
     assertInLogsCount(logs,
                       {'event_name=partnership_interest_submitted': 1})
Пример #4
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})
 def test_anonymous_user_can_submit_county_selection(self):
     self.be_anonymous()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.client.fill_form(
             reverse('intake-apply'),
             counties=['contracosta'],
             confirm_county_selection='yes',
             headers={'HTTP_USER_AGENT': 'tester'})
     self.assertRedirects(response, reverse('intake-county_application'))
     applicant_id = self.client.session.get('applicant_id')
     self.assertTrue(applicant_id)
     applicant = models.Applicant.objects.get(id=applicant_id)
     self.assertTrue(applicant)
     self.assertTrue(applicant.visitor_id)
     visitor = models.Visitor.objects.get(id=applicant.visitor_id)
     self.assertTrue(visitor)
     self.assertEqual(len(logs.output), 4)
     assertInLogsCount(logs, {
         'event_name=site_entered': 1,
         'event_name=page_viewed': 1,
         'event_name=application_started': 1,
         'event_name=application_page_complete': 1,
         'call_to_mixpanel': 4,
         'distinct_id=' + visitor.get_uuid(): 4,
     })
     assertInLogs(
         logs, 'user_agent', 'referrer', 'source', 'counties', 'contracosta'
     )
Пример #6
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})
 def test_validation_warnings(self, send_confirmation):
     applicant = factories.ApplicantFactory.create()
     self.set_form_session_data(
         counties=['sanfrancisco'], applicant_id=applicant.id)
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.client.fill_form(
             reverse(self.view_name),
             **mock.fake.sf_pubdef_answers(ssn=''))
     self.assertRedirects(
         response, reverse('intake-confirm'), fetch_redirect_response=False)
     response = self.client.get(response.url)
     self.assertContains(response, escape(WARNING_FLASH_MESSAGE))
     self.assertContains(
         response,
         escape(
             fields.SocialSecurityNumberField.is_recommended_error_message))
     send_confirmation.assert_not_called()
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 0,
         })
Пример #8
0
 def test_validation_warnings(self, slack, send_confirmation):
     applicant = factories.ApplicantFactory.create()
     self.set_form_session_data(
         counties=['sanfrancisco'], applicant_id=applicant.id)
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.client.fill_form(
             reverse(self.view_name),
             **mock.fake.sf_pubdef_answers(ssn=''))
     self.assertRedirects(
         response, reverse('intake-confirm'), fetch_redirect_response=False)
     response = self.client.get(response.url)
     self.assertContains(response, escape(WARNING_FLASH_MESSAGE))
     self.assertContains(
         response,
         escape(
             fields.SocialSecurityNumberField.is_recommended_error_message))
     slack.assert_not_called()
     send_confirmation.assert_not_called()
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 0,
             })
Пример #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',
             '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})
Пример #10
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})
Пример #11
0
 def test_all_new_tags(self):
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         result = TagsService.update_tags_for_submission(
             self.cfa_user.id, self.sub.id, "new, thing")
     self.assertTagsHaveNames(result, ["existing", "new", "thing"])
     assertInLogsCount(logs, {
         'event_name=app_tag_added': 2, 'new': 1, 'thing': 1})
Пример #12
0
 def test_fires_event(self):
     profile = fake_app_reviewer()
     self.client.login(email=profile.user.email,
                       password=settings.TEST_USER_PASSWORD)
     for get_url_name, target_url_name in self.url_names_and_targets:
         with self.assertLogs('project.services.logging_service',
                              logging.INFO) as logs:
             response = self.client.get(reverse(get_url_name))
         assertInLogsCount(logs, {'event_name=user_email_link_clicked': 1})
Пример #13
0
 def test_logged_in_user_can_get_submission_display(self):
     self.be_apubdef_user()
     submission = self.a_pubdef_submissions[0]
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.get_detail(submission)
     self.assertEqual(response.context_data['form'].submission, submission)
     self.assertHasDisplayData(response, submission)
     assertInLogsCount(logs, {'event_name=app_opened': 1})
Пример #14
0
 def test_fires_expected_mixpanel_events(self):
     user = self.be_ccpubdef_user()
     submission = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[user.profile.organization])
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.get_page(submission)
     assertInLogsCount(logs, {'event_name=app_opened': 1})
     assertInLogsCount(logs, {'event_name=user_app_opened': 1})
Пример #15
0
 def test_logged_in_user_can_get_submission_display(self, slack):
     self.be_apubdef_user()
     submission = self.a_pubdef_submissions[0]
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         response = self.get_detail(submission)
     self.assertEqual(response.context_data['form'].submission, submission)
     self.assertHasDisplayData(response, submission)
     assertInLogsCount(logs, {'event_name=app_opened': 1})
Пример #16
0
 def test_fires_expected_mixpanel_events(self):
     user = self.be_ccpubdef_user()
     submission = factories.FormSubmissionWithOrgsFactory.create(
         organizations=[user.profile.organization])
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.get_page(submission)
     assertInLogsCount(logs, {'event_name=app_opened': 1})
     assertInLogsCount(logs, {'event_name=user_app_opened': 1})
 def test_fires_expected_mixpanel_events(self):
     app_ids = intake_factories.make_app_ids_for('sf_pubdef')
     profile = user_accounts_factories.app_reviewer('sf_pubdef')
     login(self.client, profile)
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.client.get(
             query_params.get_url_for_ids(self.view_name, app_ids))
     assertInLogsCount(logs, {'event_name=app_opened': len(app_ids)})
     assertInLogsCount(logs, {'event_name=user_app_opened': len(app_ids)})
 def test_fires_event(self):
     profile = fake_app_reviewer()
     self.client.login(
         email=profile.user.email,
         password=settings.TEST_USER_PASSWORD)
     for get_url_name, target_url_name in self.url_names_and_targets:
         with self.assertLogs(
                 'project.services.logging_service', logging.INFO) as logs:
             response = self.client.get(reverse(get_url_name))
         assertInLogsCount(logs, {'event_name=user_email_link_clicked': 1})
Пример #19
0
 def test_some_new_tags(self):
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         result = TagsService.update_tags_for_submission(
             self.cfa_user.id, self.sub.id, "old, new")
     self.assertTagsHaveNames(result, ["existing", "new", "old"])
     assertInLogsCount(
         logs, {
             'event_name=app_tag_added': 2,
             "'tag_name': 'new'": 1,
             "'tag_name': 'old'": 1})
 def test_logs_page_complete_and_application_started(self):
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse('intake-apply'),
                               counties=['alameda', 'contracosta'])
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 1,
         })
     assertInLogs(logs, 'alameda', 'contracosta')
Пример #21
0
 def test_fires_expected_mixpanel_events(self):
     profile = user_accounts_factories.app_reviewer('a_pubdef')
     login(self.client, profile)
     submission = intake_factories.make_apps_for(
                 'a_pubdef', count=1)[0].form_submission
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.get(
             reverse('intake-case_printout', kwargs=dict(
                     submission_id=submission.id)))
     assertInLogsCount(logs, {'event_name=app_opened': 1})
     assertInLogsCount(logs, {'event_name=user_app_opened': 1})
Пример #22
0
 def test_logs_page_complete_and_application_started(self):
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.fill_form(
             reverse('intake-apply'), counties=['alameda', 'contracosta'],
             confirm_county_selection='yes')
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 1,
             })
     assertInLogs(logs, 'alameda', 'contracosta')
Пример #23
0
 def test_fires_expected_mixpanel_events(self, slack):
     profile = user_accounts_factories.app_reviewer('a_pubdef')
     login(self.client, profile)
     submission = intake_factories.make_apps_for('a_pubdef',
                                                 count=1)[0].form_submission
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.get(
             reverse('intake-case_printout',
                     kwargs=dict(submission_id=submission.id)))
     assertInLogsCount(logs, {'event_name=app_opened': 1})
     assertInLogsCount(logs, {'event_name=user_app_opened': 1})
 def test_logs_validation_errors_event(self):
     self.set_form_session_data(counties=['sanfrancisco'])
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse(self.view_name),
                               **mock.fake.sf_pubdef_answers(first_name=''))
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 0,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 1,
         })
Пример #25
0
 def test_returns_201_for_valid_input(self):
     user = self.be_cfa_user()
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         response = self.post_new_note(user)
     self.assertEqual(response.status_code, 201)
     # here we can test the
     serialized_note = response.json()
     self.assertEqual(serialized_note['body'], "Coffee might help")
     for expected_key in ['submission', 'user', 'created', 'id']:
         self.assertIn(expected_key, serialized_note)
         self.assertTrue(serialized_note[expected_key])
     assertInLogsCount(logs, {'event_name=app_note_added': 1})
 def test_logs_page_complete_event(self):
     self.set_form_session_data(counties=['alameda'],
                                **mock.fake.a_pubdef_answers())
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse(self.view_name),
                               **mock.fake.declaration_letter_answers())
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 0,
         })
 def test_logs_validation_errors_event(self):
     self.set_form_session_data(counties=['sanfrancisco'])
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.fill_form(
             reverse(self.view_name),
             **mock.fake.sf_pubdef_answers(first_name=''))
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 0,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 1,
         })
 def test_returns_201_for_valid_input(self):
     user = self.be_cfa_user()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         response = self.post_new_note(user)
     self.assertEqual(response.status_code, 201)
     # here we can test the
     serialized_note = response.json()
     self.assertEqual(
         serialized_note['body'], "Coffee might help")
     for expected_key in ['submission', 'user', 'created', 'id']:
         self.assertIn(expected_key, serialized_note)
         self.assertTrue(serialized_note[expected_key])
     assertInLogsCount(logs, {'event_name=app_note_added': 1})
 def test_logs_validation_errors_event(self):
     self.set_form_session_data(counties=['contracosta'],
                                **mock.fake.cc_pubdef_answers())
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse(self.view_name),
                               submit_action='gobbledygook')
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 0,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 1,
         })
 def test_logs_page_complete_event(self):
     self.set_form_session_data(
         counties=['alameda'], **mock.fake.a_pubdef_answers())
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.fill_form(
             reverse(self.view_name),
             **mock.fake.declaration_letter_answers())
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 0,
             })
Пример #31
0
    def test_returns_200_on_existing_bundle_id(self):
        """`ApplicationBundleDetailView` return `OK` for existing bundle

        create an `ApplicationBundle`,
        try to access `ApplicationBundleDetailView` using `id`
        assert that 200 OK is returned
        """
        self.be_apubdef_user()
        with self.assertLogs(
                'project.services.logging_service', logging.INFO) as logs:
            result = self.client.get(reverse(
                'intake-app_bundle_detail',
                kwargs=dict(bundle_id=self.a_pubdef_bundle.id)))
        self.assertEqual(result.status_code, 200)
        assertInLogsCount(logs, {
            'app_bundle_opened': self.a_pubdef_bundle.submissions.count()})
Пример #32
0
    def test_returns_200_on_existing_bundle_id(self, slack):
        """`ApplicationBundleDetailView` return `OK` for existing bundle

        create an `ApplicationBundle`,
        try to access `ApplicationBundleDetailView` using `id`
        assert that 200 OK is returned
        """
        self.be_apubdef_user()
        with self.assertLogs(
                'project.services.logging_service', logging.INFO) as logs:
            result = self.client.get(reverse(
                'intake-app_bundle_detail',
                kwargs=dict(bundle_id=self.a_pubdef_bundle.id)))
        self.assertEqual(result.status_code, 200)
        assertInLogsCount(logs, {
            'app_bundle_opened': self.a_pubdef_bundle.submissions.count()})
 def test_logs_validation_errors_event(self):
     self.set_form_session_data(
         counties=['contracosta'],
         **mock.fake.cc_pubdef_answers())
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.fill_form(
             reverse(self.view_name),
             submit_action='gobbledygook')
     assertInLogsCount(
         logs, {
             'event_name=application_page_complete': 0,
             'event_name=application_started': 0,
             'event_name=application_submitted': 0,
             'event_name=application_errors': 1,
         })
Пример #34
0
    def test_user_can_edit_message(self, front):
        self.be_apubdef_user()
        self.create_status_update(follow=True)
        edited_message = "Hi, I've been edited"

        with self.assertLogs(
                'project.services.logging_service', logging.INFO) as logs:
            response = self.confirm_status_update(sent_message=edited_message)
        self.assertRedirects(response, reverse('intake-app_index'))
        application = self.sub.applications.filter(
            organization=self.a_pubdef).first()
        status_update = application.status_updates.latest('updated')
        customizable_sent_message_string = \
            status_update.notification.sent_message.split("\n\n")[1]
        self.assertEqual(
            customizable_sent_message_string, edited_message)
        assertInLogsCount(logs, {'event_name=app_status_updated': 1})
    def test_user_can_edit_message(self, front):
        self.be_apubdef_user()
        self.create_status_update(follow=True)
        edited_message = "Hi, I've been edited"

        with self.assertLogs(
                'project.services.logging_service', logging.INFO) as logs:
            response = self.confirm_status_update(sent_message=edited_message)
        self.assertRedirects(response, reverse('intake-app_index'))
        application = self.sub.applications.filter(
            organization=self.a_pubdef).first()
        status_update = application.status_updates.latest('updated')
        customizable_sent_message_string = \
            status_update.notification.sent_message.split("\n\n")[1]
        self.assertEqual(
            customizable_sent_message_string, edited_message)
        assertInLogsCount(logs, {'event_name=app_status_updated': 1})
 def test_finalize_application_actions(self, create_sub, fill_pdfs,
                                       flash_success):
     self.set_form_session_data(counties=['contracosta'])
     answers = fake.contra_costa_county_form_answers()
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse('intake-county_application'),
                               **answers)
     self.assertEqual(create_sub.call_count, 1)
     self.assertEqual(fill_pdfs.call_count, 1)
     self.assertEqual(self.slack_new_submission.call_count, 1)
     self.assertEqual(self.send_confirmations.call_count, 1)
     self.assertEqual(flash_success.call_count, 1)
     assertInLogsCount(
         logs, {
             'event_name=application_submitted': 1,
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_errors': 0,
         })
 def test_finalize_application_actions(
         self, create_sub, fill_pdfs, flash_success):
     self.set_form_session_data(counties=['contracosta'])
     answers = fake.contra_costa_county_form_answers()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         self.client.fill_form(
             reverse('intake-county_application'), **answers)
     self.assertEqual(create_sub.call_count, 1)
     self.assertEqual(fill_pdfs.call_count, 1)
     self.assertEqual(self.slack_new_submission.call_count, 1)
     self.assertEqual(self.send_confirmations.call_count, 1)
     self.assertEqual(flash_success.call_count, 1)
     assertInLogsCount(
         logs, {
             'event_name=application_submitted': 1,
             'event_name=application_page_complete': 1,
             'event_name=application_started': 0,
             'event_name=application_errors': 0,
         })
Пример #38
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)
Пример #39
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)
Пример #40
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)
 def test_finalize_application_actions(self, create_sub, send_to_newapps,
                                       flash_success, mock_form_submitted):
     self.set_form_session_data(counties=['solano'])
     answers = fake.solano_county_form_answers()
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         self.client.fill_form(reverse('intake-county_application'),
                               **answers)
         self.client.fill_form(reverse('intake-review'),
                               submit_action='approve_application')
     self.assertEqual(create_sub.call_count, 1)
     self.assertEqual(send_to_newapps.call_count, 1)
     self.assertEqual(self.send_confirmations.call_count, 1)
     self.assertEqual(flash_success.call_count, 1)
     self.assertEqual(mock_form_submitted.call_count, 1)
     assertInLogsCount(
         logs, {
             'event_name=application_submitted': 0,
             'event_name=application_page_complete': 2,
             'event_name=application_started': 0,
             'event_name=application_errors': 0,
         })
Пример #42
0
 def test_creates_expected_objects(self):
     user = User.objects.filter(
         profile__organization__slug='a_pubdef').first()
     to_org = Organization.objects.get(slug='ebclc')
     application = models.Application.objects.filter(
         organization__slug='a_pubdef').first()
     with self.assertLogs('project.services.logging_service',
                          logging.INFO) as logs:
         TransferService.transfer_application(
             user, application, to_org, 'because of subspace interference')
     new_application = models.Application.objects.filter(
         incoming_transfers__status_update__author=user).first()
     self.assertTrue(new_application.pk)
     self.assertEqual(new_application.incoming_transfers.count(), 1)
     transfer = new_application.incoming_transfers.first()
     self.assertEqual(transfer.status_update.status_type.slug,
                      'transferred')
     self.assertEqual(
         transfer.status_update.application.organization.county.slug,
         'alameda')
     self.assertEqual(transfer.reason, 'because of subspace interference')
     self.assertTrue(application.was_transferred_out)
     assertInLogsCount(logs, {'event_name=app_transferred': 1})
 def test_creates_expected_objects(self):
     user = User.objects.filter(
         profile__organization__slug='a_pubdef').first()
     to_org = Organization.objects.get(slug='ebclc')
     application = models.Application.objects.filter(
         organization__slug='a_pubdef').first()
     with self.assertLogs(
             'project.services.logging_service', logging.INFO) as logs:
         TransferService.transfer_application(
             user, application, to_org, 'because of subspace interference')
     new_application = models.Application.objects.filter(
         incoming_transfers__status_update__author=user).first()
     self.assertTrue(new_application.pk)
     self.assertEqual(new_application.incoming_transfers.count(), 1)
     transfer = new_application.incoming_transfers.first()
     self.assertEqual(
         transfer.status_update.status_type.slug, 'transferred')
     self.assertEqual(
         transfer.status_update.application.organization.county.slug,
         'alameda')
     self.assertEqual(transfer.reason, 'because of subspace interference')
     self.assertTrue(application.was_transferred_out)
     assertInLogsCount(logs, {'event_name=app_transferred': 1})
Пример #44
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)