Example #1
0
 def test_elections_full(self):
     results = self._results(
         api.url_for(
             ElectionView,
             office='house',
             district='00',
             cycle=2020,
             state='PR',
             election_full='true',
         ))
     totals = self.totals
     cash_on_hand_totals = self.totals[:2]
     expected = {
         'candidate_id':
         self.candidate.candidate_id,
         'candidate_name':
         self.candidate.name,
         'incumbent_challenge_full':
         self.candidate.incumbent_challenge_full,
         'party_full':
         self.candidate.party_full,
         'total_receipts':
         sum(each.receipts for each in totals),
         'total_disbursements':
         sum(each.disbursements for each in totals),
         'cash_on_hand_end_period':
         max(each.last_cash_on_hand_end_period
             for each in cash_on_hand_totals),
     }
     assert len(results) == 1
     assert_dicts_subset(results[0], expected)
Example #2
0
 def test_elections_2_year(self):
     results = self._results(
         api.url_for(
             ElectionView,
             office='house',
             district='00',
             cycle=2020,
             state='PR',
             election_full=False,
         ))
     self.assertEqual(len(results), 1)
     totals = [each for each in self.totals if each.cycle == 2020]
     expected = {
         'candidate_id':
         self.candidate.candidate_id,
         'candidate_name':
         self.candidate.name,
         'incumbent_challenge_full':
         self.candidate.incumbent_challenge_full,
         'party_full':
         self.candidate.party_full,
         'total_receipts':
         sum(each.receipts for each in totals),
         'total_disbursements':
         sum(each.disbursements for each in totals),
         'cash_on_hand_end_period':
         sum(each.last_cash_on_hand_end_period for each in totals),
     }
     assert_dicts_subset(results[0], expected)
     assert set(each.committee_id for each in self.committees) == set(
         results[0]['committee_ids'])
Example #3
0
 def test_elections_full(self):
     results = self._results(
         api.url_for(
             ElectionView,
             office='senate',
             cycle=2012,
             state='NY',
             election_full='true',
         ))
     totals = self.totals
     cash_on_hand_totals = self.totals[:2]
     expected = {
         'candidate_id':
         self.candidate.candidate_id,
         'candidate_name':
         self.candidate.name,
         'incumbent_challenge_full':
         self.candidate.incumbent_challenge_full,
         'party_full':
         self.candidate.party_full,
         'total_receipts':
         sum(each.receipts for each in totals),
         'total_disbursements':
         sum(each.disbursements for each in totals),
         'cash_on_hand_end_period':
         sum(each.last_cash_on_hand_end_period
             for each in cash_on_hand_totals),
     }
     assert len(results) == 1
     assert_dicts_subset(results[0], expected)
     assert set(results[0]['committee_ids']) == set(
         each.committee_id for each in self.committees
         if each.designation != 'J')
Example #4
0
 def test_totals(self):
     results = self._results(
         api.url_for(
             TotalsCandidateView,
             candidate_id=self.candidate.candidate_id,
             cycle=2012,
         ))
     assert len(results) == 1
     assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 75})
Example #5
0
 def test_totals(self):
     results = self._results(
         api.url_for(
             TotalsCandidateView,
             candidate_id=self.candidate.candidate_id,
             cycle=2012,
         )
     )
     assert len(results) == 1
     assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 75})
Example #6
0
 def test_totals_full(self):
     results = self._results(
         api.url_for(
             TotalsCandidateView,
             candidate_id=self.candidate.candidate_id,
             cycle=2012,
             election_full='true',
         ))
     assert len(results) == 1
     assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 100})
Example #7
0
 def test_totals_full(self):
     results = self._results(
         api.url_for(
             TotalsCandidateView,
             candidate_id=self.candidate.candidate_id,
             cycle=2012,
             election_full='true',
         )
     )
     assert len(results) == 1
     assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 100})
