示例#1
0
 def setUp(self):
     super(TestAggregates, self).setUp()
     self.committee = factories.CommitteeHistoryFactory(
         name='Ritchie for America',
         cycle=2012,
     )
     self.candidate = factories.CandidateDetailFactory(
         candidate_id='P123',
         name='Robert Ritchie',
         election_years=[2012],
         office='P',
     )
     self.candidate_history = factories.CandidateHistoryFactory(
         candidate_id='P123',
         name='Robert Ritchie',
         election_years=[2012],
         two_year_period=2012,
         office='P',
     )
     factories.CandidateElectionFactory(
         candidate_id='P123',
         cand_election_year=2012,
     )
示例#2
0
    def test_disbursement_purpose(self):
        committee = factories.CommitteeHistoryFactory(cycle=2012)

        aggregate = factories.ScheduleBByPurposeFactory(
            committee_id=committee.committee_id,
            cycle=committee.cycle,
            purpose='ADMINISTRATIVE EXPENSES')
        results = self._results(
            api.url_for(ScheduleBByPurposeView,
                        committee_id=committee.committee_id,
                        cycle=2012,
                        purpose='Administrative'))
        self.assertEqual(len(results), 1)
        expected = {
            'committee_id': committee.committee_id,
            'purpose': 'ADMINISTRATIVE EXPENSES',
            'cycle': 2012,
            'total': aggregate.total,
            'count': aggregate.count,
            'memo_total': aggregate.memo_total,
            'memo_count': aggregate.memo_count,
        }
        self.assertEqual(results[0], expected)
示例#3
0
 def test_ie_committee(self):
     committee = factories.CommitteeFactory(committee_type='I')
     committee_id = committee.committee_id
     factories.CommitteeHistoryFactory(
         committee_id=committee_id,
         committee_type='I',
     )
     report = factories.ReportsIEOnlyFactory(
         committee_id=committee_id,
         independent_contributions_period=200,
         independent_expenditures_period=100,
     )
     results = self._results(
         api.url_for(
             ReportsView,
             committee_id=committee_id,
         ))
     result = results[0]
     for key in [
             'report_form', 'independent_contributions_period',
             'independent_expenditures_period'
     ]:
         self.assertEqual(result[key], getattr(report, key))
示例#4
0
    def test_disbursement_recipient(self):
        committee = factories.CommitteeHistoryFactory(cycle=2012)

        aggregate = factories.ScheduleBByRecipientFactory(
            committee_id=committee.committee_id,
            cycle=committee.cycle,
            recipient_name='STARBOARD STRATEGIES, INC.')
        results = self._results(
            api.url_for(ScheduleBByRecipientView,
                        committee_id=committee.committee_id,
                        cycle=2012,
                        recipient_name='Starboard Strategies'))
        self.assertEqual(len(results), 1)
        expected = {
            'committee_id': committee.committee_id,
            'recipient_name': 'STARBOARD STRATEGIES, INC.',
            'cycle': 2012,
            'total': aggregate.total,
            'count': aggregate.count,
            'memo_total': aggregate.memo_total,
            'memo_count': aggregate.memo_count,
        }
        self.assertEqual(results[0], expected)
示例#5
0
 def _check_reports(self, committee_type, factory, schema):
     committee = factories.CommitteeFactory(committee_type=committee_type)
     factories.CommitteeHistoryFactory(
         committee_id=committee.committee_id,
         committee_type=committee_type,
         cycle=2012,
     )
     end_dates = [datetime.datetime(2012, 1, 1), datetime.datetime(2008, 1, 1)]
     committee_id = committee.committee_id
     db.session.flush()
     [
         factory(
             committee_id=committee_id, coverage_end_date=end_date, report_year=2011,
         )
         for end_date in end_dates
     ]
     response = self._results(
         api.url_for(CommitteeReportsView, committee_id=committee_id)
     )
     self.assertEqual(len(response), 2)
     self.assertEqual(response[0]['coverage_end_date'], isoformat(end_dates[0]))
     self.assertEqual(response[1]['coverage_end_date'], isoformat(end_dates[1]))
     assert response[0].keys() == schema().fields.keys()
