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 create_fake_applications(context, count, org_slug=None, status=None): count = int(count) if org_slug: org = Organization.objects.get(slug=org_slug) factories.FormSubmissionWithOrgsFactory.create_batch( count, organizations=[org]) if status: for sub in FormSubmission.objects.all(): app = sub.applications.first() app.has_been_opened = True app.save() if status == "read and updated": profile = UserProfileFactory(organization=org) for sub in FormSubmission.objects.all(): factories.StatusUpdateFactory( application=sub.applications.first(), author=profile.user) else: factories.FormSubmissionWithOrgsFactory.create_batch(count)