def test_gets_all_cnl_submissions(self):
     cfa = Organization.objects.get(slug='cfa')
     sf_pubdef = Organization.objects.get(slug='sf_pubdef')
     cnl_sub1 = factories.FormSubmissionWithOrgsFactory(organizations=[cfa])
     cnl_sub2 = factories.FormSubmissionWithOrgsFactory(organizations=[cfa])
     other_sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[sf_pubdef])
     cnl_subs = SubmissionsService.get_all_cnl_submissions(0)
     self.assertEqual(len(cnl_subs.object_list), 2)
 def test_calls_task_if_sf_in_sub(self, add_application_pdfs):
     sf_pubdef = Organization.objects.get(slug='sf_pubdef')
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[sf_pubdef])
     SubmissionsService.send_to_newapps_bundle_if_needed(sub, [sf_pubdef])
     add_application_pdfs.delay.assert_called_with(
         sub.applications.first().id)
Beispiel #3
0
 def test_when_opened_app_is_for_not_sf(self, update_pdf):
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[Organization.objects.get(slug='a_pubdef')])
     app = sub.applications.first()
     factories.FillablePDFFactory()
     PDFService.rebuild_pdf_bundle_for_removed_application(app.id)
     update_pdf.assert_not_called()
 def test_calls_remove_pdf_task_when_opened(self, remove_application_pdfs):
     profile = UserProfileFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[profile.organization], answers={})
     AppsService.handle_apps_opened(Mock(**{'request.user': profile.user}),
                                    sub.applications.all())
     remove_application_pdfs.assert_called_with(sub.applications.first().id)
Beispiel #5
0
 def test_does_not_call_task_if_not_sf(self, add_application_pdfs):
     a_pubdef = Organization.objects.get(
         slug='a_pubdef')
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[a_pubdef])
     SubmissionsService.send_to_newapps_bundle_if_needed(sub, [a_pubdef])
     add_application_pdfs.delay.assert_not_called()
Beispiel #6
0
def create_searchable_applicant_with_bad_data(context, org_slug=None):
    global SEARCHABLE_APPLICANT_ID
    if org_slug:
        org = Organization.objects.get(slug=org_slug)
    answers = mock.fake.contra_costa_county_form_answers(**{
        'first_name': 'Waldo',
        'last_name': 'Waldini',
        'phone_number': '5555555555',
        'alternate_phone_number': '5555555555',
        'email': 'waldo@odlaw',
        'contact_preferences': ['prefers_email', 'prefers_sms'],
        'email': 'waldo@odlaw',
        'dob.day': '28',
        'dob.month': 'February',
        'dob.year': '1972',
    })
    kwargs = dict(
        answers=answers,
        date_received=PACIFIC_TIME.localize(
            mock.fake.date_time_between('-4w', '-2w'))
        )
    if org_slug:
        kwargs.update(organizations=[org])
    sub = factories.FormSubmissionWithOrgsFactory(**kwargs)
    SEARCHABLE_APPLICANT_ID = sub.id
Beispiel #7
0
 def test_if_one_app(self, set_bytes, fill_pdfs):
     new_sf_sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[Organization.objects.get(slug='sf_pubdef')])
     factories.FilledPDFFactory(submission=new_sf_sub)
     new_sf_app = new_sf_sub.applications.first()
     result = PDFService.create_new_pdf_bundle_for_apps(
         self.sf, [new_sf_app])
     self.assertEqual([new_sf_app], list(result.applications.all()))
     fill_pdfs.assert_called_once_with([new_sf_app.id])
     self.assertEqual(set_bytes.call_count, 1)
