Example #1
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateHistoryFactory(
         two_year_period=2012)
     self.committees = [
         factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
         factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
     ]
     factories.CandidateDetailFactory(
         candidate_key=self.candidate.candidate_key)
     [
         factories.CommitteeDetailFactory(committee_key=each.committee_key)
         for each in self.committees
     ]
     db.session.flush()
     factories.CandidateCommitteeLinkFactory(
         candidate_key=self.candidate.candidate_key,
         committee_key=self.committees[0].committee_key,
         election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_key=self.candidate.candidate_key,
         committee_key=self.committees[1].committee_key,
         election_year=2012,
     )
Example #2
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateDetailFactory()
     self.committees = [factories.CommitteeDetailFactory() for _ in range(2)]
     self.histories = [
         factories.CommitteeHistoryFactory(committee_id=self.committees[0].committee_id, cycle=2010),
         factories.CommitteeHistoryFactory(committee_id=self.committees[1].committee_id, cycle=2012),
     ]
     db.session.flush()
     self.links = [
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[0].committee_id,
             fec_election_year=2010,
             committee_type='P',
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidate.candidate_id,
             committee_id=self.committees[1].committee_id,
             fec_election_year=2012,
             committee_type='P',
         ),
     ]
     self.election = factories.CandidateElectionFactory(
         candidate_id=self.candidate.candidate_id,
         cand_election_year=2012,
     )
Example #3
0
    def test_hide_null_election(self):
        candidates = [
            factories.CandidateFactory(candidate_id='C1234'),
            factories.CandidateFactory(candidate_id='C5678'),
        ]
        cmteFacorty = [
            factories.CommitteeDetailFactory(committee_id='H1234'),
            factories.CommitteeDetailFactory(committee_id='H5678')
        ]
        db.session.flush()
        candidateHistory = [
            factories.CandidateHistoryFactory(candidate_id='C1234', two_year_period=2016, state='MO',
                                              candidate_election_year=2016, candidate_inactive=False, district='01',
                                              office='S', election_years=[2016], cycles=[2016]),
            factories.CandidateHistoryFactory(candidate_id='C5678',  candidate_election_year=2016,
                                              two_year_period=2016, state='MO', election_years=[2016], cycles=[2016],
                                              candidate_inactive=False, district='02', office='S')
        ]
        candidateCmteLinks = [
            factories.CandidateCommitteeLinkFactory(committee_id='H1234', candidate_id='C1234', fec_election_year=2016,committee_designation='P'),
            factories.CandidateCommitteeLinkFactory(committee_id='H5678', candidate_id='C5678', fec_election_year=2016,
                                                    committee_designation='P')

        ]
        cmteTotalsFactory = [
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H1234', cycle=2016),
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H1234', cycle=2016, disbursements='9999.99'),
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H5678', cycle=2016)

        ]
        electionResults = [
            factories.ElectionResultFactory(cand_id='C1234', election_yr=2016, cand_office='S', cand_office_st='MO', cand_office_district='01' ),
            factories.ElectionResultFactory(cand_id='C5678', election_yr=2016, cand_office='S', cand_office_st='MO',
                                            cand_office_district='02')

        ]
        db.session.flush()
        arg_map = {}
        arg_map['office'] = 'senate'
        arg_map['cycle'] = 2016
        arg_map['state'] = 'MO'
        #arg_map['district'] = '00'

        electionView = elections.ElectionView()
        query, columns = sorting.sort(electionView._get_records(arg_map), 'total_disbursements', model=None)

        #print(str(query.statement.compile(dialect=postgresql.dialect())))
        self.assertEqual(len(query.all()), len(candidates))
        query, columns = sorting.sort(electionView._get_records(arg_map), 'total_disbursements', model=None, hide_null=True)
        #Taking this assert statement out because I believe, at least how the FEC interprets null (i.e. none) primary
        #committees for a candidate is that they have in fact raised/spent 0.0 dollars, this can be shown as true
        #using the Alabama special election as an example
        #self.assertEqual(len(query.all()), len(candidates) - 1)
        self.assertTrue(candidates[1].candidate_id in query.all()[0])
        self.assertEqual(query.all()[0].total_disbursements, 0.0)