Example #8
0
    def test_totals(self):
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate.candidate_id,
                cycle=2012,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 75})

        # candidate_zero
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_zero.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 0})

        # candidate_17_18
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_18.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 100})

        # candidate_17_only
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_only.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 150})

        # candidate_20
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_20.candidate_id,
                cycle=self.current_cycle,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'cycle': self.current_cycle,
            'receipts': 25000
        })
Example #9
0
 def test_search_incumbent(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2006,
             cand_office_st='NJ',
             cand_office_district='00',
             cand_id='S012345',
             cand_name='Howard Stackhouse',
         )
     ]
     results = self._results(api.url_for(ElectionList, office='senate', state='NJ'))
     assert len(results) == 1
     assert_dicts_subset(results[0], {'incumbent_id': 'S012345', 'incumbent_name': 'Howard Stackhouse'})
Example #10
0
 def test_elections(self):
     results = self._results(api.url_for(ElectionView, office='senate', cycle=2012, state='NY'))
     self.assertEqual(len(results), 1)
     totals = [each for each in self.totals if each.cycle == 2012]
     expected = {
         'candidate_id': self.candidate.candidate_id,
         'candidate_name': self.candidate.name,
         'incumbent_challenge_full': self.candidate.incumbent_challenge_full,
         'party_full': self.candidate.party_full,
         'total_receipts': sum(each.receipts for each in totals),
         'total_disbursements': sum(each.disbursements for each in totals),
         'cash_on_hand_end_period': sum(each.last_cash_on_hand_end_period for each in totals),
         'won': False,
     }
     assert_dicts_subset(results[0], expected)
     assert set(each.committee_id for each in self.committees) == set(results[0]['committee_ids'])
Example #11
0
 def test_search_incumbent(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2006,
             cand_office_st='NJ',
             cand_office_district='00',
             cand_id='S012345',
             cand_name='Howard Stackhouse',
         )
     ]
     results = self._results(
         api.url_for(ElectionList, office='senate', state='NJ'))
     assert len(results) == 1
     assert_dicts_subset(results[0], {
         'incumbent_id': 'S012345',
         'incumbent_name': 'Howard Stackhouse'
     })
Example #12
0
 def test_elections_winner(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2012,
             cand_office_st='NY',
             cand_id=self.candidate.candidate_id,
             cand_name=self.candidate.name,
         )
     ]
     results = self._results(api.url_for(ElectionView, office='senate', cycle=2012, state='NY'))
     self.assertEqual(len(results), 1)
     expected = {
         'candidate_id': self.candidate.candidate_id,
         'candidate_name': self.candidate.name,
         'won': True,
     }
     assert_dicts_subset(results[0], expected)
Example #13
0
    def test_electionview_excludes_jfc(self):
        self.candidate_committee_links[0].committee_designation = 'J'
        self.committees[0].designation = 'J'

        results = self._results(
            api.url_for(
                ElectionView,
                office='senate',
                cycle=2012,
                state='NY',
                election_full='true',
            ))
        # Joint Fundraising Committees raise money for multiple
        # candidate committees and transfer that money to those committees.
        # By limiting the committee designations to A and P
        # you eliminate J (joint) and thus do not inflate
        # the candidate's money by including it twice and
        # by including money that was raised and transferred
        # to the other committees in the joint fundraiser.
        totals_without_jfc = self.totals[1:]
        cash_on_hand_without_jfc = self.totals[1:2]
        expected = {
            'candidate_id':
            self.candidate.candidate_id,
            'candidate_name':
            self.candidate.name,
            'incumbent_challenge_full':
            self.candidate.incumbent_challenge_full,
            'party_full':
            self.candidate.party_full,
            'total_receipts':
            sum(each.receipts for each in totals_without_jfc),
            'total_disbursements':
            sum(each.disbursements for each in totals_without_jfc),
            'cash_on_hand_end_period':
            sum(each.last_cash_on_hand_end_period
                for each in cash_on_hand_without_jfc),
        }
        assert len(results) == 1
        assert_dicts_subset(results[0], expected)
        assert set(results[0]['committee_ids']) == set(
            each.committee_id for each in self.committees
            if each.designation != 'J')
