예제 #1
0
 def test9LoadCard(self):
     game = GameModel.getGameById(1, self.session)
     round = game.getCurrentRound()
     self.session.commit()
     turn = round.getCurrentTurn()
     cardData = turn.loadCard()
     print("buzzword: " + cardData['card']['buzzword'])
     self.session.commit()
     self.session.close()
예제 #2
0
 def test5AddUsedCard(self):
     game = GameModel.getGameById(1, self.session)
     card = CardModel.findCardById(self.session, 2)
     game.addUsedCard(card)
     self.session.flush()
     self.session.commit()
     self.assertTrue(card in game.usedCards)
     unusedCards = game.getUnusedCards()
     self.assertEqual(len(unusedCards), 49)
예제 #3
0
 def test8AddGameChanger(self):
     game = GameModel.getGameById(1, self.session)
     round = game.getCurrentRound()
     self.session.commit()
     turn = round.getCurrentTurn()
     turn.setGameChanger()
     print("Changer Number is {}".format(turn.gameChangerNumber))
     turn.updatePlayerRoles(
     )  # roles have to be updated if the all-guessers game changer is selected
     self.session.commit()
     self.session.close()
예제 #4
0
 def test7CreateTurn(self):
     game = GameModel.getGameById(1, self.session)
     turn = game.createTurn()
     self.session.commit()
     obervers = turn.getObservers()
     guessers = turn.getGuessers()
     moderator = turn.getModerator()
     teller = turn.getTeller()
     teamOnDeck = turn.team
     print("On deck: " + teamOnDeck.name)
     print("Moderator: " + moderator.nickname)
     print("Teller: " + teller.nickname)
     self.session.close()
예제 #5
0
    def test3JoinTeam(self):
        player1 = PlayerModel.findPlayerById(self.session, 2)
        team1 = TeamModel.getTeamById(self.session, 1)
        cGame = GameModel.getGameById(1, self.session)
        player1.team = team1

        for i in range(1, 8):
            team = TeamModel.getTeamById(self.session, i)
            player2 = PlayerModel.findPlayerById(self.session, 2 * i)
            player3 = PlayerModel.findPlayerById(self.session, 2 * i + 1)
            player2.team = team
            player3.team = team
            i = i + 1
            self.session.flush()
            self.session.commit()
        self.assertTrue(player1 in team1.players)
        self.assertTrue(player1.team == team1)
예제 #6
0
    def test2GameCreate(self):
        print(
            "\n\n*************Test add new valid game with 7 teams**************\n\n"
        )
        initiator = PlayerModel.findPlayerById(self.session, 1)
        #print ("Email: " + initiator.email)
        game = GameModel(initiator, "CS699", 60)
        team1 = TeamModel("Team 1")
        team2 = TeamModel("Team 2")
        team3 = TeamModel("Team 3")
        teams = [team1, team2, team3]
        initiator.team = team1
        self.session.flush()
        game.teams = teams
        self.session.add(game)
        self.session.commit()
        self.assertEqual(GameModel.numberOfRows(self.session), 1)
        self.assertEqual(GameModel.getGameById(1, self.session), game)
        cGame = GameModel.getGameById(1, self.session)
        self.assertEqual(cGame.teams, teams)
        self.assertEqual(team1.gameId, 1)

        print(
            "\n\n*************Test add invalid gamename **************************\n\n"
        )
        gameData = {
            "maxPlayersPerTeam": 2,
            "turnDuration": 30,
            "pointsToWin": 30,
            "numberOfTeams": 2,
            "skipPenaltyAfter": 3,
            "gameChangers": True,
            "name": "",
            "initiatorTeam": {
                "name": "team1"
            },
            "teamData": [{
                "name": "team1"
            }, {
                "name": "team2"
            }]
        }
        feedback = GameModel.isValidGame(self.session, gameData)
        self.assertFalse(feedback["valid"])
        self.assertEqual(feedback["message"],
                         'game name must be between 2 and 255 characters')

        print(
            "\n\n*************Test add invalid turnDuration **************************\n\n"
        )
        gameData = {
            "maxPlayersPerTeam": 2,
            "turnDuration": 0,
            "pointsToWin": 30,
            "numberOfTeams": 2,
            "skipPenaltyAfter": 3,
            "gameChangers": True,
            "name": "game123",
            "initiatorTeam": {
                "name": "team1"
            },
            "teamData": [{
                "name": "team1"
            }, {
                "name": "team2"
            }]
        }
        feedback = GameModel.isValidGame(self.session, gameData)
        self.assertFalse(feedback["valid"])
        self.assertEqual(feedback["message"],
                         "turn duration must be between 30 and 120 inclusive")

        print(
            "\n\n*************Test add invalid teams *****************************\n\n"
        )
        gameData = {
            "maxPlayersPerTeam": 2,
            "turnDuration": 30,
            "pointsToWin": 30,
            "numberOfTeams": 0,
            "skipPenaltyAfter": 3,
            "gameChangers": True,
            "name": "game123",
            "initiatorTeam": {
                "name": "team1"
            },
            "teamData": []
        }
        feedback = GameModel.isValidGame(self.session, gameData)
        self.assertFalse(feedback["valid"])
        self.assertEqual(feedback["message"],
                         "number of teams must be between 2 and 5 inclusive")

        print(
            "\n\n*************Test add invalid players in one team *****************************\n\n"
        )
        gameData = {
            "maxPlayersPerTeam": 10,
            "turnDuration": 30,
            "pointsToWin": 30,
            "numberOfTeams": 2,
            "skipPenaltyAfter": 3,
            "gameChangers": True,
            "name": "game123",
            "initiatorTeam": {
                "name": "team1"
            },
            "teamData": [{
                "name": "team1"
            }, {
                "name": "team2"
            }]
        }
        feedback = GameModel.isValidGame(self.session, gameData)
        self.assertFalse(feedback["valid"])
        self.assertEqual(
            feedback["message"],
            "number of players in a team must be between 2 and 5 inclusive")

        print(
            "\n\n*************Test add invalid points to win *****************************\n\n"
        )
        gameData = {
            "maxPlayersPerTeam": 2,
            "turnDuration": 30,
            "pointsToWin": 1,
            "numberOfTeams": 2,
            "skipPenaltyAfter": 3,
            "gameChangers": True,
            "name": "game123",
            "initiatorTeam": {
                "name": "team1"
            },
            "teamData": [{
                "name": "team1"
            }, {
                "name": "team2"
            }]
        }
        feedback = GameModel.isValidGame(self.session, gameData)
        self.assertFalse(feedback["valid"])
        self.assertEqual(feedback["message"],
                         "points to win must be between 10 and 60 inclusive")