Example #4
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateHistoryFactory(
         state='NY',
         district='07',
         two_year_period=2012,
         election_years=[2010, 2012],
         office='H',
     )
     self.committees = [
         factories.CommitteeHistoryFactory(cycle=2012, designation='P'),
         factories.CommitteeHistoryFactory(cycle=2012, designation='A'),
     ]
     factories.CandidateDetailFactory(
         candidate_key=self.candidate.candidate_key)
     [
         factories.CommitteeDetailFactory(committee_key=each.committee_key)
         for each in self.committees
     ]
     db.session.flush()
     factories.CandidateCommitteeLinkFactory(
         candidate_key=self.candidate.candidate_key,
         committee_key=self.committees[0].committee_key,
         election_year=2012,
     )
     factories.CandidateCommitteeLinkFactory(
         candidate_key=self.candidate.candidate_key,
         committee_key=self.committees[1].committee_key,
         election_year=2011,
     )
     self.totals = [
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[0].committee_id,
             coverage_end_date=datetime.datetime(2012, 9, 30),
             last_beginning_image_number=123,
             last_report_type_full='Quarter Three',
             last_cash_on_hand_end_period=1979,
             last_report_year=2012,
             cycle=2012,
         ),
         factories.TotalsHouseSenateFactory(
             receipts=50,
             disbursements=75,
             committee_id=self.committees[1].committee_id,
             coverage_end_date=datetime.datetime(2012, 12, 31),
             last_beginning_image_number=456,
             last_report_type_full='Quarter Three',
             last_cash_on_hand_end_period=1979,
             last_report_year=2012,
             cycle=2012,
         ),
     ]
Example #5
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.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
     ]
     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,
     )
Example #6
0
    def test_election_full(self):
        # When election_full=true, return all two_year_periods with that candidate_election_year
        candidate = factories.CandidateDetailFactory(candidate_id='H001')
        first_two_year_period = factories.CandidateHistoryFactory(
            candidate_id=candidate.candidate_id,
            two_year_period=2018,
            candidate_election_year=2020,
        )
        second_two_year_period = factories.CandidateHistoryFactory(
            candidate_id=candidate.candidate_id,
            two_year_period=2020,
            candidate_election_year=2020,
        )
        db.session.flush()
        # Link
        factories.CandidateCommitteeLinkFactory(
            candidate_id=candidate.candidate_id,
            fec_election_year=2018,
            committee_type='H',
            election_yr_to_be_included=2020,
        )

        # test election_full='false'
        results_false = self._results(
            api.url_for(
                CandidateHistoryView,
                candidate_id=candidate.candidate_id,
                cycle=2018,
                election_full='false',
            ))
        assert len(results_false) == 1
        assert results_false[0][
            'candidate_id'] == first_two_year_period.candidate_id
        assert results_false[0][
            'two_year_period'] == first_two_year_period.two_year_period
        assert results_false[0][
            'candidate_election_year'] == first_two_year_period.candidate_election_year

        # test election_full='true'
        results_true = self._results(
            api.url_for(
                CandidateHistoryView,
                candidate_id=candidate.candidate_id,
                cycle=2020,
                election_full='true',
            ))
        assert len(results_true) == 2
        assert results_true[0][
            'candidate_id'] == second_two_year_period.candidate_id
        assert results_true[0][
            'two_year_period'] == second_two_year_period.two_year_period
        assert results_true[0][
            'candidate_election_year'] == second_two_year_period.candidate_election_year
        # Default sort is two_year_period descending
        assert results_true[1][
            'candidate_id'] == first_two_year_period.candidate_id
        assert results_true[1][
            'two_year_period'] == first_two_year_period.two_year_period
        assert results_true[1][
            'candidate_election_year'] == first_two_year_period.candidate_election_year
Example #7
0
 def test_house_cand_history_between_cycles(self):
     # Committee
     factories.CommitteeDetailFactory()
     candidate = factories.CandidateDetailFactory(candidate_id='H001')
     history = factories.CandidateHistoryFactory(
         candidate_id=candidate.candidate_id,
         two_year_period=2018,
         candidate_election_year=2020,
     )
     db.session.flush()
     # Link
     factories.CandidateCommitteeLinkFactory(
         candidate_id=candidate.candidate_id,
         fec_election_year=2018,
         committee_type='H',
     )
     factories.CandidateElectionFactory(
         candidate_id=candidate.candidate_id,
         cand_election_year=2020,
         prev_election_year=2018,
     )
     # Make sure future house candidate returns results
     results = self._results(
         api.url_for(
             CandidateHistoryView,
             candidate_id=candidate.candidate_id,
             cycle=2020,
             # election_full='false' is strictly 2-year period
             election_full='true',
         ))
     assert len(results) == 1
     assert results[0]['candidate_id'] == history.candidate_id
     assert results[0]['two_year_period'] == history.two_year_period
     assert results[0][
         'candidate_election_year'] == history.candidate_election_year