示例#6
0
 def test_reports_sort_default(self):
     committee = factories.CommitteeFactory(committee_type='H')
     committee_id = committee.committee_id
     factories.CommitteeHistoryFactory(
         committee_id=committee_id, committee_type='H',
     )
     dates = [
         datetime.datetime(2015, 7, 4),
         datetime.datetime(2015, 7, 5),
     ]
     dates_formatted = [isoformat(each) for each in dates]
     factories.ReportsHouseSenateFactory(
         committee_id=committee_id, coverage_end_date=dates[0]
     )
     factories.ReportsHouseSenateFactory(
         committee_id=committee_id, coverage_end_date=dates[1]
     )
     results = self._results(
         api.url_for(CommitteeReportsView, committee_id=committee_id)
     )
     self.assertEqual(
         [each['coverage_end_date'] for each in results], dates_formatted[::-1]
     )
示例#7
0
 def test_reports_sort(self):
     committee = factories.CommitteeFactory(committee_type='H')
     committee_id = committee.committee_id
     factories.CommitteeHistoryFactory(
         committee_id=committee_id, committee_type='H',
     )
     contributions = [0, 100]
     factories.ReportsHouseSenateFactory(
         committee_id=committee_id, net_contributions_period=contributions[0]
     )
     factories.ReportsHouseSenateFactory(
         committee_id=committee_id, net_contributions_period=contributions[1]
     )
     results = self._results(
         api.url_for(
             CommitteeReportsView,
             committee_id=committee_id,
             sort=['-net_contributions_period'],
         )
     )
     self.assertEqual(
         [each['net_contributions_period'] for each in results], contributions[::-1]
     )
示例#8
0
    def test_Presidential_totals(self):
        committee_id = 'C8675309'
        transaction_coverage = factories.TransactionCoverageFactory(
            committee_id=committee_id, fec_election_year=2016)
        history = factories.CommitteeHistoryFactory(
            committee_id=committee_id,
            committee_type='P',
        )
        presidential_fields = {
            'committee_id': 'C8675309',
            'cycle': 2016,
            'candidate_contribution': 1,
            'exempt_legal_accounting_disbursement': 2,
            'federal_funds': 3,
            'fundraising_disbursements': 4,
            'loan_repayments_made': 16,
            'loans_received': 5,
            'loans_received_from_candidate': 6,
            'offsets_to_fundraising_expenditures': 7,
            'offsets_to_legal_accounting': 8,
            'total_offsets_to_operating_expenditures': 9,
            'other_loans_received': 10,
            'other_receipts': 11,
            'repayments_loans_made_by_candidate': 12,
            'repayments_other_loans': 13,
            'transfers_from_affiliated_committee': 14,
            'transfers_to_other_authorized_committee': 15,
        }

        fields = utils.extend(shared_fields, presidential_fields)
        committee_total = factories.CommitteeTotalsPerCycleFactory(**fields)

        fields = utils.extend(fields, transaction_coverage_fields)

        results = self._results(
            api.url_for(TotalsCommitteeView, committee_id=committee_id))
        self.assertEqual(results[0], fields)
示例#9
0
    def setUp(self):
        super().setUp()
        self.candidate = factories.CandidateDetailFactory()
        self.committees = [factories.CommitteeDetailFactory() for _ in range(5)]
        self.histories = [
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[0].committee_id,
                cycle=2010,
                designation='P',
                is_active=True,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[1].committee_id,
                cycle=2012,
                designation='P',
                is_active=True,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[2].committee_id,
                cycle=2014,
                designation='P',
                is_active=True,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[3].committee_id,
                cycle=2014,
                designation='A',
                is_active=False,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[4].committee_id,
                cycle=2014,
                designation='J',
                is_active=False,
            ),
        ]

        db.session.flush()
        self.links = [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[0].committee_id,
                fec_election_year=2010,
                election_yr_to_be_included=2012,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[1].committee_id,
                fec_election_year=2012,
                election_yr_to_be_included=2012,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[2].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[3].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='A',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[4].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='J',
            ),
        ]
        self.elections = [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=2012,
                prev_election_year=2008,
            ),
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=2016,
                prev_election_year=2012,
            ),
        ]
