changeset 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 7ea7053dda88
children 660b3f5b6c78
files src/plugins/plugin_misc_room_game.py src/test/test_plugin_misc_room_game.py
diffstat 2 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_room_game.py	Thu Feb 20 16:37:05 2014 +0100
+++ b/src/plugins/plugin_misc_room_game.py	Thu Feb 20 17:51:51 2014 +0100
@@ -304,7 +304,7 @@
         nicks = []
         for player_jid in [player.userhostJID() for player in players_jids]:
             # TODO: find a way to make it secure
-            other_nick = self.host.plugins["XEP-0045"].getRoomNickOfUser(room, player_jid, secure=False)
+            other_nick = self.host.plugins["XEP-0045"].getRoomNickOfUser(room, player_jid, secure=self.testing)
             if other_nick is None:
                 self.host.plugins["XEP-0249"].invite(player_jid, room_jid, {"game": self.name}, profile)
             else:
--- a/src/test/test_plugin_misc_room_game.py	Thu Feb 20 16:37:05 2014 +0100
+++ b/src/test/test_plugin_misc_room_game.py	Thu Feb 20 17:51:51 2014 +0100
@@ -377,7 +377,7 @@
         self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
         room = self.plugin_0045.getRoom(0, 0)
         nicks = [self.plugin_0045.getNick(0, 0)]
-        self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()])
+        self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()])
 
         # one user joins
         user_nick = self.plugin_0045.joinRoom(0, 1)
@@ -387,14 +387,17 @@
         # the user leaves
         self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
         room = self.plugin_0045.getRoom(0, 1)
-        self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1])  # wrong profile
+        # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile
+        self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1])  # not the referee
         self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
         room = self.plugin_0045.getRoom(0, 0)
-        self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE)  # referee profile
+        user_nick = self.plugin_0045.leaveRoom(0, 1)
+        self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE)  # referee
         nicks.pop()
         self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
 
         # all the users join
+        user_nick = self.plugin_0045.joinRoom(0, 1)
         self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
         nicks.append(user_nick)
         user_nick = self.plugin_0045.joinRoom(0, 3)
@@ -407,20 +410,22 @@
         self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
 
         # one user leaves
+        user_nick = self.plugin_0045.leaveRoom(0, 4)
         self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
         nicks.pop()
-        self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[4].userhost()])
+        self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost()])
 
         # another leaves
+        user_nick = self.plugin_0045.leaveRoom(0, 3)
         self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
         nicks.pop()
-        self.assertTrue(self.plugin.invitations[ROOM_JID_S][0], [Const.JID[4].userhost(), Const.JID[3].userhost()])
+        self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost(), Const.JID[3].userhost()])
 
         # they can join again
-        user_nick = self.plugin_0045.getNickOfUser(0, 3, 0)
+        user_nick = self.plugin_0045.joinRoom(0, 3)
         self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
         nicks.append(user_nick)
-        user_nick = self.plugin_0045.getNickOfUser(0, 4, 0)
+        user_nick = self.plugin_0045.joinRoom(0, 4)
         self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
         nicks.append(user_nick)
         self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)