Пример #1
0
    def test_game(self):
        team1 = Team(name='Yankees', city='New York', abbreviation='NYY')
        team2 = Team(name='Cubs', city='Chicago', abbreviation='CHC')
        game1 = Game(schedule_status='normal',
                     delayed_or_postponed_reason=None,
                     location='Yankee Stadium',
                     home_team=team1,
                     away_team=team2)
        db.session.add_all([team1, team2, game1])
        db.session.commit()
        self.assertEqual(game1.schedule_status, 'normal')
        self.assertEqual(game1.location, 'Yankee Stadium')
        self.assertEqual(game1.delayed_or_postponed_reason, None)

        self.assertEqual(game1.home_team.name, 'Yankees')
        self.assertEqual(len(team1.home_games), 1)

        game2 = Game(schedule_status='normal',
                     delayed_or_postponed_reason=None,
                     location='Yankee Stadium',
                     home_team=team1,
                     away_team=team2)
        game3 = Game(schedule_status='normal',
                     delayed_or_postponed_reason=None,
                     location='Wrigley Field',
                     home_team=team2,
                     away_team=team1)
        db.session.add_all([game2, game3])
        db.session.commit()
        self.assertEqual(len(team1.home_games), 2)
        self.assertEqual(len(team1.away_games), 1)

        game2.schedule_status = 'postponed'
        game2.delayed_or_postponed_reason = 'rain'

        self.assertEqual(game2.schedule_status, 'postponed')
        self.assertEqual(game2.delayed_or_postponed_reason, 'rain')