Beispiel #8
0
 def test_if_all_apps_have_pdfs(self, fill_pdf):
     app_ids = []
     subs = []
     for i in range(3):
         sub = factories.FormSubmissionWithOrgsFactory(
             organizations=[Organization.objects.get(slug='sf_pubdef')])
         factories.FilledPDFFactory(submission=sub)
         subs.append(sub)
         app_ids.append(sub.applications.first().id)
     fill_pdf.assert_not_called()
 def test_user_sees_correct_columns_and_data_in_csv(self):
     user = accounts_factories.app_reviewer('ebclc').user
     ebclc = Organization.objects.get(slug='ebclc')
     sub = intake_factories.FormSubmissionWithOrgsFactory(
         organizations=[ebclc], answers=ebclc_answers)
     app = sub.applications.first()
     update_1 = intake_factories.StatusUpdateFactory(
         application=app,
         status_type=StatusType.objects.get(slug='eligible'),
         author=user
     )
     update_1.created = PACIFIC_TIME.localize(datetime(2017, 1, 1))
     update_1.save()
     update_2 = intake_factories.StatusUpdateFactory(
         application=app,
         status_type=StatusType.objects.get(slug='granted'),
         author=user
     )
     update_2.created = PACIFIC_TIME.localize(datetime(2017, 1, 2))
     update_2.save()
     self.client.login(
         username=user.username, password=settings.TEST_USER_PASSWORD)
     response = self.client.get(reverse(self.view_name))
     self.assertEqual(200, response.status_code)
     result = response.content.decode('utf-8')
     expected_result_line_1 = str(
         'id,Link,Application Date,Applied on,Wants help with record in,'
         'Preferred contact methods,First name,Middle name,'
         'Last name,Preferred pronouns,Phone number,Alternate phone number,'
         'Email,Address,Date of birth,Citizenship status,'
         'Is currently being charged,Is serving a sentence,'
         'Is on probation or parole,Finished half probation,'
         'Reduced probation,RAP in other counties,Where/when,'
         'Has suspended license,Owes court fines/fees,'
         'Has been denied housing or employment,'
         'Denied housing/employment by,Seeking job that requires LiveScan,'
         'Registered under PC 290,'
         'Monthly income,On public benefits,Owns home,Household size,'
         'Reasons for applying,How they found out about this,'
         'Additional information,'
         'Understands might not qualify and could take a few months,'
         '"Consents to record access, filing, and court representation",'
         'Was transferred out,Has been opened,Latest status,'
         'Latest status date,Latest status author,Status history link')
     expected_result_line_2 = str(
         'Alameda,Text Message,Gabriel,Tiffany,Jenkins,She/Her/Hers,'
         '(415) 212-4848,(415) 212-4848,[email protected],'
         '"6230 Shawn View\nNorth John, VA\n80973",4/19/1983,'
         'Other/I don\'t know,No,No,Yes,Not on probation,Not on probation,'
         'No,,No,No,,,,,"$3,001.00",No,Yes,3,,from work,I want help,'
         '"Yes, I understand","Yes, I give them permission to do that",'
         'False,False,Granted,01/02/2017,[email protected],')
     self.assertIn(expected_result_line_1, result)
     self.assertTrue(result.startswith(expected_result_line_1))
     self.assertIn(expected_result_line_2, result)
 def test_mark_only_users_app_opened(self):
     fake_org_1 = FakeOrganizationFactory()
     fake_org_2 = FakeOrganizationFactory()
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[fake_org_1, fake_org_2], answers={})
     org_1_user = UserProfileFactory(organization=fake_org_1).user
     AppsService.handle_apps_opened(Mock(**{'request.user': org_1_user}),
                                    sub.applications.all())
     org_1_apps = sub.applications.filter(organization=fake_org_1)
     org_2_apps = sub.applications.filter(organization=fake_org_2)
     self.assertTrue(all([app.has_been_opened for app in org_1_apps]))
     self.assertFalse(any([app.has_been_opened for app in org_2_apps]))
Beispiel #11
0
 def test_if_some_apps_have_pdfs(self, fill_pdf):
     app_ids = []
     subs = []
     for i in range(3):
         sub = factories.FormSubmissionWithOrgsFactory(
             organizations=[Organization.objects.get(slug='sf_pubdef')])
         subs.append(sub)
         if i < 2:
             factories.FilledPDFFactory(submission=sub)
         app_ids.append(sub.applications.first().id)
     with self.settings(DEFAULT_HOST='www.crazymanes.horse'):
         PDFService.fill_any_unfilled_pdfs_for_app_ids(app_ids)
     fill_pdf.assert_called_once_with(app_ids[2])
Beispiel #12
0
 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)
Beispiel #13
0
 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)
Beispiel #14
0
    def test_agency_user_can_only_see_latest_status_for_their_org(self):
        user = self.be_apubdef_user()
        other_org = Organization.objects.get(slug='cc_pubdef')
        submission = factories.FormSubmissionWithOrgsFactory(
            organizations=[user.profile.organization, other_org])

        # make a status notification for the other org
        other_app = models.Application.objects.filter(
            organization=other_org, form_submission=submission).first()
        other_status_type = models.StatusType.objects.get(slug='court-date')
        factories.StatusUpdateWithNotificationFactory.create(
            status_type=other_status_type,
            application=other_app,
            author=other_org.profiles.first().user)
        other_app.has_been_opened = True
        other_app.save()

        # make a status notification for tis org
        this_status_type = models.StatusType.objects.get(slug='eligible')
        this_app = models.Application.objects.filter(
            organization__profiles__user=user,
            form_submission=submission).first()
        factories.StatusUpdateWithNotificationFactory.create(
            status_type=this_status_type, application=this_app, author=user)
        this_app.has_been_opened = True
        this_app.save()

        # set the other status notification date to be later than this one
        statuses = models.StatusUpdate.objects.filter(
            application__form_submission=submission)
        this_status = statuses.filter(
            application__organization=user.profile.organization, ).latest(
                'updated')
        this_status_date = statuses.latest('updated').updated
        even_later = this_status_date + timedelta(days=3)
        other_status = statuses.exclude(
            application__organization=user.profile.organization, ).first()
        other_status.updated = even_later
        other_status.save()

        response = self.get_page(submission)
        other_logged_by = 'logged by ' + other_status.author.profile.name
        other_status_name = other_status.status_type.display_name
        this_status_logged_by = \
            'logged by ' + this_status.author.profile.name
        this_status_name = this_status.status_type.display_name
        self.assertContains(response, escape(this_status_name))
        self.assertContains(response, escape(this_status_logged_by))
        self.assertNotContains(response, escape(other_logged_by))
        self.assertNotContains(response, escape(other_status_name))