Example #14
0
 def test_elections_winner(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2012,
             cand_office_st='NY',
             cand_id=self.candidate.candidate_id,
             cand_name=self.candidate.name,
         )
     ]
     results = self._results(
         api.url_for(ElectionView, office='senate', cycle=2012, state='NY'))
     self.assertEqual(len(results), 1)
     expected = {
         'candidate_id': self.candidate.candidate_id,
         'candidate_name': self.candidate.name,
         'won': True,
     }
     assert_dicts_subset(results[0], expected)
Example #15
0
    def test_candidate_totals_by_office_by_party(self):
        results = self._results(api.url_for(AggregateByOfficeByPartyView, ))
        assert len(results) == 6

        results = self._results(
            api.url_for(AggregateByOfficeByPartyView, office='S'))
        assert len(results) == 2
        assert_dicts_subset(
            results[0],
            {
                'election_year': 2016,
                'party': 'DEM',
                'total_receipts': 100,
                'total_disbursements': 100,
            },
        )
        assert_dicts_subset(
            results[1],
            {
                'election_year': 2016,
                'party': 'REP',
                'total_receipts': 10000,
                'total_disbursements': 10000,
            },
        )

        results = self._results(
            api.url_for(
                AggregateByOfficeByPartyView,
                office='H',
                is_active_candidate=True,
            ))
        assert len(results) == 2
        assert_dicts_subset(
            results[0],
            {
                'election_year': 2016,
                'party': 'Other',
                'total_receipts': 300,
                'total_disbursements': 300,
            },
        )
        assert_dicts_subset(
            results[1],
            {
                'election_year': 2016,
                'party': 'REP',
                'total_receipts': 200,
                'total_disbursements': 200,
            },
        )
Example #16
0
    def test_search_incumbent(self):

        [
            factories.ElectionResultFactory(
                cand_office='S',
                election_yr=2006,
                cand_office_st='GA',
                cand_office_district='00',
                cand_id='SGA123',
                cand_name='George P. Burdell',
                election_type='G',
                fec_election_yr=2006,
            )
        ]
        results = self._results(
            api.url_for(ElectionList, office='senate', state='GA'))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'incumbent_id': 'SGA123',
            'incumbent_name': 'George P. Burdell'
        })
Example #17
0
    def test_candidate_totals_by_office(self):
        results = self._results(api.url_for(AggregateByOfficeView, ))
        assert len(results) == 2

        results = self._results(api.url_for(AggregateByOfficeView, office='S'))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'election_year': 2016,
            'total_receipts': 5121
        })

        results = self._results(
            api.url_for(
                AggregateByOfficeView,
                office='S',
                is_active_candidate=True,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'election_year': 2016,
            'total_receipts': 121
        })

        results = self._results(
            api.url_for(
                AggregateByOfficeView,
                office='S',
                is_active_candidate=False,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'election_year': 2016,
            'total_receipts': 5000
        })
Example #18
0
    def test_search_zip(self):
        factories.ZipsDistrictsFactory(district='05',
                                       zip_code='22902',
                                       state_abbrevation='VA')

        results = self._results(api.url_for(ElectionsListView, zip='22902'))
        assert len(results) == 3
        assert_dicts_subset(results[0], {
            'cycle': 2012,
            'office': 'P',
            'state': 'US',
            'district': '00'
        })
        assert_dicts_subset(results[1], {
            'cycle': 2012,
            'office': 'S',
            'state': 'VA',
            'district': '00'
        })
        assert_dicts_subset(results[2], {
            'cycle': 2012,
            'office': 'H',
            'state': 'VA',
            'district': '05'
        })
Example #19
0
    def test_search_zip(self):
        factories.ZipsDistrictsFactory(district='05', zip_code='22902', state_abbrevation='VA')

        results = self._results(api.url_for(ElectionsListView, zip='22902'))
        assert len(results) == 3
        assert_dicts_subset(results[0], {'cycle': 2012, 'office': 'P', 'state': 'US', 'district': '00'})
        assert_dicts_subset(results[1], {'cycle': 2012, 'office': 'S', 'state': 'VA', 'district': '00'})
        assert_dicts_subset(results[2], {'cycle': 2012, 'office': 'H', 'state': 'VA', 'district': '05'})