示例#10
0
    def test_party_totals(self):

        committee_id = 'C00540005'
        transaction_coverage = factories.TransactionCoverageFactory(  # noqa
            committee_id=committee_id, fec_election_year=2014)
        history = factories.CommitteeHistoryFactory(  # noqa
            committee_id=committee_id,
            committee_type='X',
        )
        party_fields = {
            'committee_id': committee_id,
            'cycle': 2014,
            'committee_name': 'PRESIDENTIAL INAUGURAL COMMITTEE',
            'coverage_start_date': '2012-12-10 00:00:00',
            'coverage_end_date': '2013-08-07 00:00:00',
            'all_loans_received': 1,
            'allocated_federal_election_levin_share': 2,
            'coordinated_expenditures_by_party_committee': 3,
            'fed_candidate_committee_contributions': 4,
            'fed_candidate_contribution_refunds': 5,
            'fed_disbursements': 6,
            'fed_election_activity': 7,
            'fed_operating_expenditures': 8,
            'fed_receipts': 9,
            'federal_funds': 2,
            'independent_expenditures': 10,
            'loan_repayments_made': 11,
            'loan_repayments_received': 12,
            'loans_and_loan_repayments_received': 2,
            'loans_and_loan_repayments_made': 2,
            'loans_made': 13,
            'non_allocated_fed_election_activity': 14,
            'total_transfers': 15,
            'other_fed_operating_expenditures': 16,
            'other_fed_receipts': 17,
            'shared_fed_activity': 18,
            'shared_fed_activity_nonfed': 19,
            'shared_fed_operating_expenditures': 20,
            'shared_nonfed_operating_expenditures': 21,
            'transfers_from_affiliated_party': 22,
            'transfers_from_nonfed_account': 23,
            'transfers_from_nonfed_levin': 24,
            'transfers_to_affiliated_committee': 25,
            'net_contributions': 127,
            'net_operating_expenditures': 128,
            'exp_subject_limits': 4,
            'exp_prior_years_subject_limits': 4,
            'total_exp_subject_limits': 4,
            'refunds_relating_convention_exp': 4,
            'itemized_refunds_relating_convention_exp': 4,
            'unitemized_refunds_relating_convention_exp': 4,
            'other_refunds': 4,
            'itemized_other_refunds': 4,
            'unitemized_other_refunds': 4,
            'itemized_other_income': 4,
            'unitemized_other_income': 4,
            'convention_exp': 4,
            'itemized_convention_exp': 4,
            'unitemized_convention_exp': 4,
            'itemized_other_disb': 4,
            'unitemized_other_disb': 4,
        }
        fields = utils.extend(party_fields, shared_fields)
        committee_total = factories.TotalsPartyFactory(**fields)  # noqa

        fields = utils.extend(fields, transaction_coverage_fields)

        results = self._results(
            api.url_for(TotalsCommitteeView, committee_id=committee_id))
        self.assertEqual(results[0], fields)
示例#11
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateDetailFactory()
     self.candidates = [
         factories.CandidateHistoryFactory(
             candidate_id=self.candidate.candidate_id,
             state='PR',
             district='00',
             two_year_period=2018,
             election_years=[2020],
             cycles=[2018, 2020],
             office='H',
             candidate_election_year=2020,
         ),
         factories.CandidateHistoryFactory(
             candidate_id=self.candidate.candidate_id,
             state='PR',
             district='00',
             two_year_period=2020,
             election_years=[2020],
             cycles=[2018, 2020],
             office='H',
             candidate_election_year=2020,
         ),
     ]
     self.committees = [
         factories.CommitteeHistoryFactory(cycle=2020, designation='P'),
         factories.CommitteeHistoryFactory(cycle=2020, designation='A'),
     ]
     [
         factories.CandidateElectionFactory(
             candidate_id=self.candidate.candidate_id,
             cand_election_year=year) for year in [2016, 2020]
     ]
     [
         factories.CommitteeDetailFactory(committee_id=each.committee_id)
         for each in self.committees
     ]
     db.session.flush()
     self.candidate_committee_links = [
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[0].committee_id,
             committee_designation='P',
             fec_election_year=2018,
             election_yr_to_be_included=2020,
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[1].committee_id,
             committee_designation='A',
             fec_election_year=2018,
             election_yr_to_be_included=2020,
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[0].committee_id,
             committee_designation='P',
             fec_election_year=2020,
             election_yr_to_be_included=2020,
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[1].committee_id,
             committee_designation='A',
             fec_election_year=2020,
             election_yr_to_be_included=2020,
         ),
     ]
     self.totals = [
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[1].committee_id,
             coverage_end_date=datetime.datetime(2018, 12, 31),
             last_cash_on_hand_end_period=100,
             cycle=2018,
         ),
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[1].committee_id,
             coverage_end_date=datetime.datetime(2020, 12, 31),
             last_cash_on_hand_end_period=300,
             cycle=2020,
         ),
     ]
     db.session.flush()
