forked from test/mau_mau_bot
fix end_game
This commit is contained in:
parent
c9f7c09a46
commit
424219d825
2 changed files with 39 additions and 3 deletions
|
@ -127,16 +127,18 @@ class GameManager(object):
|
|||
|
||||
# Clear game
|
||||
for player_in_game in game.players:
|
||||
this_users_players = self.userid_players[player.user.id]
|
||||
this_users_players = self.userid_players[player_in_game.user.id]
|
||||
this_users_players.remove(player_in_game)
|
||||
|
||||
if this_users_players:
|
||||
self.userid_current[player.user.id] = this_users_players[0]
|
||||
else:
|
||||
del self.userid_players[player.user.id]
|
||||
del self.userid_current[player.user.id]
|
||||
del self.userid_players[player_in_game.user.id]
|
||||
del self.userid_current[player_in_game.user.id]
|
||||
|
||||
self.chatid_games[chat.id].remove(game)
|
||||
if not self.chatid_games[chat.id]:
|
||||
del self.chatid_games[chat.id]
|
||||
|
||||
def player_for_user_in_chat(self, user, chat):
|
||||
players = self.userid_players.get(user.id, list())
|
||||
|
|
|
@ -71,3 +71,37 @@ class Test(unittest.TestCase):
|
|||
self.assertRaises(AlreadyJoinedError,
|
||||
self.gm.join_game,
|
||||
*(self.user1, self.chat0))
|
||||
|
||||
def test_leave_game(self):
|
||||
g0 = self.gm.new_game(self.chat0)
|
||||
|
||||
self.gm.join_game(self.user0, self.chat0)
|
||||
self.gm.join_game(self.user1, self.chat0)
|
||||
|
||||
self.assertRaises(NotEnoughPlayersError,
|
||||
self.gm.leave_game,
|
||||
*(self.user1, self.chat0))
|
||||
|
||||
self.gm.join_game(self.user2, self.chat0)
|
||||
self.gm.leave_game(self.user0, self.chat0)
|
||||
|
||||
self.assertRaises(NoGameInChatError,
|
||||
self.gm.leave_game,
|
||||
*(self.user0, self.chat0))
|
||||
|
||||
def test_end_game(self):
|
||||
g0 = self.gm.new_game(self.chat0)
|
||||
|
||||
self.gm.join_game(self.user0, self.chat0)
|
||||
self.gm.join_game(self.user1, self.chat0)
|
||||
|
||||
self.assertEqual(len(self.gm.userid_players[0]), 1)
|
||||
|
||||
g1 = self.gm.new_game(self.chat0)
|
||||
self.gm.join_game(self.user2, self.chat0)
|
||||
|
||||
self.gm.end_game(self.chat0, self.user0)
|
||||
self.assertEqual(len(self.gm.chatid_games[0]), 1)
|
||||
|
||||
self.gm.end_game(self.chat0, self.user2)
|
||||
self.assertFalse(0 in self.gm.chatid_games)
|
||||
|
|
Loading…
Reference in a new issue