Example #20
0
 def test_search_zip(self):
     results = self._results(api.url_for(ElectionList, zip='22902'))
     assert len(results) == 3
     assert_dicts_subset(results[0], {
         'cycle': 2012,
         'office': 'P',
         'state': 'US',
         'district': '00'
     })
     assert_dicts_subset(results[1], {
         'cycle': 2012,
         'office': 'S',
         'state': 'VA',
         'district': '00'
     })
     assert_dicts_subset(results[2], {
         'cycle': 2012,
         'office': 'H',
         'state': 'VA',
         'district': '05'
     })
Example #21
0
 def test_search_district(self):
     results = self._results(
         api.url_for(ElectionsListView, state='NJ', district='09'))
     self.assertEqual(len(results), 3)
     assert_dicts_subset(results[0], {
         'cycle': 2012,
         'office': 'P',
         'state': 'US',
         'district': '00'
     })
     assert_dicts_subset(results[1], {
         'cycle': 2012,
         'office': 'S',
         'state': 'NJ',
         'district': '00'
     })
     assert_dicts_subset(results[2], {
         'cycle': 2012,
         'office': 'H',
         'state': 'NJ',
         'district': '09'
     })
Example #22
0
    def test_totals(self):
        # 2-year totals
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate.candidate_id,
                cycle=2012,
                election_full=False,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 75})

        # Full-cycle totals (default is true)
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate.candidate_id,
                cycle=2012,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2012, 'receipts': 100})

        # candidate_zero
        # by default, load all candidates, current candidate should return
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_zero.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 0})

        # active candidate test: loading active candidates result nothing
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_zero.candidate_id,
                cycle=2018,
                is_active_candidate=True,
            ))
        assert len(results) == 0

        # active candidate test: loading inactive candidates result current one
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_zero.candidate_id,
                cycle=2018,
                is_active_candidate=False,
                election_full=False,
            ))
        assert len(results) == 1

        # candidate_17_18
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_18.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 100})

        # active candidats tst2: load inactive candidates result nothing
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_18.candidate_id,
                cycle=2018,
                is_active_candidate=False,
            ))
        assert len(results) == 0

        # active candidats tst3: load active candidates only
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_18.candidate_id,
                cycle=2018,
                is_active_candidate=True,
            ))
        assert len(results) == 1

        # candidate_17_only
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_17_only.candidate_id,
                cycle=2018,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {'cycle': 2018, 'receipts': 150})

        # candidate_20
        results = self._results(
            api.url_for(
                TotalsCandidateView,
                candidate_id=self.candidate_20.candidate_id,
                cycle=self.current_cycle,
                election_full=False,
            ))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'cycle': self.current_cycle,
            'receipts': 25000
        })
Example #23
0
 def test_search_district(self):
     results = self._results(api.url_for(ElectionList, state='NJ', district='09'))
     self.assertEqual(len(results), 3)
     assert_dicts_subset(results[0], {'cycle': 2012, 'office': 'P', 'state': 'US', 'district': '00'})
     assert_dicts_subset(results[1], {'cycle': 2012, 'office': 'S', 'state': 'NJ', 'district': '00'})
     assert_dicts_subset(results[2], {'cycle': 2012, 'office': 'H', 'state': 'NJ', 'district': '09'})
Example #24
0
 def test_search_zip(self):
     results = self._results(api.url_for(ElectionList, zip='22902'))
     assert len(results) == 3
     assert_dicts_subset(results[0], {'cycle': 2012, 'office': 'P', 'state': 'US', 'district': '00'})
     assert_dicts_subset(results[1], {'cycle': 2012, 'office': 'S', 'state': 'VA', 'district': '00'})
     assert_dicts_subset(results[2], {'cycle': 2012, 'office': 'H', 'state': 'VA', 'district': '05'})