Example #8
0
 def test_committees_by_candidate_count(self):
     committee = factories.CommitteeFactory()
     candidate = factories.CandidateFactory()
     db.session.flush()
     [
         factories.CandidateCommitteeLinkFactory(
             candidate_id=candidate.candidate_id,
             committee_id=committee.committee_id,
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=candidate.candidate_id,
             committee_id=committee.committee_id,
         ),
     ]
     response = self._response(api.url_for(CommitteeView, candidate_id=candidate.candidate_id))
     self.assertEqual(response['pagination']['count'], 1)
     self.assertEqual(len(response['results']), 1)
Example #9
0
 def test_candidates_by_com(self):
     committee = factories.CommitteeFactory()
     candidate = factories.CandidateFactory()
     db.session.flush()
     factories.CandidateCommitteeLinkFactory(
         candidate_id=candidate.candidate_id,
         committee_id=committee.committee_id,
     )
     results = self._results(api.url_for(CandidateView, committee_id=committee.committee_id))
     self.assertEquals(1, len(results))
Example #10
0
    def test_case_insensitivity(self):
        lower_candidate = factories.CandidateDetailFactory(candidate_id="H01")
        lower_committee_1 = factories.CommitteeDetailFactory(committee_id="ID01")
        [
            factories.CommitteeHistoryFactory(
                committee_id=lower_committee_1.committee_id,
                cycle=2014,
                designation='J',
                is_active=False,
            ),
        ]
        db.session.flush()
        [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=lower_candidate.candidate_id,
                committee_id=lower_committee_1.committee_id,
                fec_election_year=2014,
                committee_type='P',
                committee_designation='J',
            ),
        ]
        [
            factories.CandidateElectionFactory(
                candidate_id=lower_candidate.candidate_id,
                cand_election_year=2012,
                prev_election_year=2008,
            ),
            factories.CandidateElectionFactory(
                candidate_id=lower_candidate.candidate_id,
                cand_election_year=2016,
                prev_election_year=2012,
            ),
        ]

        results = self._results(
            api.url_for(
                CommitteeHistoryView,
                committee_id="id01",
                cycle=2014,
                election_full=False,
                is_active=False,
            )
        )
        assert len(results) == 1

        results = self._results(
            api.url_for(
                CommitteeHistoryView,
                candidate_id="h01",
                cycle=2014,
                election_full=False,
                is_active=False,
            )
        )
        assert len(results) == 1
Example #11
0
 def setUp(self):
     super().setUp()
     self.committee = factories.CommitteeDetailFactory()
     self.candidates = [
         factories.CandidateDetailFactory(candidate_id='P001'),
         factories.CandidateDetailFactory(candidate_id='P002'),
     ]
     self.histories = [
         factories.CandidateHistoryFactory(
             candidate_id=self.candidates[0].candidate_id,
             two_year_period=2010),
         factories.CandidateHistoryFactory(
             candidate_id=self.candidates[1].candidate_id,
             two_year_period=2012),
     ]
     db.session.flush()
     self.links = [
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidates[0].candidate_id,
             committee_id=self.committee.committee_id,
             fec_election_year=2010,
             committee_type='P',
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_id=self.candidates[1].candidate_id,
             committee_id=self.committee.committee_id,
             fec_election_year=2012,
             committee_type='P',
         ),
     ]
     self.elections = [
         factories.CandidateElectionFactory(
             candidate_id=self.candidates[0].candidate_id,
             cand_election_year=2012,
             prev_election_year=2008,
         ),
         factories.CandidateElectionFactory(
             candidate_id=self.candidates[1].candidate_id,
             cand_election_year=2012,
             prev_election_year=2008,
         ),
     ]
Example #12
0
 def test_committee_by_cand_filter(self):
     committee = factories.CommitteeFactory(designation='P')
     candidate = factories.CandidateFactory()
     db.session.flush()
     factories.CandidateCommitteeLinkFactory(
         candidate_id=candidate.candidate_id,
         committee_id=committee.committee_id,
     )
     results = self._results(
         api.url_for(CommitteeView, candidate_id=candidate.candidate_id, designation='P')
     )
     self.assertEqual(1, len(results))
