Ejemplo n.º 1
0
    def test_candidate(self):
        """Compare results to expected fields."""
        candidate_old = factories.CandidateDetailFactory(
            load_date=datetime.datetime(2014, 1, 2), **fields)
        candidate = factories.CandidateDetailFactory(
            load_date=datetime.datetime(2014, 1, 3), **fields)
        response = self._response(
            api.url_for(CandidateView, candidate_id=candidate.candidate_id))
        self.assertResultsEqual(response['pagination'], {
            'count': 1,
            'page': 1,
            'pages': 1,
            'per_page': 20
        })
        # we are showing the full history rather than one result
        self.assertEqual(len(response['results']), 1)

        result = response['results'][0]
        self.assertEqual(result['candidate_id'], candidate.candidate_id)
        self.assertEqual(result['form_type'], 'F2')
        # @todo - check for a value for expire_data
        self.assertEqual(result['expire_date'], None)
        # # most recent record should be first
        self.assertEqual(result['load_date'], isoformat(candidate.load_date))
        self.assertNotEqual(result['load_date'],
                            isoformat(candidate_old.load_date))
        self.assertResultsEqual(result['name'], candidate.name)
        # #address
        self.assertEqual(result['address_city'], candidate.address_city)
        self.assertEqual(result['address_state'], candidate.address_state)
        self.assertEqual(result['address_street_1'],
                         candidate.address_street_1)
        self.assertEqual(result['address_zip'], candidate.address_zip)
        # # office
        self.assertResultsEqual(result['office'], candidate.office)
        self.assertResultsEqual(result['district'], candidate.district)
        self.assertResultsEqual(result['state'], candidate.state)
        self.assertResultsEqual(result['office_full'], candidate.office_full)
        # # From party_mapping
        self.assertResultsEqual(result['party'], candidate.party)
        self.assertResultsEqual(result['party_full'], candidate.party_full)
        # From status_mapping
        self.assertResultsEqual(result['active_through'],
                                candidate.active_through)
        self.assertResultsEqual(result['candidate_inactive'],
                                candidate.candidate_inactive)
        self.assertResultsEqual(result['candidate_status'],
                                candidate.candidate_status)
        self.assertResultsEqual(result['incumbent_challenge'],
                                candidate.incumbent_challenge)
        self.assertResultsEqual(result['candidate_status_full'],
                                candidate.candidate_status_full)
    def test_candidate(self):
        """Compare results to expected fields."""
        candidate = factories.CandidateDetailFactory(**fields)
        response = self._response(
            api.url_for(CandidateView, candidate_id=candidate.candidate_id)
        )
        assert response['pagination'] == {'count': 1, 'page': 1, 'pages': 1, 'per_page': 20}
        # we are showing the full history rather than one result
        assert len(response['results']) == 1

        result = response['results'][0]
        assert result['candidate_id'] == candidate.candidate_id
        # # most recent record should be first
        assert result['name'] == candidate.name
        # #address
        assert result['address_city'] == candidate.address_city
        assert result['address_state'] == candidate.address_state
        assert result['address_street_1'] == candidate.address_street_1
        assert result['address_zip'] == candidate.address_zip
        # # office
        assert result['office'] == candidate.office
        assert result['district'] == candidate.district
        assert result['state'] == candidate.state
        assert result['office_full'] == candidate.office_full
        # # From party_mapping
        assert result['party'] == candidate.party
        assert result['party_full'] == candidate.party_full
        # From status_mapping
        assert result['active_through'] == candidate.active_through
        assert result['candidate_inactive'] == candidate.candidate_inactive
        assert result['candidate_status'] == candidate.candidate_status
        assert result['incumbent_challenge'] == candidate.incumbent_challenge
Ejemplo n.º 3
0
 def test_fields(self):
     candidate = factories.CandidateDetailFactory()
     response = self._results(
         api.url_for(CandidateView, candidate_id=candidate.candidate_id))
     assert response[0].keys() == schemas.CandidateDetailSchema(
     ).fields.keys()
     response = response[0]
Ejemplo n.º 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
Ejemplo n.º 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,
     )
Ejemplo n.º 6
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,
     )
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def test_extra_fields(self):
     candidate = factories.CandidateDetailFactory(
         address_street_1='PO Box 8102', address_zip='60680',
     )
     response = self._results(
         api.url_for(CandidateView, candidate_id=candidate.candidate_id)
     )
     response = response[0]
     self.assertIn(candidate.address_street_1, response['address_street_1'])
     self.assertIn(candidate.address_zip, response['address_zip'])
Ejemplo n.º 9
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
Ejemplo n.º 10
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,
         ),
     ]
Ejemplo n.º 11
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,
         ),
     ]
Ejemplo n.º 12
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,
     )
Ejemplo n.º 13
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,
     )
Ejemplo n.º 14
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,
            ),
        ]
Ejemplo n.º 15
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,
        )
Ejemplo n.º 16
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()
Ejemplo n.º 17
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,
            ),
        ]
Ejemplo n.º 18
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,
         ),
     ]
Ejemplo n.º 19
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,
            ),
        ]
Ejemplo n.º 20
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,
     )