Beispiel #15
0
 def test_if_multiple_apps(self, set_bytes, fill_pdfs):
     new_sf_subs = [
         factories.FormSubmissionWithOrgsFactory(
             organizations=[Organization.objects.get(slug='sf_pubdef')])
         for i in range(3)
     ]
     for sub in new_sf_subs:
         factories.FilledPDFFactory(submission=sub)
     new_sf_apps = [sub.applications.first() for sub in new_sf_subs]
     new_app_ids = [app.id for app in new_sf_apps]
     result = PDFService.create_new_pdf_bundle_for_apps(
         self.sf, new_sf_apps)
     self.assertEqual(set(new_sf_apps), set(result.applications.all()))
     fill_pdfs.assert_called_once_with(new_app_ids)
     self.assertEqual(set_bytes.call_count, 1)
Beispiel #16
0
 def test_if_some_apps_have_pdfs(self, admin_alert, fill_pdf):
     app_ids = []
     subs = []
     for i in range(3):
         sub = factories.FormSubmissionWithOrgsFactory(
             organizations=[Organization.objects.get(slug='sf_pubdef')])
         subs.append(sub)
         if i < 2:
             factories.FilledPDFFactory(submission=sub)
         app_ids.append(sub.applications.first().id)
     PDFService.fill_any_unfilled_pdfs_for_app_ids(app_ids)
     fill_pdf.assert_called_once_with(app_ids[2])
     printed_app = str(subs[2].applications.first())
     admin_alert.assert_called_once_with(
         subject='No FilledPDFs for Applications',
         message='1 apps did not have PDFs:\n{}'.format(printed_app))
def create_searchable_applicant(context, org_slug=None):
    global SEARCHABLE_APPLICANT_ID
    if org_slug:
        org = Organization.objects.get(slug=org_slug)
    answers = mock.fake.contra_costa_county_form_answers(
        first_name='Waldo',
        last_name='Waldini',
        phone_number='5555555555',
        email='*****@*****.**')
    kwargs = dict(answers=answers,
                  date_received=PACIFIC_TIME.localize(
                      mock.fake.date_time_between('-4w', '-2w')))
    if org_slug:
        kwargs.update(organizations=[org])
    sub = factories.FormSubmissionWithOrgsFactory(**kwargs)
    SEARCHABLE_APPLICANT_ID = sub.id
Beispiel #18
0
 def test_agency_user_can_only_see_latest_status_for_their_org(self, slack):
     user = self.be_apubdef_user()
     orgs = [
         Organization.objects.get(slug='a_pubdef'),
         Organization.objects.get(slug='cc_pubdef')
         ]
     submission = factories.FormSubmissionWithOrgsFactory(
         organizations=orgs)
     for org in orgs:
         updated_application = models.Application.objects.filter(
             organization=org, form_submission=submission).first()
         factories.StatusUpdateWithNotificationFactory.create(
             application=updated_application,
             author=org.profiles.first().user)
         updated_application.has_been_opened = True
         updated_application.save()
     statuses = models.StatusUpdate.objects.filter(
         application__form_submission=submission)
     latest_status = statuses.filter(
         application__organization=user.profile.organization,
     ).latest('updated')
     latest_status_date = statuses.latest('updated').updated
     even_later = latest_status_date + timedelta(days=3)
     other_status = statuses.exclude(
         application__organization=user.profile.organization,
     ).first()
     other_status.updated = even_later
     other_status.save()
     response = self.get_page(submission)
     other_logged_by = 'logged by ' + other_status.author.profile.name
     other_status_name = other_status.status_type.display_name
     this_status_logged_by = \
         'logged by ' + latest_status.author.profile.name
     this_status_name = latest_status.status_type.display_name
     self.assertContains(response, escape(this_status_name))
     self.assertContains(response, escape(this_status_logged_by))
     self.assertNotContains(response, escape(other_logged_by))
     if other_status_name not in this_status_name:
         self.assertNotContains(response, escape(other_status_name))
Beispiel #19
0
 def setUpClass(cls, *args, **kwargs):
     super().setUpClass(*args, **kwargs)
     sub = factories.FormSubmissionWithOrgsFactory(
         organizations=[Organization.objects.get(slug='sf_pubdef')])
     cls.app = sub.applications.first()