Example #13
0
 def test_candidates_search(self):
     principal_committee = factories.CommitteeFactory(designation='P')
     joint_committee = factories.CommitteeFactory(designation='J')
     candidate = factories.CandidateFactory()
     db.session.flush()
     [
         factories.CandidateCommitteeLinkFactory(
             candidate_key=candidate.candidate_key,
             committee_key=principal_committee.committee_key,
         ),
         factories.CandidateCommitteeLinkFactory(
             candidate_key=candidate.candidate_key,
             committee_key=joint_committee.committee_key,
         ),
     ]
     results = self._results(api.url_for(CandidateSearch))
     self.assertEqual(len(results), 1)
     self.assertIn('principal_committees', results[0])
     self.assertEqual(len(results[0]['principal_committees']), 1)
     self.assertEqual(
         results[0]['principal_committees'][0]['committee_id'],
         principal_committee.committee_id,
     )
Example #14
0
    def test_committees_by_cand_id(self):
        committees = [factories.CommitteeFactory() for _ in range(3)]
        candidate = factories.CandidateFactory()
        db.session.flush()
        [
            factories.CandidateCommitteeLinkFactory(
                candidate_id=candidate.candidate_id,
                committee_id=committee.committee_id,
            )
            for committee in committees
        ]
        results = self._results(api.url_for(CommitteeView, candidate_id=candidate.candidate_id))

        self.assertEqual(
            set((each['committee_id'] for each in results)),
            set((each.committee_id for each in committees)),
        )
Example #15
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,
            ),
        ]
Example #16
0
 def setUp(self):
     super().setUp()
     self.candidate = factories.CandidateHistoryFactory(
         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.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,
     )
     # Create a candidate_zero without a committee and $0 in CandidateTotal
     self.candidate_zero = factories.CandidateHistoryFactory(
         candidate_id='H321',
         two_year_period=2018,
         candidate_election_year=2018,
     )
     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,
     )
Example #17
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,
        )
Example #18
0
    def test_hide_null_election(self):
        candidates = [
            factories.CandidateFactory(candidate_id='C1234'),
            factories.CandidateFactory(candidate_id='C5678'),
        ]
        cmteFacorty = [
            factories.CommitteeDetailFactory(committee_id='H1234'),
            factories.CommitteeDetailFactory(committee_id='H5678')
        ]
        db.session.flush()
        candidateHistory = [
            factories.CandidateHistoryFactory(candidate_id='C1234',
                                              two_year_period=2016,
                                              state='MO',
                                              candidate_inactive=False,
                                              district='01',
                                              office='S',
                                              election_years=[2016],
                                              cycles=[2016]),
            factories.CandidateHistoryFactory(candidate_id='C5678',
                                              two_year_period=2016,
                                              state='MO',
                                              election_years=[2016],
                                              cycles=[2016],
                                              candidate_inactive=False,
                                              district='02',
                                              office='S')
        ]
        candidateCmteLinks = [
            factories.CandidateCommitteeLinkFactory(committee_id='H1234',
                                                    candidate_id='C1234',
                                                    fec_election_year=2016,
                                                    committee_designation='P'),
            factories.CandidateCommitteeLinkFactory(committee_id='H5678',
                                                    candidate_id='C5678',
                                                    fec_election_year=2016,
                                                    committee_designation='P')
        ]
        cmteTotalsFactory = [
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H1234',
                                                        cycle=2016),
            factories.CommitteeTotalsHouseSenateFactory(
                committee_id='H1234', cycle=2016, disbursements='9999.99'),
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H5678',
                                                        cycle=2016)
        ]
        electionResults = [
            factories.ElectionResultFactory(cand_id='C1234',
                                            election_yr=2016,
                                            cand_office='S',
                                            cand_office_st='MO',
                                            cand_office_district='01'),
            factories.ElectionResultFactory(cand_id='C5678',
                                            election_yr=2016,
                                            cand_office='S',
                                            cand_office_st='MO',
                                            cand_office_district='02')
        ]
        db.session.flush()
        arg_map = {}
        arg_map['office'] = 'senate'
        arg_map['cycle'] = 2016
        arg_map['state'] = 'MO'
        #arg_map['district'] = '00'

        electionView = elections.ElectionView()
        query, columns = sorting.sort(electionView._get_records(arg_map),
                                      'total_disbursements',
                                      model=None)

        #print(str(query.statement.compile(dialect=postgresql.dialect())))
        self.assertEqual(len(query.all()), len(candidates))
        query, columns = sorting.sort(electionView._get_records(arg_map),
                                      'total_disbursements',
                                      model=None,
                                      hide_null=True)
        self.assertEqual(len(query.all()), len(candidates) - 1)

        self.assertTrue(candidates[0].candidate_id in query.all()[0])
Example #19
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()
Example #20
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,
         ),
     ]
Example #21
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,
            ),
        ]
Example #22
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,
            ),
        ]