comparison src/test/test_plugin_misc_room_game.py @ 857:3c270d691e56

test: fix the tests for plugin room game
author souliane <souliane@mailoo.org>
date Thu, 20 Feb 2014 17:51:51 +0100
parents 187d2443c82d
children 301b342c697a
comparison
equal deleted inserted replaced
856:7ea7053dda88 857:3c270d691e56
375 self.init(player_init={"xxx": "xyz"}) 375 self.init(player_init={"xxx": "xyz"})
376 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]] 376 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]]
377 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) 377 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
378 room = self.plugin_0045.getRoom(0, 0) 378 room = self.plugin_0045.getRoom(0, 0)
379 nicks = [self.plugin_0045.getNick(0, 0)] 379 nicks = [self.plugin_0045.getNick(0, 0)]
380 self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()]) 380 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()])
381 381
382 # one user joins 382 # one user joins
383 user_nick = self.plugin_0045.joinRoom(0, 1) 383 user_nick = self.plugin_0045.joinRoom(0, 1)
384 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) 384 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
385 nicks.append(user_nick) 385 nicks.append(user_nick)
386 386
387 # the user leaves 387 # the user leaves
388 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) 388 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
389 room = self.plugin_0045.getRoom(0, 1) 389 room = self.plugin_0045.getRoom(0, 1)
390 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # wrong profile 390 # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile
391 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) 391 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # not the referee
392 room = self.plugin_0045.getRoom(0, 0) 392 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
393 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee profile 393 room = self.plugin_0045.getRoom(0, 0)
394 user_nick = self.plugin_0045.leaveRoom(0, 1)
395 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee
394 nicks.pop() 396 nicks.pop()
395 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) 397 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
396 398
397 # all the users join 399 # all the users join
400 user_nick = self.plugin_0045.joinRoom(0, 1)
398 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) 401 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
399 nicks.append(user_nick) 402 nicks.append(user_nick)
400 user_nick = self.plugin_0045.joinRoom(0, 3) 403 user_nick = self.plugin_0045.joinRoom(0, 3)
401 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 404 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
402 nicks.append(user_nick) 405 nicks.append(user_nick)
405 nicks.append(user_nick) 408 nicks.append(user_nick)
406 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) 409 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
407 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) 410 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
408 411
409 # one user leaves 412 # one user leaves
413 user_nick = self.plugin_0045.leaveRoom(0, 4)
410 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 414 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
411 nicks.pop() 415 nicks.pop()
412 self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[4].userhost()]) 416 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost()])
413 417
414 # another leaves 418 # another leaves
419 user_nick = self.plugin_0045.leaveRoom(0, 3)
415 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 420 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
416 nicks.pop() 421 nicks.pop()
417 self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[4].userhost(), Const.JID[3].userhost()]) 422 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost(), Const.JID[3].userhost()])
418 423
419 # they can join again 424 # they can join again
420 user_nick = self.plugin_0045.getNickOfUser(0, 3, 0) 425 user_nick = self.plugin_0045.joinRoom(0, 3)
421 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 426 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
422 nicks.append(user_nick) 427 nicks.append(user_nick)
423 user_nick = self.plugin_0045.getNickOfUser(0, 4, 0) 428 user_nick = self.plugin_0045.joinRoom(0, 4)
424 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 429 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
425 nicks.append(user_nick) 430 nicks.append(user_nick)
426 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) 431 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
427 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) 432 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
428 433