示例#12
0
    def setUp(self):
        super().setUp()
        self.candidate = factories.CandidateHistoryFutureFactory(
            candidate_id='S123',
            two_year_period=2012,
            candidate_election_year=2012,
        )
        self.committees = [
            factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
            factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
        ]
        factories.CandidateDetailFactory(
            candidate_id=self.candidate.candidate_id,
            election_years=[2008, 2012],
        )
        [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=election_year,
            ) for election_year in [2008, 2012]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.committees
        ]
        factories.CandidateTotalFactory(
            candidate_id=self.candidate.candidate_id,
            cycle=2012,
            is_election=True,
            receipts=100,
        )
        factories.CandidateTotalFactory(
            candidate_id=self.candidate.candidate_id,
            cycle=2012,
            is_election=False,
            receipts=75,
        )
        factories.CandidateFlagsFactory(
            candidate_id=self.candidate.candidate_id)
        db.session.flush()
        # Create two-year totals for both the target period (2011-2012) and the
        # previous period (2009-2010) for testing the `election_full` flag
        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate.candidate_id,
            committee_id=self.committees[0].committee_id,
            committee_designation='P',
            committee_type='S',
            fec_election_year=2012,
            election_yr_to_be_included=2012,
        )
        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate.candidate_id,
            committee_id=self.committees[1].committee_id,
            committee_designation='A',
            committee_type='S',
            fec_election_year=2012,
            election_yr_to_be_included=2012,
        )
        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate.candidate_id,
            committee_id=self.committees[1].committee_id,
            committee_designation='A',
            committee_type='S',
            fec_election_year=2010,
            election_yr_to_be_included=2012,
        )
        # Create a candidate_zero without a committee and $0 in CandidateTotal
        self.candidate_zero = factories.CandidateHistoryFutureFactory(
            candidate_id='H321',
            two_year_period=2018,
            candidate_election_year=2018,
            candidate_inactive=True,
        )
        factories.CandidateDetailFactory(
            candidate_id=self.candidate_zero.candidate_id,
            election_years=[2018],
        )
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_zero.candidate_id,
            cycle=2018,
            is_election=False,
            receipts=0,
        )
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_zero.candidate_id,
            cycle=2018,
            is_election=True,
            receipts=0,
        )
        # Create data for a candidate who ran in 2017 and 2018

        self.candidate_17_18 = factories.CandidateHistoryFutureFactory(
            candidate_id='S456',
            two_year_period=2018,
            candidate_election_year=2018,
            candidate_inactive=False,
        )
        self.committees_17_18 = [
            factories.CommitteeHistoryFactory(cycle=2018, designation='P'),
        ]
        factories.CandidateDetailFactory(
            candidate_id=self.candidate_17_18.candidate_id,
            election_years=[2018],
        )
        [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate_17_18.candidate_id,
                cand_election_year=election_year,
            ) for election_year in [2017, 2018]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.committees_17_18
        ]
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_17_18.candidate_id,
            cycle=2018,
            is_election=True,
            receipts=100,
        )
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_17_18.candidate_id,
            cycle=2018,
            is_election=False,
            receipts=100,
        )
        factories.CandidateFlagsFactory(
            candidate_id=self.candidate_17_18.candidate_id)
        db.session.flush()

        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate_17_18.candidate_id,
            committee_id=self.committees_17_18[0].committee_id,
            committee_designation='P',
            committee_type='S',
            cand_election_year=2017,
            fec_election_year=2018,
        )
        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate_17_18.candidate_id,
            committee_id=self.committees_17_18[0].committee_id,
            committee_designation='P',
            committee_type='S',
            cand_election_year=2018,
            fec_election_year=2018,
        )
        # Create data for a candidate who ran just in 2017
        self.candidate_17_only = factories.CandidateHistoryFutureFactory(
            candidate_id='H456',
            two_year_period=2018,
            candidate_election_year=2017,
        )
        self.committees_17_only = [
            factories.CommitteeHistoryFactory(cycle=2018, designation='P'),
        ]
        factories.CandidateDetailFactory(
            candidate_id=self.candidate_17_only.candidate_id,
            election_years=[2017],
        )
        [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate_17_only.candidate_id,
                cand_election_year=election_year,
            ) for election_year in [2017]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.committees_17_only
        ]
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_17_only.candidate_id,
            cycle=2018,
            is_election=True,
            receipts=150,
        )
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_17_only.candidate_id,
            cycle=2018,
            is_election=False,
            receipts=150,
        )
        factories.CandidateFlagsFactory(
            candidate_id=self.candidate_17_only.candidate_id)
        db.session.flush()

        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate_17_only.candidate_id,
            committee_id=self.committees_17_only[0].committee_id,
            committee_designation='P',
            committee_type='S',
            cand_election_year=2017,
            fec_election_year=2018,
        )

        # Create data for future presidential - next_cycle. Use formula for future

        # Test full next_cycle and current_cycle 2-year totals

        self.candidate_20 = factories.CandidateHistoryFutureFactory(
            candidate_id='P456',
            two_year_period=self.current_cycle,
            candidate_election_year=self.next_cycle,
        )
        self.candidate_20 = factories.CandidateHistoryFutureFactory(
            candidate_id='P456',
            two_year_period=self.next_cycle,
            candidate_election_year=self.next_cycle,
        )
        # Candidate history won't have next_cycle yet
        self.committees_20 = [
            factories.CommitteeHistoryFactory(cycle=self.current_cycle,
                                              designation='P'),
        ]
        factories.CandidateDetailFactory(
            candidate_id=self.candidate_20.candidate_id,
            election_years=[self.next_cycle],
        )
        [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate_20.candidate_id,
                cand_election_year=election_year,
            ) for election_year in [self.next_cycle - 4, self.next_cycle]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.committees_20
        ]
        # Full next_cycle
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_20.candidate_id,
            cycle=self.next_cycle,
            is_election=True,
            receipts=55000,
        )
        # current_cycle 2-year
        factories.CandidateTotalFactory(
            candidate_id=self.candidate_20.candidate_id,
            cycle=self.current_cycle,
            is_election=False,
            receipts=25000,
        )
        factories.CandidateFlagsFactory(
            candidate_id=self.candidate_20.candidate_id)
        db.session.flush()

        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate_20.candidate_id,
            committee_id=self.committees_20[0].committee_id,
            committee_designation='P',
            committee_type='P',
            cand_election_year=self.next_cycle,
            fec_election_year=self.current_cycle,
        )

        factories.CandidateCommitteeLinkFactory(
            candidate_id=self.candidate_20.candidate_id,
            committee_id=self.committees_20[0].committee_id,
            committee_designation='P',
            committee_type='P',
            cand_election_year=self.next_cycle,
            fec_election_year=self.next_cycle,
        )
