def handle(self, *args, **options): call_command('flush', interactive=False) self.stdout.write( self.style.SUCCESS("Destroyed all existing data")) call_command('load_essential_data') self.stdout.write( self.style.SUCCESS( "Loaded organizations, counties, groups, & permissions " "from fixtures")) create_seed_users() self.stdout.write( self.style.SUCCESS("Created fake user profiles")) serialize_seed_users() self.stdout.write( self.style.SUCCESS( "Saved to mock_profiles fixture")) fillable_pdf() self.stdout.write( self.style.SUCCESS( "Load fake fillable pdf")) build_seed_submissions() self.stdout.write( self.style.SUCCESS( "Created fake submissions, bundles, and transfers " "and saved them to fixture files")) for app_id in Application.objects.filter( organization__slug='sf_pubdef' ).values_list('id', flat=True): fill_pdf_for_application(app_id) update_pdf_bundle_for_san_francisco() self.stdout.write( self.style.SUCCESS( "Pre-filled PDFs for San Francisco, including pdf bundle of " "unread apps"))
def handle(self, *args, **options): call_command('flush', interactive=False) self.stdout.write( self.style.SUCCESS("Destroyed all existing data")) call_command('load_essential_data') self.stdout.write( self.style.SUCCESS( "Loaded organizations, counties, groups, & permissions " "from fixtures")) create_seed_users() self.stdout.write( self.style.SUCCESS("Created fake user profiles")) serialize_seed_users() self.stdout.write( self.style.SUCCESS( "Saved to mock_profiles fixture")) fillable_pdf() self.stdout.write( self.style.SUCCESS( "Load fake fillable pdf")) build_seed_submissions() self.stdout.write( self.style.SUCCESS( "Created fake submissions, bundles, and transfers " "and saved them to fixture files"))
def handle(self, *args, **options): call_command('flush', interactive=False) self.stdout.write(self.style.SUCCESS("Destroyed all existing data")) call_command('load_essential_data') self.stdout.write( self.style.SUCCESS( "Loaded organizations, counties, groups, & permissions " "from fixtures")) create_seed_users() self.stdout.write(self.style.SUCCESS("Created fake user profiles")) serialize_seed_users() self.stdout.write(self.style.SUCCESS("Saved to mock_profiles fixture")) fillable_pdf() self.stdout.write(self.style.SUCCESS("Load fake fillable pdf")) build_seed_submissions() self.stdout.write( self.style.SUCCESS( "Created fake submissions, bundles, and transfers " "and saved them to fixture files")) for app_id in Application.objects.filter( organization__slug='sf_pubdef').values_list('id', flat=True): fill_pdf_for_application(app_id) update_pdf_bundle_for_san_francisco() self.stdout.write( self.style.SUCCESS( "Pre-filled PDFs for San Francisco, including pdf bundle of " "unread apps"))
def test_should_have_a_pdf_positive(self): sf_pubdef = auth_models.Organization.objects.get(slug='sf_pubdef') mock.fillable_pdf(organization=sf_pubdef) sub = SubmissionsService.create_for_organizations( [sf_pubdef], answers={}) bundle = BundlesService.create_bundle_from_submissions( organization=sf_pubdef, submissions=[sub], skip_pdf=True) self.assertTrue(bundle.should_have_a_pdf())
def test_build_bundled_pdf_with_one_pdf(self, logger, get_parser, slack): # set up associated data sf_pubdef = auth_models.Organization.objects.get( slug=constants.Organizations.SF_PUBDEF) sub = SubmissionsService.create_for_organizations([sf_pubdef], answers={}) fillable = mock.fillable_pdf(organization=sf_pubdef) data = b'content' filled = models.FilledPDF.create_with_pdf_bytes(pdf_bytes=data, submission=sub, original_pdf=fillable) bundle = BundlesService.create_bundle_from_submissions( organization=sf_pubdef, submissions=[sub], skip_pdf=True) # set up mocks should_have_a_pdf = Mock(return_value=True) get_individual_filled_pdfs = Mock(return_value=[filled]) bundle.should_have_a_pdf = should_have_a_pdf bundle.get_individual_filled_pdfs = get_individual_filled_pdfs # run method BundlesService.build_bundled_pdf_if_necessary(bundle) # check results get_parser.assert_not_called() logger.assert_not_called() slack.assert_not_called() get_individual_filled_pdfs.assert_called_once_with() self.assertEqual(bundle.bundled_pdf.read(), data)
def test_build_bundled_pdf_with_one_pdf(self, logger, get_parser, slack): # set up associated data sf_pubdef = auth_models.Organization.objects.get( slug=constants.Organizations.SF_PUBDEF) sub = SubmissionsService.create_for_organizations( [sf_pubdef], answers={}) fillable = mock.fillable_pdf(organization=sf_pubdef) data = b'content' filled = models.FilledPDF.create_with_pdf_bytes( pdf_bytes=data, submission=sub, original_pdf=fillable) bundle = BundlesService.create_bundle_from_submissions( organization=sf_pubdef, submissions=[sub], skip_pdf=True) # set up mocks should_have_a_pdf = Mock(return_value=True) get_individual_filled_pdfs = Mock( return_value=[filled]) bundle.should_have_a_pdf = should_have_a_pdf bundle.get_individual_filled_pdfs = get_individual_filled_pdfs # run method BundlesService.build_bundled_pdf_if_necessary(bundle) # check results get_parser.assert_not_called() logger.assert_not_called() slack.assert_not_called() get_individual_filled_pdfs.assert_called_once_with() self.assertEqual(bundle.bundled_pdf.read(), data)
def handle(self, *args, **options): call_command('flush', interactive=False) self.stdout.write(self.style.SUCCESS("Destroyed all existing data")) call_command('load_essential_data') self.stdout.write( self.style.SUCCESS( "Loaded organizations, counties, groups, & permissions " "from fixtures")) create_seed_users() self.stdout.write(self.style.SUCCESS("Created fake user profiles")) serialize_seed_users() self.stdout.write(self.style.SUCCESS("Saved to mock_profiles fixture")) fillable_pdf() self.stdout.write(self.style.SUCCESS("Load fake fillable pdf")) build_seed_submissions() self.stdout.write( self.style.SUCCESS( "Created fake submissions, bundles, and transfers " "and saved them to fixture files"))
def test_calls_pdfparser_correctly(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=mock.fake.cleaned_sf_county_form_answers()) for i in range(2)] pdfs = [fillable.fill_for_submission(sub) for sub in subs] parser = models.get_parser() result = parser.join_pdfs(filled.pdf for filled in pdfs) self.assertTrue(len(result) > 30000)
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)
def have_a_fillable_pdf(cls): cls.fillable = mock.fillable_pdf(organization=cls.sfpubdef)
def handle(self, *args, **kwargs): management.call_command( 'loaddata', *ALL_MOCK_DATA_FIXTURES) if pdfs.FillablePDF.objects.count() == 0: mock.fillable_pdf()
def have_a_fillable_pdf(cls): cls.fillable = mock.fillable_pdf(organization=cls.sf_pubdef)
def handle(self, *args, **kwargs): management.call_command('loaddata', *ALL_MOCK_DATA_FIXTURES) if pdfs.FillablePDF.objects.count() == 0: mock.fillable_pdf()
def have_a_fillable_pdf(cls): cls.fillable = mock.fillable_pdf()
def before_scenario(context, scenario): call_command('load_essential_data') mock.fillable_pdf()