Esempio n. 1
0
    def _get_placed_horses(self):
        place_spots: Dict = {
            1: 'win',
            2: 'place',
            3: 'show',
            4: 'fourth_place',
            5: 'fifth_place',
        }

        # Set to use consolidated races db
        self.db.set_db(consolidated_races_db)
        sql = self.db.generate_query(
            consolidated_performances_table,
            ['horse_name', 'horse_id', f'position_{self.distance}'],
            where=self._generate_where_for_race(),
            other=f'AND position_{self.distance} IN (1, 2, 3, 4, 5)')
        horses = self.db.query_db(sql)

        # Set win/place/show/4th/5th attributes based on horse's finish position
        for horse in horses:
            # Check if there's a horse already found for that finish position
            if getattr(self, place_spots[horse[2]]) is not None:
                raise DuplicateHorseException(
                    getattr(self, place_spots[horse[2]]),
                    HorseID(horse[0], horse[1]))

            setattr(self, place_spots[horse[2]], HorseID(horse[0], horse[1]))

        # After going through horses, check if any of win/place/etc. are empty
        # If so, put generic unknown horse in there

        for place in place_spots.keys():
            if getattr(self, place_spots[place]) is None:
                setattr(self, place_spots[place], HorseID.unknown_horse())
Esempio n. 2
0
    def test_get_win_place_show_info_missing_some(self):
        # Set up data with no place horse in db
        self.db_handler.generate_query.return_value = 'This is a SQL query string'
        self.db_handler.query_db.return_value = [('Dark Artist', '15001360', 1), ('Lisa Limon', '15000251', 4),
                                                 ('So Hi Society (IRE)', 'F0044820', 3),
                                                 ('Stormologist', '15007318', 5)]
        # Set up the SUT
        race_id = RaceID(date(self.year, self.month, self.day), self.track, self.race_num)
        race = Race(race_id, self.db_handler, test_mode=True)

        # Run the SUT
        race._get_placed_horses()

        # Check the output state. Race.place should have a Horse.unknown_horse() in it
        self.assertEqual(race.place, HorseID.unknown_horse())