示例#13
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateDetailFactory()
     self.candidates = [
         factories.CandidateHistoryFactory(
             candidate_id=self.candidate.candidate_id,
             state='NY',
             two_year_period=2012,
             election_years=[2010, 2012],
             cycles=[2010, 2012],
             office='S',
         ),
         factories.CandidateHistoryFactory(
             candidate_id=self.candidate.candidate_id,
             state='NY',
             two_year_period=2010,
             election_years=[2010, 2012],
             cycles=[2010, 2012],
             office='S',
         ),
     ]
     self.committees = [
         factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
         factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
     ]
     [
         factories.CandidateElectionFactory(
             candidate_id=self.candidate.candidate_id,
             cand_election_year=year) for year in [2010, 2012]
     ]
     [
         factories.CommitteeDetailFactory(committee_id=each.committee_id)
         for each in self.committees
     ]
     db.session.flush()
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[0].committee_id,
         committee_designation='A',
         fec_election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[1].committee_id,
         committee_designation='P',
         fec_election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[1].committee_id,
         committee_designation='P',
         fec_election_year=2010,
     )
     self.totals = [
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[0].committee_id,
             coverage_end_date=datetime.datetime(2012, 9, 30),
             last_cash_on_hand_end_period=1979,
             cycle=2012,
         ),
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[1].committee_id,
             coverage_end_date=datetime.datetime(2012, 12, 31),
             last_cash_on_hand_end_period=1979,
             cycle=2012,
         ),
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[1].committee_id,
             coverage_end_date=datetime.datetime(2012, 12, 31),
             last_cash_on_hand_end_period=1979,
             cycle=2010,
         ),
     ]
