def test_get_absolute_url(self): org = auth_models.Organization.objects.get( slug=constants.Organizations.SF_PUBDEF) sub = SubmissionsService.create_for_organizations([org], answers={}) expected_url = "/application/{}/pdf/".format(sub.id) filled = models.FilledPDF(submission=sub) self.assertEqual(filled.get_absolute_url(), expected_url)
def test_save_binary_data_to_pdf(self): org = auth_models.Organization.objects.get( slug='sf_pubdef') sub = SubmissionsService.create_for_organizations([org], answers={}) data = b'content' fob = SimpleUploadedFile( content=data, name="content.pdf", content_type="application/pdf") filled = models.FilledPDF(submission=sub, pdf=fob) filled.save() self.assertEqual(filled.pdf.read(), data) self.assertIn("content", filled.pdf.name) self.assertIn(".pdf", filled.pdf.name)
def test_authenticated_user_can_see_filled_pdf(self): self.be_sfpubdef_user() submission = self.sf_pubdef_submissions[0] filled_pdf_bytes = self.fillable.fill(submission) pdf_file = SimpleUploadedFile('filled.pdf', filled_pdf_bytes, content_type='application/pdf') filled_pdf_model = models.FilledPDF(original_pdf=self.fillable, submission=submission, pdf=pdf_file) filled_pdf_model.save() pdf = self.client.get( reverse('intake-filled_pdf', kwargs=dict(submission_id=submission.id))) self.assertTrue(len(pdf.content) > 69000) self.assertEqual(type(pdf.content), bytes)
def test_get_individual_filled_pdfs(self): sf_pubdef = auth_models.Organization.objects.get(slug='sf_pubdef') fillable = mock.fillable_pdf(organization=sf_pubdef) subs = [ SubmissionsService.create_for_organizations( [sf_pubdef], answers={}) for i in range(2)] expected_pdfs = [ models.FilledPDF(original_pdf=fillable, submission=sub) for sub in subs] for pdf in expected_pdfs: pdf.save() bundle = BundlesService.create_bundle_from_submissions( organization=sf_pubdef, submissions=subs, skip_pdf=True) query = bundle.get_individual_filled_pdfs().order_by('pk') pdfs = list(query) self.assertListEqual(pdfs, expected_pdfs)