def test_filter_date(self): [ factories.FilingsFactory(receipt_date=datetime.date(2012, 1, 1)), factories.FilingsFactory(receipt_date=datetime.date(2013, 1, 1)), factories.FilingsFactory(receipt_date=datetime.date(2014, 1, 1)), factories.FilingsFactory(receipt_date=datetime.date(2015, 1, 1)), ] min_date = datetime.date(2013, 1, 1) results = self._results( api.url_for(FilingsList, min_receipt_date=min_date)) self.assertTrue( all(each for each in results if each['receipt_date'] >= min_date.isoformat())) max_date = datetime.date(2014, 1, 1) results = self._results( api.url_for(FilingsList, max_receipt_date=max_date)) self.assertTrue( all(each for each in results if each['receipt_date'] <= max_date.isoformat())) results = self._results( api.url_for(FilingsList, min_receipt_date=min_date, max_receipt_date=max_date)) self.assertTrue( all(each for each in results if min_date.isoformat() <= each['receipt_date'] <= max_date.isoformat()))
def test_filings(self): """ Check filings returns in general endpoint""" factories.FilingsFactory(committee_id='C001') factories.FilingsFactory(committee_id='C002') results = self._results(api.url_for(FilingsList)) self.assertEqual(len(results), 2)
def test_sort(self): [ factories.FilingsFactory(beginning_image_number=2), factories.FilingsFactory(beginning_image_number=1), ] results = self._results( api.url_for(FilingsList, sort='beginning_image_number')) self.assertTrue([each['beginning_image_number'] for each in results], [1, 2])
def test_secondary_sort_descending(self): [ factories.FilingsFactory(beginning_image_number=2, coverage_end_date='2017-01-01'), factories.FilingsFactory(beginning_image_number=1, coverage_end_date='2017-01-01'), factories.FilingsFactory(beginning_image_number=0, coverage_end_date='2017-01-02'), ] results = self._results( api.url_for(FilingsList, sort=['coverage_end_date', '-beginning_image_number'])) self.assertEqual(results[0]['beginning_image_number'], '2')
def test_filings_filters(self): [ factories.FilingsFactory(committee_id='C0004'), factories.FilingsFactory(committee_id='C0005'), factories.FilingsFactory(beginning_image_number=123456789021234567), factories.FilingsFactory(form_type='3'), factories.FilingsFactory(primary_general_indicator='G'), factories.FilingsFactory(amendment_indicator='A'), factories.FilingsFactory(report_type='Post General'), factories.FilingsFactory(report_year=1999), ] filter_fields = ( ('beginning_image_number', 123456789021234567), ('form_type', '3'), ('primary_general_indicator', 'G'), ('amendment_indicator', 'A'), ('report_type', 'Post General'), ('report_year', 1999), ) # checking one example from each field orig_response = self._response(api.url_for(FilingsList)) original_count = orig_response['pagination']['count'] for field, example in filter_fields: page = api.url_for(FilingsList, **{field: example}) # returns at least one result results = self._results(page) self.assertGreater(len(results), 0) # doesn't return all results response = self._response(page) self.assertGreater(original_count, response['pagination']['count'])
def test_candidate_filings(self): candidate_id = 'P12345' factories.FilingsFactory(candidate_id=candidate_id) results = self._results( api.url_for(FilingsView, candidate_id=candidate_id)) self.assertEqual(len(results), 1) self.assertEqual(results[0]['candidate_id'], candidate_id)
def test_committee_filing(self): """ Check filing returns with a specified committee id""" committee_id = 'C8675309' filing = factories.FilingsFactory(committee_id=committee_id) results = self._results(api.url_for(FilingsView, committee_id=committee_id)) self.assertEqual(results[0]['committee_id'], committee_id)
def test_views(self, upload_s3): committee = factories.CommitteeFactory(committee_type='H') committee_id = committee.committee_id factories.CommitteeHistoryFactory(committee_id=committee_id, committee_type='H') filing = factories.FilingsFactory(committee_id=committee_id) efiling = factories.EFilingsFactory(committee_id=committee_id, receipt_date=datetime.datetime( 2012, 1, 1)) basef3pfiling = factories.BaseF3PFilingFactory( committee_id=committee_id, receipt_date=datetime.date(2012, 1, 1)) db.session.commit() for view in tasks.RESOURCE_WHITELIST: if view.endpoint in [ 'reportsview', 'efilingsummaryview', ]: url = api.url_for(view, committee_type=committee.committee_type) elif view.endpoint in [ 'filingsview', 'committeereportsview', ]: url = api.url_for(view, committee_id=committee.committee_id) else: url = api.url_for(view) tasks.export_query(url, b'')
def test_views(self, make_bundle): committee = factories.CommitteeFactory(committee_type='H') committee_id = committee.committee_id factories.CommitteeHistoryFactory(committee_id=committee_id, committee_type='H') filing = factories.FilingsFactory(committee_id=committee_id) # noqa efiling = factories.EFilingsFactory( # noqa committee_id=committee_id, receipt_date=datetime.datetime(2012, 1, 1)) basef3pfiling = factories.BaseF3PFilingFactory( # noqa committee_id=committee_id, receipt_date=datetime.date(2012, 1, 1)) db.session.commit() # these are the major downloadable resources, we may want to add more later RESOURCE_WHITELIST = { aggregates.ScheduleABySizeView, aggregates.ScheduleAByStateView, aggregates.ScheduleAByZipView, aggregates.ScheduleAByEmployerView, aggregates.ScheduleAByOccupationView, aggregates.ScheduleBByRecipientView, aggregates.ScheduleBByRecipientIDView, aggregates.ScheduleBByPurposeView, candidate_aggregates.TotalsCandidateView, candidates.CandidateList, committees.CommitteeList, costs.CommunicationCostView, costs.ElectioneeringView, filings.EFilingsView, filings.FilingsList, filings.FilingsView, reports.ReportsView, reports.CommitteeReportsView, reports.EFilingHouseSenateSummaryView, reports.EFilingPresidentialSummaryView, reports.EFilingPacPartySummaryView, sched_a.ScheduleAView, sched_a.ScheduleAEfileView, sched_b.ScheduleBView, sched_b.ScheduleBEfileView, sched_d.ScheduleDView, sched_e.ScheduleEView, sched_e.ScheduleEEfileView, sched_f.ScheduleFView, } for view in RESOURCE_WHITELIST: if view.endpoint in ['reportsview']: url = api.url_for(view, committee_type=committee.committee_type) elif view.endpoint in [ 'filingsview', 'committeereportsview', ]: url = api.url_for(view, committee_id=committee.committee_id) else: url = api.url_for(view) tasks.export_query(url, base64.b64encode(b'').decode('UTF-8'))
def test_pdf_url(self): factories.FilingsFactory( report_type_full='report {more information than we want}', beginning_image_number=123456, committee_id='C007', report_year=2004, ) results = self._results(api.url_for(FilingsView, committee_id='C007')) self.assertEqual(len(results), 1) self.assertEqual(results[0]['pdf_url'], 'http://docquery.fec.gov/pdf/456/123456/123456.pdf')
def test_regex(self): """ Getting rid of extra text that comes in the tables.""" factories.FilingsFactory( report_type_full='report {more information than we want}', committee_id='C007', report_year=2004, ) results = self._results(api.url_for(FilingsView, committee_id='C007')) self.assertEqual(results[0]['document_description'], 'report 2004')
def test_filings_filters(self): [ factories.FilingsFactory(committee_id='C0004'), factories.FilingsFactory(committee_id='C0005'), factories.FilingsFactory(candidate_id='H0001'), factories.FilingsFactory(amendment_indicator='A'), factories.FilingsFactory( beginning_image_number=123456789021234567), factories.FilingsFactory(committee_type='P'), factories.FilingsFactory(cycle=2000), factories.FilingsFactory(document_type='X'), factories.FilingsFactory(file_number=123), factories.FilingsFactory(form_category='REPORT'), factories.FilingsFactory(form_category='REPORT'), factories.FilingsFactory(form_type='3'), factories.FilingsFactory(office='H'), factories.FilingsFactory(party='DEM'), factories.FilingsFactory(primary_general_indicator='G'), factories.FilingsFactory(report_type='POST GENERAL'), factories.FilingsFactory(report_year=1999), factories.FilingsFactory(request_type='5'), factories.FilingsFactory(state='MD'), ] filter_fields = ( ('amendment_indicator', 'A'), ('beginning_image_number', 123456789021234567), ('committee_type', 'P'), ('cycle', 2000), ('document_type', 'X'), ('file_number', 123), ('form_category', 'REPORT'), ('form_type', '3'), ('office', 'H'), ('party', 'DEM'), ('primary_general_indicator', 'G'), ('report_type', 'Post General'), ('report_year', 1999), ('request_type', '5'), ('state', 'MD'), ('candidate_id', 'H0001'), ) # checking one example from each field orig_response = self._response(api.url_for(FilingsList)) original_count = orig_response['pagination']['count'] for field, example in filter_fields: page = api.url_for(FilingsList, **{field: example}) # returns at least one result results = self._results(page) self.assertGreater(len(results), 0) # doesn't return all results response = self._response(page) self.assertGreater(original_count, response['pagination']['count'])