Example #1
0
    def test_init_races(self):
        """
        Verify race data is properly written to disk
        """
        ap.init('.tests')

        with open('.tests/init_races.json') as f:
            races = json.load(f)
            senate_races = [race for race in races if race['office_id'] == 'S']
            house_races = [race for race in races if race['office_id'] == 'H']
            gov_races = [race for race in races if race['office_id'] == 'G']

            # Correct number of races initialized, fixed #s like Senate Races are
            # particularly useful for testing.
            self.assertEqual(NUM_RACES, len(races))
            self.assertEqual(NUM_SENATE_RACES, len(senate_races))
            self.assertEqual(NUM_HOUSE_RACES, len(house_races))
            self.assertEqual(NUM_GOV_RACES, len(gov_races))

            # Are keys correct?
            expected_keys = [
                'office_name',
                'seat_name',
                'seat_number',
                'race_type',
                'office_id',
                'state_postal',
                'race_id',
            ]
            self.assertItemsEqual(races[0], expected_keys)

            # Are there weird or missing states?
            for race in races:
                self.assertIn(race.get('state_postal'), STATES.keys())
Example #2
0
    def test_init_races(self):
        """
        Verify race data is properly written to disk
        """
        ap.init('.tests')

        with open('.tests/init_races.json') as f:
            races = json.load(f)
            senate_races = [race for race in races if race['office_id'] == 'S']
            house_races = [race for race in races if race['office_id'] == 'H']
            gov_races = [race for race in races if race['office_id'] == 'G']

            # Correct number of races initialized, fixed #s like Senate Races are
            # particularly useful for testing.
            self.assertEqual(NUM_RACES, len(races))
            self.assertEqual(NUM_SENATE_RACES, len(senate_races))
            self.assertEqual(NUM_HOUSE_RACES, len(house_races))
            self.assertEqual(NUM_GOV_RACES, len(gov_races))

            # Are keys correct?
            expected_keys = [
                'office_name',
                'seat_name',
                'seat_number',
                'race_type',
                'office_id',
                'state_postal',
                'race_id',
            ]
            self.assertItemsEqual(races[0], expected_keys)

            # Are there weird or missing states?
            for race in races:
                self.assertIn(race.get('state_postal'), STATES.keys())
Example #3
0
    def test_init_candidates(self):
        """
        Verify candidate data is properly written to disk
        """
        ap.init('.tests')

        with open('.tests/init_candidates.json') as f:
            candidates = json.load(f)

            # Correct number of candidates
            self.assertEqual(len(candidates), NUM_CANDIDATES)

            # Correct keys
            expected_keys = [
                'first_name',
                'last_name',
                'incumbent',
                'candidate_id',
                'race_id',
                'party',
            ]
            self.assertItemsEqual(candidates[0], expected_keys)
Example #4
0
    def test_init_candidates(self):
        """
        Verify candidate data is properly written to disk
        """
        ap.init('.tests')

        with open('.tests/init_candidates.json') as f:
            candidates = json.load(f)

            # Correct number of candidates
            self.assertEqual(len(candidates), NUM_CANDIDATES)

            # Correct keys
            expected_keys = [
                'first_name',
                'last_name',
                'incumbent',
                'candidate_id',
                'race_id',
                'party',
            ]
            self.assertItemsEqual(candidates[0], expected_keys)