def test_authenticated_user_can_see_pdf_bundle(self, slack): self.be_sfpubdef_user() ids = models.FormSubmission.objects.filter( organizations=self.sf_pubdef).values_list('pk', flat=True) url = url_with_ids('intake-pdf_bundle', ids) bundle = self.client.get(url, follow=True) self.assertEqual(bundle.status_code, 200)
def render(self, **context_args): if 'submissions' in context_args and 'bundle_url' not in context_args: bundle_url = getattr(settings, 'DEFAULT_HOST', '') + url_with_ids( 'intake-app_bundle', [s.id for s in context_args['submissions']]) context_args.update(bundle_url=bundle_url) return super().render(**context_args)
def test_authenticated_user_can_see_app_bundle(self, slack): self.be_cfa_user() submissions = self.submissions ids = [s.id for s in submissions] url = url_with_ids('intake-app_bundle', ids) bundle = self.client.get(url) self.assertEqual(bundle.status_code, 200)
def build_redirect_url(self, request): key_set = request.GET.get('keys') uuids = [key for key in key_set.split('|')] submissions = models.FormSubmission.objects.filter( old_uuid__in=uuids) return url_with_ids( self.redirect_view_name, [s.id for s in submissions])
def test_authenticated_user_can_see_app_bundle(self, slack): self.be_regular_user() ids = [s.id for s in self.submissions] url = url_with_ids('intake-app_bundle', ids) bundle = self.client.get(url) self.assertEqual(bundle.status_code, 200) self.assert_called_once_with_types( slack, submissions='list', user='******')
def test_authenticated_user_can_see_app_bundle(self, slack): self.be_cfa_user() # we need a pdf for this users organization ids = [s.id for s in self.submissions] url = url_with_ids('intake-app_bundle', ids) bundle = self.client.get(url) self.assertEqual(bundle.status_code, 200) self.assert_called_once_with_types(slack, submissions='list', user='******')
def test_look_at_app_bundle_of_another_org(self): user = self.ccpubdef_users[0] submissions = self.sf_submissions self.run_sequence("Look at bundle of another org", [ S.get( 'tried to go to app bundle', url_with_ids('intake-app_bundle', [s.id for s in submissions])), S.fill_form( 'entered login info', login=user.email, password=fake_password) ], base.SMALL_DESKTOP)
def test_staff_user_can_see_pdf_bundle(self, slack): self.be_cfa_user() submissions = self.sf_pubdef_submissions bundle = BundlesService.create_bundle_from_submissions( submissions=submissions, organization=self.sf_pubdef) ids = [s.id for s in submissions] url = url_with_ids('intake-pdf_bundle', ids) response = self.client.get(url) self.assertRedirects(response, bundle.get_pdf_bundle_url()) pdf_response = self.client.get(response.url) self.assertEqual(pdf_response.status_code, 200)
def test_old_urls_return_permanent_redirect(self): # redirecting the auth views does not seem necessary redirects = { '/sanfrancisco/': reverse('intake-apply'), '/sanfrancisco/applications/': reverse('intake-app_index'), } # redirecting the action views (add) does not seem necessary id_redirects = {'/sanfrancisco/{}/': 'intake-filled_pdf'} multi_id_redirects = { '/sanfrancisco/bundle/{}': 'intake-app_bundle', '/sanfrancisco/pdfs/{}': 'intake-pdf_bundle' } # make some old apps with ids old_uuids = [ '0efd75e8721c4308a8f3247a8c63305d', 'b873c4ceb1cd4939b1d4c890997ef29c', '6cb3887be35543c4b13f27bf83219f4f' ] key_params = '?keys=' + '|'.join(old_uuids) ported_models = [] for uuid in old_uuids: instance = factories.FormSubmissionFactory.create(old_uuid=uuid) ported_models.append(instance) ported_models_query = models.FormSubmission.objects.filter( old_uuid__in=old_uuids) for old, new in redirects.items(): response = self.client.get(old) self.assertRedirects(response, new, status_code=301, fetch_redirect_response=False) for old_template, new_view in id_redirects.items(): old = old_template.format(old_uuids[2]) response = self.client.get(old) new = reverse(new_view, kwargs=dict(submission_id=ported_models[2].id)) self.assertRedirects(response, new, status_code=301, fetch_redirect_response=False) for old_template, new_view in multi_id_redirects.items(): old = old_template.format(key_params) response = self.client.get(old) new = url_with_ids(new_view, [s.id for s in ported_models_query]) self.assertRedirects(response, new, status_code=301, fetch_redirect_response=False)
def test_look_at_app_bundle(self): user = self.users[0] submissions = random.sample( self.submissions, 3) self.run_sequence( "Look at app bundle", [ S.get('tried to go to app bundle', url_with_ids('intake-app_bundle', [s.id for s in submissions])), S.fill_form('entered login info', login=user.email, password=fake_password), S.wait('wait for pdf to load', 4) ], base.SMALL_DESKTOP)
def test_look_at_app_bundle_with_pdf(self): user = self.sfpubdef_users[0] submissions = self.sf_submissions self.run_sequence("Look at app pdf bundle", [ S.get( 'tried to go to app bundle', url_with_ids('intake-app_bundle', [s.id for s in submissions])), S.fill_form('entered login info', login=user.email, password=fake_password), S.wait('wait for pdf to load', 2) ], base.SMALL_DESKTOP)
def test_agency_user_can_mark_apps_as_processed(self, slack): self.be_sfpubdef_user() submissions = self.submissions[:2] ids = [s.id for s in submissions] mark_link = url_with_ids('intake-mark_processed', ids) marked = self.client.get(mark_link) self.assert_called_once_with_types(slack, submissions='list', user='******') self.assertRedirects(marked, reverse('intake-app_index')) args, kwargs = slack.call_args for sub in kwargs['submissions']: self.assertTrue(sub.last_processed_by_agency()) self.assertIn(sub.id, ids)
def test_old_urls_return_permanent_redirect(self): # redirecting the auth views does not seem necessary redirects = { '/sanfrancisco/': reverse('intake-apply'), '/sanfrancisco/applications/': reverse('intake-app_index'), } # redirecting the action views (add) does not seem necessary id_redirects = {'/sanfrancisco/{}/': 'intake-filled_pdf'} multi_id_redirects = { '/sanfrancisco/bundle/{}': 'intake-app_bundle', '/sanfrancisco/pdfs/{}': 'intake-pdf_bundle'} # make some old apps with ids old_uuids = [ '0efd75e8721c4308a8f3247a8c63305d', 'b873c4ceb1cd4939b1d4c890997ef29c', '6cb3887be35543c4b13f27bf83219f4f'] key_params = '?keys=' + '|'.join(old_uuids) ported_models = [] for uuid in old_uuids: instance = factories.FormSubmissionFactory.create( old_uuid=uuid) ported_models.append(instance) ported_models_query = models.FormSubmission.objects.filter( old_uuid__in=old_uuids) for old, new in redirects.items(): response = self.client.get(old) self.assertRedirects( response, new, status_code=301, fetch_redirect_response=False) for old_template, new_view in id_redirects.items(): old = old_template.format(old_uuids[2]) response = self.client.get(old) new = reverse( new_view, kwargs=dict( submission_id=ported_models[2].id)) self.assertRedirects( response, new, status_code=301, fetch_redirect_response=False) for old_template, new_view in multi_id_redirects.items(): old = old_template.format(key_params) response = self.client.get(old) new = url_with_ids(new_view, [s.id for s in ported_models_query]) self.assertRedirects( response, new, status_code=301, fetch_redirect_response=False)
def test_authenticated_user_can_mark_apps_as_processed(self, slack): self.be_regular_user() submissions = self.submissions[:2] ids = [s.id for s in submissions] mark_link = url_with_ids('intake-mark_processed', ids) marked = self.client.get(mark_link) self.assert_called_once_with_types( slack, submissions='list', user='******') self.assertRedirects(marked, reverse('intake-app_index')) args, kwargs = slack.call_args for sub in kwargs['submissions']: self.assertTrue(sub.processed_by_agency) self.assertIn(sub.id, ids)
def get_submissions(self, group): ids = [s.id for s in group] url = url_with_ids('intake-app_bundle', ids) return self.client.get(url)
def test_authenticated_user_can_see_pdf_bundle(self): self.be_regular_user() ids = [s.id for s in self.submissions] url = url_with_ids('intake-pdf_bundle', ids) bundle = self.client.get(url) self.assertEqual(bundle.status_code, 200)
def test_authenticated_user_can_see_pdf_bundle(self): self.be_sfpubdef_user() ids = [s.id for s in self.submissions] url = url_with_ids('intake-pdf_bundle', ids) bundle = self.client.get(url) self.assertEqual(bundle.status_code, 200)