示例#14
0
    def setUp(self):
        super().setUp()
        self.candidate = factories.CandidateDetailFactory()
        self.candidates = [
            factories.CandidateHistoryFactory(
                candidate_id=self.candidate.candidate_id,
                state='NY',
                two_year_period=2012,
                election_years=[2010, 2012],
                cycles=[2010, 2012],
                office='S',
                candidate_election_year=2012,
            ),
            factories.CandidateHistoryFactory(
                candidate_id=self.candidate.candidate_id,
                state='NY',
                two_year_period=2010,
                election_years=[2010, 2012],
                cycles=[2010, 2012],
                office='S',
                candidate_election_year=2012,
            ),
        ]
        self.committees = [
            factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
            factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
        ]
        [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=year) for year in [2010, 2012]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.committees
        ]
        db.session.flush()
        self.candidate_committee_links = [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[0].committee_id,
                committee_designation='A',
                fec_election_year=2012,
                election_yr_to_be_included=2012,
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[1].committee_id,
                committee_designation='P',
                fec_election_year=2012,
                election_yr_to_be_included=2012,
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[1].committee_id,
                committee_designation='P',
                fec_election_year=2010,
                election_yr_to_be_included=2012,
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[1].committee_id,
                committee_designation='P',
                fec_election_year=2010,
            ),
        ]
        self.totals = [
            factories.TotalsHouseSenateFactory(
                receipts=50,
                disbursements=75,
                committee_id=self.committees[0].committee_id,
                coverage_end_date=datetime.datetime(2012, 9, 30),
                last_cash_on_hand_end_period=100,
                cycle=2012,
            ),
            factories.TotalsHouseSenateFactory(
                receipts=50,
                disbursements=75,
                committee_id=self.committees[1].committee_id,
                coverage_end_date=datetime.datetime(2012, 12, 31),
                last_cash_on_hand_end_period=100,
                cycle=2012,
            ),
            factories.TotalsHouseSenateFactory(
                receipts=50,
                disbursements=75,
                committee_id=self.committees[1].committee_id,
                coverage_end_date=datetime.datetime(2012, 12, 31),
                last_cash_on_hand_end_period=300,
                cycle=2010,
            ),
        ]

        self.president_candidate = factories.CandidateDetailFactory()
        self.president_candidates = [
            factories.CandidateHistoryFactory(
                candidate_id=self.president_candidate.candidate_id,
                state='NY',
                two_year_period=2020,
                office='P',
                candidate_inactive=False,
                candidate_election_year=2020,
            ),
            factories.CandidateHistoryFactory(
                candidate_id=self.president_candidate.candidate_id,
                state='NY',
                two_year_period=2018,
                office='P',
                candidate_inactive=False,
                candidate_election_year=2020,
            ),
        ]
        self.president_committees = [
            factories.CommitteeHistoryFactory(cycle=2020, designation='P'),
            factories.CommitteeHistoryFactory(cycle=2020, designation='J'),
        ]
        [
            factories.CandidateElectionFactory(
                candidate_id=self.president_candidate.candidate_id,
                cand_election_year=year,
            ) for year in [2016, 2020]
        ]
        [
            factories.CommitteeDetailFactory(committee_id=each.committee_id)
            for each in self.president_committees
        ]
        db.session.flush()
        self.president_candidate_committee_links = [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.president_candidate.candidate_id,
                committee_id=self.president_committees[0].committee_id,
                committee_designation='P',
                fec_election_year=2020,
                cand_election_year=2020,
                election_yr_to_be_included=2020,
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.president_candidate.candidate_id,
                committee_id=self.president_committees[0].committee_id,
                committee_designation='P',
                fec_election_year=2018,
                cand_election_year=2020,
                election_yr_to_be_included=2020,
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.president_candidate.candidate_id,
                committee_id=self.president_committees[1].committee_id,
                committee_designation='P',
                fec_election_year=2018,
                cand_election_year=2020,
                election_yr_to_be_included=2020,
            ),
        ]

        self.presidential_totals = [
            factories.TotalsCombinedFactory(
                receipts=50,
                disbursements=75,
                committee_id=self.president_committees[0].committee_id,
                coverage_end_date=datetime.datetime(2019, 9, 30),
                last_cash_on_hand_end_period=0,
                cycle=2020,
            ),
            factories.TotalsCombinedFactory(
                receipts=1,
                disbursements=1,
                committee_id=self.president_committees[1].committee_id,
                coverage_end_date=datetime.datetime(2017, 12, 31),
                last_cash_on_hand_end_period=100,
                cycle=2018,
            ),
            factories.TotalsCombinedFactory(
                receipts=25,
                disbursements=10,
                committee_id=self.president_committees[0].committee_id,
                coverage_end_date=datetime.datetime(2017, 12, 31),
                last_cash_on_hand_end_period=300,
                cycle=2018,
            ),
        ]
