Ejemplo n.º 1
0
    def test_standardized_filename(self):
        # Test with bare minimum args
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'extension': ".csv",
        }
        expected = "20120403__md.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)

        # Test with more complicated example
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'party': "Republican",
            'race_type': "primary",
            'jurisdiction': "Prince George's",
            'reporting_level': 'precinct',
            'extension': ".csv",
        }
        expected = "20120403__md__republican__primary__prince_georges__precinct.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)

        # Test with suffix bits
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'extension': ".csv",
            'suffix_bits': ['raw']
        }
        expected = "20120403__md__raw.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)
Ejemplo n.º 2
0
    def test_standardized_filename(self):
        # Test with bare minimum args
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'extension': ".csv",
        }
        expected = "20120403__md.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)

        # Test with more complicated example
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'party': "Republican",
            'race_type': "primary",
            'jurisdiction': "Prince George's",
            'reporting_level': 'precinct',
            'extension': ".csv",
        }
        expected = "20120403__md__republican__primary__prince_georges__precinct.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)

        # Test with suffix bits
        kwargs = {
            'start_date': "2012-04-03",
            'state': 'md',
            'extension': ".csv",
            'suffix_bits': ['raw']
        }
        expected = "20120403__md__raw.csv"
        filename = standardized_filename(**kwargs)
        self.assertEqual(filename, expected)
Ejemplo n.º 3
0
    def _generatedOneStateLegElectionMetaData(self, elecVt, election,
                                              primaryParty, jurisdictions,
                                              isPrecinct):
        raceType = "primary" if primaryParty else "general"
        office = self._officeNameFromId(elecVt['officeId'])

        jurisdiction = elecVt['district']
        if jurisdiction == "Statewide":
            jurisdiction = "Vermont"

        generatedFileName = standardized_filename(
            'vt',
            election['start_date'],
            '.csv',
            party=primaryParty,
            race_type=raceType,
            reporting_level="precinct" if isPrecinct else None,
            jurisdiction=jurisdiction,
            office=office)

        meta = {
            'name': jurisdiction,
            'raw_url': self._getElectionViewUrl(elecVt['id'], isPrecinct),
            'generated_filename': generatedFileName,
            'election': election['slug'],
            # specific for VT
            'isPrecinct': isPrecinct,
            'office': office,
            'isPrimary': raceType == "general",
            'primaryParty': primaryParty,
            'officeDistrict': jurisdiction,
        }
        return meta
Ejemplo n.º 4
0
    def _generatedOneStateLegElectionMetaData(self, elecVt, election, primaryParty, jurisdictions, isPrecinct):
        raceType = "primary" if primaryParty else "general"
        office = self._officeNameFromId(elecVt['officeId'])

        jurisdiction = elecVt['district']
        if jurisdiction == "Statewide":
            jurisdiction = "Vermont"

        generatedFileName = standardized_filename('vt', election['start_date'], '.csv',
            party=primaryParty,
            race_type=raceType,
            reporting_level= "precinct" if isPrecinct  else None,
            jurisdiction=jurisdiction,
            office=office)

        meta = {
            'name'                  : jurisdiction,
            'raw_url'               : self._getElectionViewUrl(elecVt['id'], isPrecinct),
            'generated_filename'    : generatedFileName,
            'election'              : election['slug'],
            # specific for VT
            'isPrecinct'    : isPrecinct,
            'office'        : office,
            'isPrimary'     : raceType == "general",
            'primaryParty'  : primaryParty,
            'officeDistrict': jurisdiction,
            }
        return meta
Ejemplo n.º 5
0
 def filename(cls, fmt, timestamp=None, **filter_kwargs):
     state = filter_kwargs.get('state')
     assert state is not None
     start_date = filter_kwargs.get('datefilter')
     assert start_date is not None
     start_date_s = start_date.replace('-', '')
     suffix_bits = ['raw']
     race_type = filter_kwargs.get('election_type')
     reporting_level = filter_kwargs.get('reporting_level')
     return standardized_filename(state=state, start_date=start_date_s,
         race_type=race_type, reporting_level=reporting_level,
         extension="."+fmt, suffix_bits=suffix_bits)
Ejemplo n.º 6
0
 def filename(cls, fmt, timestamp=None, **filter_kwargs):
     state = filter_kwargs.get('state')
     assert state is not None
     start_date = filter_kwargs.get('datefilter')
     assert start_date is not None
     start_date_s = start_date.replace('-', '')
     suffix_bits = ['raw']
     race_type = filter_kwargs.get('election_type')
     reporting_level = filter_kwargs.get('reporting_level')
     return standardized_filename(state=state,
                                  start_date=start_date_s,
                                  race_type=race_type,
                                  reporting_level=reporting_level,
                                  extension="." + fmt,
                                  suffix_bits=suffix_bits)