示例#1
0
    def test_hide_null_election(self):
        candidates = [
            factories.CandidateFactory(candidate_id='C1234'),
            factories.CandidateFactory(candidate_id='C5678'),
        ]
        cmteFacorty = [
            factories.CommitteeDetailFactory(committee_id='H1234'),
            factories.CommitteeDetailFactory(committee_id='H5678')
        ]
        db.session.flush()
        candidateHistory = [
            factories.CandidateHistoryFactory(candidate_id='C1234', two_year_period=2016, state='MO',
                                              candidate_election_year=2016, candidate_inactive=False, district='01',
                                              office='S', election_years=[2016], cycles=[2016]),
            factories.CandidateHistoryFactory(candidate_id='C5678',  candidate_election_year=2016,
                                              two_year_period=2016, state='MO', election_years=[2016], cycles=[2016],
                                              candidate_inactive=False, district='02', office='S')
        ]
        candidateCmteLinks = [
            factories.CandidateCommitteeLinkFactory(committee_id='H1234', candidate_id='C1234', fec_election_year=2016,committee_designation='P'),
            factories.CandidateCommitteeLinkFactory(committee_id='H5678', candidate_id='C5678', fec_election_year=2016,
                                                    committee_designation='P')

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

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

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

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

        #print(str(query.statement.compile(dialect=postgresql.dialect())))
        self.assertEqual(len(query.all()), len(candidates))
        query, columns = sorting.sort(electionView._get_records(arg_map), 'total_disbursements', model=None, hide_null=True)
        #Taking this assert statement out because I believe, at least how the FEC interprets null (i.e. none) primary
        #committees for a candidate is that they have in fact raised/spent 0.0 dollars, this can be shown as true
        #using the Alabama special election as an example
        #self.assertEqual(len(query.all()), len(candidates) - 1)
        self.assertTrue(candidates[1].candidate_id in query.all()[0])
        self.assertEqual(query.all()[0].total_disbursements, 0.0)
示例#2
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])