def test_sort_by_candidate_id(self):

        factories.CandidateHistoryFactory(
            candidate_id='S001',
            name='Robert Ritchie',
            two_year_period=2012,
            office='S',
            state='NY',
        )
        factories.CandidateHistoryFactory(
            candidate_id='S002',
            name='FARLEY Ritchie',
            two_year_period=2012,
            office='S',
            state='NY',
        )
        factories.CandidateHistoryFactory(
            candidate_id='S003',
            name='Robert Ritchie',
            election_years=[2012],
            two_year_period=2012,
            office='S',
            state='NY',
        )

        factories.CandidateElectionFactory(candidate_id='S001',
                                           cand_election_year=2012)
        factories.CandidateElectionFactory(candidate_id='S002',
                                           cand_election_year=2012)
        factories.CandidateElectionFactory(candidate_id='S003',
                                           cand_election_year=2012)

        factories.ElectioneeringByCandidateFactory(
            cycle=2012,
            candidate_id='S001',
            total=700,
            count=5,
        ),
        factories.ElectioneeringByCandidateFactory(
            cycle=2012,
            candidate_id='S002',
            total=500,
            count=3,
        ),
        factories.ElectioneeringByCandidateFactory(
            cycle=2012,
            candidate_id='S003',
            total=100,
            count=1,
        ),
        response = self._results(
            api.url_for(ElectioneeringByCandidateView,
                        sort='-candidate_id',
                        office='senate',
                        state='NY',
                        cycle=2012))
        self.assertEqual(len(response), 3)
        self.assertEqual(response[0]['candidate_id'], 'S003')
        self.assertEqual(response[1]['candidate_id'], 'S002')
        self.assertEqual(response[2]['candidate_id'], 'S001')
Beispiel #2
0
    def test_sort_by_committee_name(self):

        factories.CommitteeHistoryFactory(name='Warner for America',
                                          cycle=2010,
                                          committee_id='C005')
        factories.CommitteeHistoryFactory(name='Ritche for America',
                                          cycle=2010,
                                          committee_id='C006')

        factories.CandidateHistoryFactory(
            candidate_id='S005',
            name='WARNER, MARK',
            election_years=[2010],
            two_year_period=2010,
            office='S',
            state='NY',
        )
        factories.CandidateHistoryFactory(
            candidate_id='S006',
            name='BALDWIN, ALISSA',
            election_years=[2010],
            two_year_period=2010,
            office='S',
            state='NY',
        )

        factories.CandidateElectionFactory(candidate_id='S005',
                                           cand_election_year=2010)
        factories.CandidateElectionFactory(candidate_id='S006',
                                           cand_election_year=2010)

        factories.ScheduleEByCandidateFactory(
            total=50000,
            count=10,
            cycle=2010,
            candidate_id='S005',
            support_oppose_indicator='S',
            committee_id='C005',
        ),
        factories.ScheduleEByCandidateFactory(
            total=10000,
            count=5,
            cycle=2010,
            candidate_id='S005',
            support_oppose_indicator='S',
            committee_id='C006',
        ),

        response = self._results(
            api.url_for(ScheduleEByCandidateView,
                        sort='-committee_name',
                        office='senate',
                        cycle=2010,
                        state='NY'))
        self.assertEqual(len(response), 2)
        self.assertEqual(response[0]['committee_name'], 'Warner for America')
        self.assertEqual(response[1]['committee_name'], 'Ritche for America')
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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,
     )
Beispiel #6
0
    def test_sort_by_candidate_name_descending(self):

        factories.CandidateHistoryFactory(
            candidate_id='S005',
            name='WARNER, MARK',
            two_year_period=2010,
            office='S',
            state='NY',
        )
        factories.CandidateHistoryFactory(
            candidate_id='S006',
            name='BALDWIN, ALISSA',
            two_year_period=2010,
            office='S',
            state='NY',
        )

        factories.CandidateElectionFactory(candidate_id='S005',
                                           cand_election_year=2010)
        factories.CandidateElectionFactory(candidate_id='S006',
                                           cand_election_year=2010)

        factories.ScheduleEByCandidateFactory(
            total=50000,
            count=10,
            cycle=2010,
            candidate_id='S005',
            support_oppose_indicator='S',
        ),
        factories.ScheduleEByCandidateFactory(
            total=10000,
            count=5,
            cycle=2010,
            candidate_id='S006',
            support_oppose_indicator='S',
        ),

        response = self._results(
            api.url_for(ScheduleEByCandidateView,
                        cycle=2010,
                        office='senate',
                        state='NY',
                        sort='-candidate_name'))
        self.assertEqual(len(response), 2)
        self.assertEqual(response[0]['candidate_name'], 'WARNER, MARK')
        self.assertEqual(response[1]['candidate_name'], 'BALDWIN, ALISSA')
Beispiel #7
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,
         ),
     ]
Beispiel #8
0
 def test_fields(self):
     candidate_id = 'S001'
     support_oppose_indicator = 'S'
     factories.ScheduleEByCandidateFactory(
         candidate_id=candidate_id,
         support_oppose_indicator=support_oppose_indicator,
         cycle=2018)
     factories.CandidateElectionFactory(candidate_id=candidate_id,
                                        cand_election_year=2018)
     results = self._results(
         api.url_for(ScheduleEByCandidateView, candidate_id='S001'))
     assert len(results) == 1
     assert results[0].keys() == ScheduleEByCandidateSchema().fields.keys()
Beispiel #9
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,
     )
Beispiel #10
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,
     )
Beispiel #11
0
    def test_sched_e_filter_match(self):
        factories.CandidateElectionFactory(candidate_id='S002',
                                           cand_election_year=2014)
        factories.ScheduleEByCandidateFactory(
            total=50000,
            count=10,
            cycle=2008,
            candidate_id='S001',
            support_oppose_indicator='O',
        ),
        factories.ScheduleEByCandidateFactory(
            total=10000,
            count=5,
            cycle=2010,
            candidate_id='S002',
            support_oppose_indicator='O',
        ),

        results = self._results(
            api.url_for(ScheduleEByCandidateView,
                        candidate_id='S002',
                        cycle=2014,
                        support_oppose_indicator='S'))
        self.assertEqual(len(results), 1)
Beispiel #12
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,
            ),
        ]
Beispiel #13
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,
        )
Beispiel #14
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()
Beispiel #15
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,
            ),
        ]
Beispiel #16
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,
         ),
     ]
Beispiel #17
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,
     )
    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,
            ),
        ]