コード例 #1
0
ファイル: test_utils.py プロジェクト: profjefer/openFEC
    def test_hide_null_election(self):
        candidates = [
            factories.CandidateFactory(candidate_id='C1234'),
            factories.CandidateFactory(candidate_id='C5678'),
        ]
        cmteFacorty = [
            factories.CommitteeDetailFactory(committee_id='H1234'),
            factories.CommitteeDetailFactory(committee_id='H5678')
        ]
        db.session.flush()
        candidateHistory = [
            factories.CandidateHistoryFactory(candidate_id='C1234', two_year_period=2016, state='MO',
                                              candidate_election_year=2016, candidate_inactive=False, district='01',
                                              office='S', election_years=[2016], cycles=[2016]),
            factories.CandidateHistoryFactory(candidate_id='C5678',  candidate_election_year=2016,
                                              two_year_period=2016, state='MO', election_years=[2016], cycles=[2016],
                                              candidate_inactive=False, district='02', office='S')
        ]
        candidateCmteLinks = [
            factories.CandidateCommitteeLinkFactory(committee_id='H1234', candidate_id='C1234', fec_election_year=2016,committee_designation='P'),
            factories.CandidateCommitteeLinkFactory(committee_id='H5678', candidate_id='C5678', fec_election_year=2016,
                                                    committee_designation='P')

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

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

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

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

        #print(str(query.statement.compile(dialect=postgresql.dialect())))
        self.assertEqual(len(query.all()), len(candidates))
        query, columns = sorting.sort(electionView._get_records(arg_map), 'total_disbursements', model=None, hide_null=True)
        #Taking this assert statement out because I believe, at least how the FEC interprets null (i.e. none) primary
        #committees for a candidate is that they have in fact raised/spent 0.0 dollars, this can be shown as true
        #using the Alabama special election as an example
        #self.assertEqual(len(query.all()), len(candidates) - 1)
        self.assertTrue(candidates[1].candidate_id in query.all()[0])
        self.assertEqual(query.all()[0].total_disbursements, 0.0)
コード例 #2
0
ファイル: test_elections.py プロジェクト: yjoshuaz/openFEC
 def test_search_incumbent(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2006,
             cand_office_st='NJ',
             cand_office_district='00',
             cand_id='S012345',
             cand_name='Howard Stackhouse',
         )
     ]
     results = self._results(
         api.url_for(ElectionList, office='senate', state='NJ'))
     assert len(results) == 1
     assert_dicts_subset(results[0], {
         'incumbent_id': 'S012345',
         'incumbent_name': 'Howard Stackhouse'
     })
コード例 #3
0
 def test_elections_winner(self):
     [
         factories.ElectionResultFactory(
             cand_office='S',
             election_yr=2012,
             cand_office_st='NY',
             cand_id=self.candidate.candidate_id,
             cand_name=self.candidate.name,
         )
     ]
     results = self._results(
         api.url_for(ElectionView, office='senate', cycle=2012, state='NY'))
     self.assertEqual(len(results), 1)
     expected = {
         'candidate_id': self.candidate.candidate_id,
         'candidate_name': self.candidate.name,
         'won': True,
     }
     assert_dicts_subset(results[0], expected)
コード例 #4
0
ファイル: test_elections.py プロジェクト: jwchumley/openFEC
    def test_search_incumbent(self):

        [
            factories.ElectionResultFactory(
                cand_office='S',
                election_yr=2006,
                cand_office_st='GA',
                cand_office_district='00',
                cand_id='SGA123',
                cand_name='George P. Burdell',
                election_type='G',
                fec_election_yr=2006,
            )
        ]
        results = self._results(
            api.url_for(ElectionList, office='senate', state='GA'))
        assert len(results) == 1
        assert_dicts_subset(results[0], {
            'incumbent_id': 'SGA123',
            'incumbent_name': 'George P. Burdell'
        })
コード例 #5
0
    def test_hide_null_election(self):
        candidates = [
            factories.CandidateFactory(candidate_id='C1234'),
            factories.CandidateFactory(candidate_id='C5678'),
        ]
        cmteFacorty = [
            factories.CommitteeDetailFactory(committee_id='H1234'),
            factories.CommitteeDetailFactory(committee_id='H5678')
        ]
        db.session.flush()
        candidateHistory = [
            factories.CandidateHistoryFactory(candidate_id='C1234',
                                              two_year_period=2016,
                                              state='MO',
                                              candidate_inactive=False,
                                              district='01',
                                              office='S',
                                              election_years=[2016],
                                              cycles=[2016]),
            factories.CandidateHistoryFactory(candidate_id='C5678',
                                              two_year_period=2016,
                                              state='MO',
                                              election_years=[2016],
                                              cycles=[2016],
                                              candidate_inactive=False,
                                              district='02',
                                              office='S')
        ]
        candidateCmteLinks = [
            factories.CandidateCommitteeLinkFactory(committee_id='H1234',
                                                    candidate_id='C1234',
                                                    fec_election_year=2016,
                                                    committee_designation='P'),
            factories.CandidateCommitteeLinkFactory(committee_id='H5678',
                                                    candidate_id='C5678',
                                                    fec_election_year=2016,
                                                    committee_designation='P')
        ]
        cmteTotalsFactory = [
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H1234',
                                                        cycle=2016),
            factories.CommitteeTotalsHouseSenateFactory(
                committee_id='H1234', cycle=2016, disbursements='9999.99'),
            factories.CommitteeTotalsHouseSenateFactory(committee_id='H5678',
                                                        cycle=2016)
        ]
        electionResults = [
            factories.ElectionResultFactory(cand_id='C1234',
                                            election_yr=2016,
                                            cand_office='S',
                                            cand_office_st='MO',
                                            cand_office_district='01'),
            factories.ElectionResultFactory(cand_id='C5678',
                                            election_yr=2016,
                                            cand_office='S',
                                            cand_office_st='MO',
                                            cand_office_district='02')
        ]
        db.session.flush()
        arg_map = {}
        arg_map['office'] = 'senate'
        arg_map['cycle'] = 2016
        arg_map['state'] = 'MO'
        #arg_map['district'] = '00'

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

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

        self.assertTrue(candidates[0].candidate_id in query.all()[0])