示例#15
0
    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)
        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()

        # 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'))
示例#16
0
    def setUp(self):
        super().setUp()
        self.candidate = factories.CandidateDetailFactory()
        self.committees = [
            factories.CommitteeDetailFactory() for _ in range(6)
        ]
        self.histories = [
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[0].committee_id,
                cycle=2010,
                designation='P',
                is_active=True,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[1].committee_id,
                cycle=2012,
                designation='P',
                is_active=True,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[2].committee_id,
                cycle=2014,
                designation='P',
                is_active=True,
            ),
            # Candidate PCC converted to PAC in 2016
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[2].committee_id,
                cycle=2016,
                designation='P',
                is_active=True,
                # Needed to show conversion info
                former_candidate_id=self.candidate.candidate_id,
                former_candidate_election_year=2016,
                former_committee_name=
                "Used to be PCC but I'm a PAC now committeee"),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[3].committee_id,
                cycle=2014,
                designation='A',
                is_active=False,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[4].committee_id,
                cycle=2014,
                designation='J',
                is_active=False,
            ),
            factories.CommitteeHistoryFactory(
                committee_id=self.committees[5].committee_id,
                cycle=2020,
                designation='D',
                is_active=True,
                sponsor_candidate_ids=['H003']),
        ]

        db.session.flush()
        self.links = [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[0].committee_id,
                fec_election_year=2010,
                election_yr_to_be_included=2012,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[1].committee_id,
                fec_election_year=2012,
                election_yr_to_be_included=2012,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[2].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='P',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[3].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='A',
            ),
            factories.CandidateCommitteeLinkFactory(
                candidate_id=self.candidate.candidate_id,
                committee_id=self.committees[4].committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='J',
            ),
        ]
        self.elections = [
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=2012,
                prev_election_year=2008,
            ),
            factories.CandidateElectionFactory(
                candidate_id=self.candidate.candidate_id,
                cand_election_year=2016,
                prev_election_year=2012,
            ),
        ]
    def test_filters_committee_candidate_id_cycle(self):
        factories.CandidateHistoryFactory(candidate_id='P001',
                                          two_year_period=2000,
                                          candidate_election_year=2000,
                                          name='Apple Smith'),
        factories.CandidateHistoryFactory(candidate_id='P002',
                                          two_year_period=2000,
                                          candidate_election_year=2000,
                                          name='Snapple Smith'),
        factories.CandidateHistoryFactory(candidate_id='P002',
                                          two_year_period=2004,
                                          candidate_election_year=2004,
                                          name='Zapple Smith'),

        factories.CommitteeHistoryFactory(committee_id='C001',
                                          cycle=2000,
                                          name='Acme Co'),
        factories.CommitteeHistoryFactory(committee_id='C002',
                                          cycle=2000,
                                          name='Tetris Corp'),
        factories.CommitteeHistoryFactory(committee_id='C002',
                                          cycle=2004,
                                          name='Winner PAC'),

        factories.CommunicationCostByCandidateFactory(committee_id='C001',
                                                      candidate_id='P001',
                                                      cycle=2000)
        factories.CommunicationCostByCandidateFactory(committee_id='C001',
                                                      candidate_id='P002',
                                                      cycle=2000)
        factories.CommunicationCostByCandidateFactory(committee_id='C002',
                                                      candidate_id='P001',
                                                      cycle=2004)
        db.session.flush()

        # assert results filtered by committee_id sorted by candidate name in descending order
        results = self._results(
            api.url_for(CCAggregatesView,
                        committee_id='C001',
                        sort='-candidate_name'))
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['candidate_name'], 'Snapple Smith')
        self.assertEqual(results[1]['candidate_name'], 'Apple Smith')

        # assert results filtered by committee_id sorted by candidate name in ascending order
        results = self._results(
            api.url_for(CCAggregatesView,
                        committee_id='C001',
                        sort='candidate_name'))
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['candidate_name'], 'Apple Smith')
        self.assertEqual(results[1]['candidate_name'], 'Snapple Smith')

        # assert results filtered by candidate_id sorted by committee name in descending order
        results = self._results(
            api.url_for(CCAggregatesView,
                        candidate_id='P001',
                        sort='-committee_name'))
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['committee_name'], 'Winner PAC')
        self.assertEqual(results[1]['committee_name'], 'Acme Co')

        # assert results filtered by candidate_id sorted by committee name in ascending order
        results = self._results(
            api.url_for(CCAggregatesView,
                        candidate_id='P001',
                        sort='committee_name'))
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['committee_name'], 'Acme Co')
        self.assertEqual(results[1]['committee_name'], 'Winner PAC')

        # assert results filtered by cycle sorted by committee name in ascending order
        results = self._results(
            api.url_for(CCAggregatesView, cycle=2000, sort='committee_name'))
        self.assertEqual(len(results), 2)
        self.assertEqual(results[0]['committee_name'], 'Acme Co')
        self.assertEqual(results[1]['committee_name'], 'Acme Co')
