Esempio n. 1
0
    def test_schedule_a_filter_line_number(self):
        [
            factories.ScheduleAFactory(line_number='16', filing_form='F3X'),
            factories.ScheduleAFactory(line_number='17', filing_form='F3X')
        ]
        results = self._results(
            api.url_for(ScheduleAView, line_number='f3X-16', **self.kwargs))
        self.assertEqual(len(results), 1)

        [
            factories.ScheduleBFactory(line_number='21', filing_form='F3X'),
            factories.ScheduleBFactory(line_number='22', filing_form='F3X')
        ]

        results = self._results(
            api.url_for(ScheduleBView, line_number='f3X-21', **self.kwargs))
        self.assertEqual(len(results), 1)

        # invalid line_number testing for sched_b
        response = self.app.get(
            api.url_for(ScheduleBView, line_number='f3x21', **self.kwargs))
        self.assertEqual(response.status_code, 400)
        self.assertIn(b'Invalid line_number', response.data)

        # invalid line_number testing for sched_a
        response = self.app.get(
            api.url_for(ScheduleAView, line_number='f3x16', **self.kwargs))
        self.assertEqual(response.status_code, 400)
        self.assertIn(b'Invalid line_number', response.data)
Esempio n. 2
0
 def test_sched_b_spender_committee_type_filter(self):
     [
         factories.ScheduleBFactory(spender_committee_type='S'),
         factories.ScheduleBFactory(spender_committee_type='S'),
         factories.ScheduleBFactory(spender_committee_type='P'),
     ]
     results = self._results(api.url_for(ScheduleBView, spender_committee_type='S', **self.kwargs))
     self.assertEqual(len(results), 2)
Esempio n. 3
0
 def test_sort_sched_b_ignores_nulls_last_parameter(self):
     disbursements = [
         factories.ScheduleBFactory(disbursement_amount=50),
         factories.ScheduleBFactory(disbursement_amount=200, disbursement_date=datetime.date(2016, 3, 1)),
         factories.ScheduleBFactory(disbursement_amount=150, disbursement_date=datetime.date(2016, 2, 1)),
         factories.ScheduleBFactory(disbursement_amount=100, disbursement_date=datetime.date(2016, 1, 1)),
     ]
     sub_ids = [str(each.sub_id) for each in disbursements]
     results = self._results(api.url_for(ScheduleBView, sort='-disbursement_date', sort_nulls_last=True, **self.kwargs))
     self.assertEqual([each['sub_id'] for each in results], sub_ids)
Esempio n. 4
0
    def test_null_pagination_with_null_sort_column_values_ascending_with_sort_expression(self):
        # NOTE:  Schedule B is sorted by disbursement date with the expression
        # sa.func.coalesce(self.disbursement_date, sa.cast('9999-12-31', sa.Date))
        # by default (in descending order), so we must account for that with the
        # results and slice the baseline list of objects accordingly!
        filings = [
            factories.ScheduleBFactory(disbursement_date=None)
            # this range should ensure the page has a null transition
            for _ in range(10)
        ]
        filings = filings + [
            factories.ScheduleBFactory(
                disbursement_date=datetime.date(2016, 1, 1)
            )
            for _ in range(15)
        ]

        page1 = self._results(api.url_for(
            ScheduleBView,
            sort='disbursement_date',
            sort_reverse_nulls='true',
            **self.kwargs
        ))

        self.assertEqual(len(page1), 20)

        top_reversed_from_middle = filings[10::]
        reversed_from_bottom_to_middle = filings[0:5:]
        top_reversed_from_middle.extend(reversed_from_bottom_to_middle)
        self.assertEqual(
            [int(each['sub_id']) for each in page1],
            [each.sub_id for each in top_reversed_from_middle],
        )
        self.assertEqual(
            [each['disbursement_date'] for each in page1],
            [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in
             top_reversed_from_middle]
        )
        page2 = self._results(api.url_for(
            ScheduleBView,
            last_index=page1[-1]['sub_id'],
            sort_null_only=True,
            sort='disbursement_date',
            **self.kwargs
        ))
        self.assertEqual(len(page2), 5)
        self.assertEqual(
            [int(each['sub_id']) for each in page2],
            [each.sub_id for each in filings[5:10:]],
        )
        self.assertEqual(
            [each['disbursement_date'] for each in page2],
            [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in
             filings[5:10:]]
        )
Esempio n. 5
0
 def test_amount_sched_b(self):
     [
         factories.ScheduleBFactory(disbursement_amount=50),
         factories.ScheduleBFactory(disbursement_amount=100),
         factories.ScheduleBFactory(disbursement_amount=150),
         factories.ScheduleBFactory(disbursement_amount=200),
     ]
     results = self._results(api.url_for(ScheduleBView, min_amount=100))
     self.assertTrue(all(each['disbursement_amount'] >= 100 for each in results))
     results = self._results(api.url_for(ScheduleBView, max_amount=150))
     self.assertTrue(all(each['disbursement_amount'] <= 150 for each in results))
     results = self._results(api.url_for(ScheduleBView, min_amount=100, max_amount=150))
     self.assertTrue(all(100 <= each['disbursement_amount'] <= 150 for each in results))