示例#18
0
 def setUp(self):
     super(TestAggregates, self).setUp()
     self.committee = factories.CommitteeHistoryFactory(cycle=2012)
示例#19
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateHistoryFactory(
         candidate_id='S123',
         two_year_period=2012,
     )
     self.committees = [
         factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
         factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
     ]
     factories.CandidateHistoryLatestFactory(
         candidate_id=self.candidate.candidate_id,
         candidate_election_year=2012,
         two_year_period=2012,
     )
     factories.CandidateDetailFactory(
         candidate_id=self.candidate.candidate_id,
         election_years=[2008, 2012],
     )
     [
         factories.CandidateElectionFactory(
             candidate_id=self.candidate.candidate_id,
             cand_election_year=election_year
         )
         for election_year in [2008, 2012]
     ]
     [
         factories.CommitteeDetailFactory(committee_id=each.committee_id)
         for each in self.committees
     ]
     factories.CandidateTotalFactory(
         candidate_id=self.candidate.candidate_id,
         cycle=2012,
         is_election=True,
         receipts=100,
     )
     factories.CandidateTotalFactory(
         candidate_id=self.candidate.candidate_id,
         cycle=2012,
         is_election=False,
         receipts=75,
     )
     factories.CandidateFlagsFactory(
         candidate_id = self.candidate.candidate_id
     )
     db.session.flush()
     # Create two-year totals for both the target period (2011-2012) and the
     # previous period (2009-2010) for testing the `election_full` flag
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[0].committee_id,
         committee_designation='P',
         committee_type='S',
         fec_election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[1].committee_id,
         committee_designation='A',
         committee_type='S',
         fec_election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_id=self.candidate.candidate_id,
         committee_id=self.committees[1].committee_id,
         committee_designation='A',
         committee_type='S',
         fec_election_year=2010,
     )