Esempio n. 6
0
    def test_filter_line_number(self):
        [
            factories.ScheduleAFactory(line_number='16', filing_form='F3X'),
            factories.ScheduleAFactory(line_number='17', filing_form='F3X')
        ]
        results = self._results(api.url_for(ScheduleAView, line_number='f3X-16', **self.kwargs))
        self.assertEqual(len(results), 1)

        [
            factories.ScheduleBFactory(line_number='21', filing_form='F3X'),
            factories.ScheduleBFactory(line_number='22', filing_form='F3X')
        ]

        results = self._results(api.url_for(ScheduleBView, line_number='f3X-21', **self.kwargs))
        self.assertEqual(len(results), 1)
Esempio n. 7
0
 def test_update_aggregate_purpose_create(self):
     filing = factories.ScheduleBFactory(
         report_year=2015,
         committee_id='C12345',
         disbursement_amount=538,
         disbursement_description='CAMPAIGN BUTTONS',
     )
     db.session.flush()
     db.session.execute('select update_aggregates()')
     rows = models.ScheduleBByPurpose.query.filter_by(
         cycle=2016,
         committee_id='C12345',
         purpose='MATERIALS',
     ).all()
     self.assertEqual(len(rows), 1)
     self.assertEqual(rows[0].total, 538)
     self.assertEqual(rows[0].count, 1)
     filing.disbursement_description = 'BUMPER STICKERS'
     db.session.add(filing)
     db.session.flush()
     db.session.execute('select update_aggregates()')
     db.session.refresh(rows[0])
     self.assertEqual(rows[0].total, 538)
     self.assertEqual(rows[0].count, 1)
     filing.disbursement_description = 'HANGING OUT'
     db.session.add(filing)
     db.session.flush()
     db.session.execute('select update_aggregates()')
     db.session.refresh(rows[0])
     self.assertEqual(rows[0].total, 0)
     self.assertEqual(rows[0].count, 0)
Esempio n. 8
0
 def test_pagination_with_null_sort_column_values_with_sort_expression(self):
     # NOTE:  Schedule B is sorted by disbursement date with the expression
     # sa.func.coalesce(self.disbursement_date, sa.cast('9999-12-31', sa.Date))
     # by default (in descending order), so we must account for that with the
     # results and slice the baseline list of objects accordingly!
     filings = [
         factories.ScheduleBFactory(disbursement_date=None)
         for _ in range(5)
     ]
     filings = filings + [
         factories.ScheduleBFactory(
             disbursement_date=datetime.date(2016, 1, 1)
         )
         for _ in range(25)
     ]
     page1 = self._results(api.url_for(
         ScheduleBView,
         sort='disbursement_date',
         **self.kwargs
     ))
     self.assertEqual(len(page1), 20)
     self.assertEqual(
         [int(each['sub_id']) for each in page1],
         [each.sub_id for each in filings[5:25]],
     )
     self.assertEqual(
         [each['disbursement_date'] for each in page1],
         [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in filings[5:25]]
     )
     page2 = self._results(
         api.url_for(
             ScheduleBView,
             last_index=page1[-1]['sub_id'],
             sort='disbursement_date',
             **self.kwargs
         )
     )
     self.assertEqual(len(page2), 5)
     self.assertEqual(
         [int(each['sub_id']) for each in page2],
         [each.sub_id for each in filings[25:]],
     )
     self.assertEqual(
         [each['disbursement_date'] for each in page2],
         [each.disbursement_date.strftime('%Y-%m-%d') if each.disbursement_date else None for each in filings[25:]]
     )
Esempio n. 9
0
 def test_schedule_b_multiple_two_year_transaction_period(self):
     """
     testing schedule_b api can take multiple cyccles now
     """
     disbursements = [
         factories.ScheduleBFactory(report_year=2014,
                                    two_year_transaction_period=2014),
         factories.ScheduleBFactory(report_year=2016,
                                    two_year_transaction_period=2016),
         factories.ScheduleBFactory(report_year=2018,
                                    two_year_transaction_period=2018),
     ]
     response = self._response(
         api.url_for(
             ScheduleBView,
             two_year_transaction_period=[2016, 2018],
         ))
     self.assertEqual(len(response['results']), 2)
Esempio n. 10
0
 def test_update_aggregate_purpose_existing(self):
     existing = models.ScheduleBByPurpose.query.filter_by(
         purpose='CONTRIBUTIONS',
         cycle=2016,
     ).first()
     total = existing.total
     count = existing.count
     factories.ScheduleBFactory(
         report_year=2015,
         committee_id=existing.committee_id,
         disbursement_amount=538,
         disbursement_type='24K',
     )
     db.session.flush()
     db.session.execute('select update_aggregates()')
     db.session.refresh(existing)
     self.assertEqual(existing.total, total + 538)
     self.assertEqual(existing.count, count + 1)
Esempio n. 11
0
 def test_schedule_b_pagination_with_sort_expression(self):
     # NOTE:  Schedule B is sorted by disbursement date with the expression
     # sa.func.coalesce(self.disbursement_date, sa.cast('9999-12-31', sa.Date))
     # by default (in descending order), so we must account for that with the
     # results and slice the baseline list of objects accordingly!
     filings = [factories.ScheduleBFactory() for _ in range(30)]
     page1 = self._results(api.url_for(ScheduleBView, **self.kwargs))
     self.assertEqual(len(page1), 20)
     self.assertEqual(
         [int(each['sub_id']) for each in page1],
         [each.sub_id for each in filings[:-21:-1]],
     )
     page2 = self._results(
         api.url_for(ScheduleBView,
                     last_index=page1[-1]['sub_id'],
                     **self.kwargs))
     self.assertEqual(len(page2), 10)
     self.assertEqual(
         [int(each['sub_id']) for each in page2],
         [each.sub_id for each in filings[9::-1]],
     )