Mercurial > libervia-backend
comparison src/test/test_plugin_misc_room_game.py @ 1412:979210da778a
test: fix the tests
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 17 Apr 2015 19:06:39 +0200 |
parents | 069ad98b360d |
children | d17772b0fe22 |
comparison
equal
deleted
inserted
replaced
1411:8767c0bb7d48 | 1412:979210da778a |
---|---|
42 "main": "Dummy", | 42 "main": "Dummy", |
43 "handler": "no", # handler MUST be "no" (dynamic inheritance) | 43 "handler": "no", # handler MUST be "no" (dynamic inheritance) |
44 "description": _("""Dummy plugin to test room game""") | 44 "description": _("""Dummy plugin to test room game""") |
45 } | 45 } |
46 | 46 |
47 ROOM_JID_S = Const.MUC_STR[0] | 47 ROOM_JID = JID(Const.MUC_STR[0]) |
48 PROFILE = Const.PROFILE[0] | 48 PROFILE = Const.PROFILE[0] |
49 OTHER_PROFILE = Const.PROFILE[1] | 49 OTHER_PROFILE = Const.PROFILE[1] |
50 | 50 |
51 | 51 |
52 class RoomGameTest(helpers.SatTestCase): | 52 class RoomGameTest(helpers.SatTestCase): |
58 self.host.reinit() | 58 self.host.reinit() |
59 self.plugin = plugin.RoomGame(self.host) | 59 self.plugin = plugin.RoomGame(self.host) |
60 self.plugin._init_(self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init) | 60 self.plugin._init_(self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init) |
61 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host) | 61 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host) |
62 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host) | 62 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host) |
63 logger = getLogger() | |
64 level = logger.getEffectiveLevel() | |
65 logger.setLevel(WARNING) # remove log.info pollution | |
66 for profile in Const.PROFILE: | 63 for profile in Const.PROFILE: |
67 self.host.getClient(profile) # init self.host.profiles[profile] | 64 self.host.getClient(profile) # init self.host.profiles[profile] |
68 logger.setLevel(level) | |
69 | 65 |
70 def initGame(self, muc_index, user_index): | 66 def initGame(self, muc_index, user_index): |
71 self.plugin_0045.joinRoom(user_index, muc_index) | 67 self.plugin_0045.joinRoom(user_index, muc_index) |
72 self.plugin._initGame(Const.MUC_STR[muc_index], Const.JID[user_index].user) | 68 self.plugin._initGame(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user) |
73 | 69 |
74 def _expectedMessage(self, to, type_, tag, players=[]): | 70 def _expectedMessage(self, to, type_, tag, players=[]): |
75 content = "<%s" % tag | 71 content = "<%s" % tag |
76 if not players: | 72 if not players: |
77 content += "/>" | 73 content += "/>" |
78 else: | 74 else: |
79 content += ">" | 75 content += ">" |
80 for i in xrange(0, len(players)): | 76 for i in xrange(0, len(players)): |
81 content += "<player index='%s'>%s</player>" % (i, players[i]) | 77 content += "<player index='%s'>%s</player>" % (i, players[i]) |
82 content += "</%s>" % tag | 78 content += "</%s>" % tag |
83 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content) | 79 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to.full(), type_, TAG, NAMESERVICE, content) |
84 | 80 |
85 def test_createOrInvite_solo(self): | 81 def test_createOrInvite_solo(self): |
86 self.reinit() | 82 self.reinit() |
87 self.plugin_0045.joinRoom(0, 0) | 83 self.plugin_0045.joinRoom(0, 0) |
88 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) | 84 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) |
89 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 85 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
90 | 86 |
91 def test_createOrInvite_multi_not_waiting(self): | 87 def test_createOrInvite_multi_not_waiting(self): |
92 self.reinit() | 88 self.reinit() |
93 self.plugin_0045.joinRoom(0, 0) | 89 self.plugin_0045.joinRoom(0, 0) |
94 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 90 other_players = [Const.JID[1], Const.JID[2]] |
95 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) | 91 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) |
96 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 92 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
97 | 93 |
98 def test_createOrInvite_multi_waiting(self): | 94 def test_createOrInvite_multi_waiting(self): |
99 self.reinit(player_init={'score': 0}) | 95 self.reinit(player_init={'score': 0}) |
100 self.plugin_0045.joinRoom(0, 0) | 96 self.plugin_0045.joinRoom(0, 0) |
101 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 97 other_players = [Const.JID[1], Const.JID[2]] |
102 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) | 98 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) |
103 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) | 99 self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) |
104 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) | 100 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) |
105 | 101 |
106 def test_initGame(self): | 102 def test_initGame(self): |
107 self.reinit() | 103 self.reinit() |
108 self.initGame(0, 0) | 104 self.initGame(0, 0) |
109 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) | 105 self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) |
110 self.assertEqual([], self.plugin.games[ROOM_JID_S]['players']) | 106 self.assertEqual([], self.plugin.games[ROOM_JID]['players']) |
111 | 107 |
112 def test_checkJoinAuth(self): | 108 def test_checkJoinAuth(self): |
113 self.reinit() | 109 self.reinit() |
114 check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user)) | 110 check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user)) |
115 check(False) | 111 check(False) |
116 # to test the "invited" mode, the referee must be different than the user to test | 112 # to test the "invited" mode, the referee must be different than the user to test |
117 self.initGame(0, 1) | 113 self.initGame(0, 1) |
118 self.plugin.join_mode = self.plugin.ALL | 114 self.plugin.join_mode = self.plugin.ALL |
119 check(True) | 115 check(True) |
120 self.plugin.join_mode = self.plugin.INVITED | 116 self.plugin.join_mode = self.plugin.INVITED |
121 check(False) | 117 check(False) |
122 self.plugin.invitations[ROOM_JID_S] = [(None, [Const.JID[0].userhost()])] | 118 self.plugin.invitations[ROOM_JID] = [(None, [Const.JID[0].userhostJID()])] |
123 check(True) | 119 check(True) |
124 self.plugin.join_mode = self.plugin.NONE | 120 self.plugin.join_mode = self.plugin.NONE |
125 check(False) | 121 check(False) |
126 self.plugin.games[ROOM_JID_S]['players'].append(Const.JID[0].user) | 122 self.plugin.games[ROOM_JID]['players'].append(Const.JID[0].user) |
127 check(True) | 123 check(True) |
128 | 124 |
129 def test_updatePlayers(self): | 125 def test_updatePlayers(self): |
130 self.reinit() | 126 self.reinit() |
131 self.initGame(0, 0) | 127 self.initGame(0, 0) |
132 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) | 128 self.assertEqual(self.plugin.games[ROOM_JID]['players'], []) |
133 self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0]) | 129 self.plugin._updatePlayers(ROOM_JID, [], True, Const.PROFILE[0]) |
134 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) | 130 self.assertEqual(self.plugin.games[ROOM_JID]['players'], []) |
135 self.plugin._updatePlayers(ROOM_JID_S, ["user1"], True, Const.PROFILE[0]) | 131 self.plugin._updatePlayers(ROOM_JID, ["user1"], True, Const.PROFILE[0]) |
136 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1"]) | 132 self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1"]) |
137 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) | 133 self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) |
138 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) | 134 self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1", "user2", "user3"]) |
139 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice | 135 self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice |
140 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) | 136 self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1", "user2", "user3"]) |
141 | 137 |
142 def test_synchronizeRoom(self): | 138 def test_synchronizeRoom(self): |
143 self.reinit() | 139 self.reinit() |
144 self.initGame(0, 0) | 140 self.initGame(0, 0) |
145 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 141 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) |
146 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", [])) | 142 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", [])) |
147 self.plugin.games[ROOM_JID_S]['players'].append("test1") | 143 self.plugin.games[ROOM_JID]['players'].append("test1") |
148 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 144 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) |
149 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"])) | 145 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", ["test1"])) |
150 self.plugin.games[ROOM_JID_S]['started'] = True | 146 self.plugin.games[ROOM_JID]['started'] = True |
151 self.plugin.games[ROOM_JID_S]['players'].append("test2") | 147 self.plugin.games[ROOM_JID]['players'].append("test2") |
152 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 148 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) |
153 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"])) | 149 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", ["test1", "test2"])) |
154 self.plugin.games[ROOM_JID_S]['players'].append("test3") | 150 self.plugin.games[ROOM_JID]['players'].append("test3") |
155 self.plugin.games[ROOM_JID_S]['players'].append("test4") | 151 self.plugin.games[ROOM_JID]['players'].append("test4") |
156 user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user) | 152 user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user) |
157 user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user) | 153 user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user) |
158 self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0]) | 154 self.plugin._synchronizeRoom(ROOM_JID, [user1, user2], Const.PROFILE[0]) |
159 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) | 155 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1, "normal", "started", ["test1", "test2", "test3", "test4"])) |
160 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) | 156 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2, "normal", "started", ["test1", "test2", "test3", "test4"])) |
161 | 157 |
162 def test_invitePlayers(self): | 158 def test_invitePlayers(self): |
163 self.reinit() | 159 self.reinit() |
164 self.initGame(0, 0) | 160 self.initGame(0, 0) |
165 self.plugin_0045.joinRoom(0, 1) | 161 self.plugin_0045.joinRoom(0, 1) |
166 self.assertEqual(self.plugin.invitations[ROOM_JID_S], []) | 162 self.assertEqual(self.plugin.invitations[ROOM_JID], []) |
167 room = self.plugin_0045.getRoom(0, 0) | 163 room = self.plugin_0045.getRoom(0, 0) |
168 nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[2]], Const.JID[0].user, Const.PROFILE[0]) | 164 nicks = self.plugin._invitePlayers(room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0]) |
169 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[2].userhost()]) | 165 self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()]) |
170 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost | 166 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost |
171 self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user]) | 167 self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user]) |
172 | 168 |
173 nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[3]], Const.JID[0].user, Const.PROFILE[0]) | 169 nicks = self.plugin._invitePlayers(room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0]) |
174 self.assertEqual(self.plugin.invitations[ROOM_JID_S][1][1], [Const.JID[1].userhost(), Const.JID[3].userhost()]) | 170 self.assertEqual(self.plugin.invitations[ROOM_JID][1][1], [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()]) |
175 # this time Const.JID[1] and Const.JID[3] have the same user but the host differs | 171 # this time Const.JID[1] and Const.JID[3] have the same user but the host differs |
176 self.assertEqual(nicks, [Const.JID[1].user]) | 172 self.assertEqual(nicks, [Const.JID[1].user]) |
177 | 173 |
178 def test_checkInviteAuth(self): | 174 def test_checkInviteAuth(self): |
179 | 175 |
180 def check(value, index): | 176 def check(value, index): |
181 nick = self.plugin_0045.getNick(0, index) | 177 nick = self.plugin_0045.getNick(0, index) |
182 getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID_S, nick)) | 178 getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID, nick)) |
183 | 179 |
184 self.reinit() | 180 self.reinit() |
185 | 181 |
186 for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]: | 182 for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]: |
187 self.plugin.invite_mode = mode | 183 self.plugin.invite_mode = mode |
196 check(False, 1) | 192 check(False, 1) |
197 self.plugin.invite_mode = self.plugin.FROM_REFEREE | 193 self.plugin.invite_mode = self.plugin.FROM_REFEREE |
198 check(True, 0) | 194 check(True, 0) |
199 check(False, 1) | 195 check(False, 1) |
200 user_nick = self.plugin_0045.joinRoom(0, 1) | 196 user_nick = self.plugin_0045.joinRoom(0, 1) |
201 self.plugin.games[ROOM_JID_S]['players'].append(user_nick) | 197 self.plugin.games[ROOM_JID]['players'].append(user_nick) |
202 self.plugin.invite_mode = self.plugin.FROM_PLAYERS | 198 self.plugin.invite_mode = self.plugin.FROM_PLAYERS |
203 check(True, 0) | 199 check(True, 0) |
204 check(True, 1) | 200 check(True, 1) |
205 check(False, 2) | 201 check(False, 2) |
206 | 202 |
207 def test_isReferee(self): | 203 def test_isReferee(self): |
208 self.reinit() | 204 self.reinit() |
209 self.initGame(0, 0) | 205 self.initGame(0, 0) |
210 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) | 206 self.assertTrue(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 0))) |
211 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1))) | 207 self.assertFalse(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 1))) |
212 | 208 |
213 def test_isPlayer(self): | 209 def test_isPlayer(self): |
214 self.reinit() | 210 self.reinit() |
215 self.initGame(0, 0) | 211 self.initGame(0, 0) |
216 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) | 212 self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 0))) |
217 user_nick = self.plugin_0045.joinRoom(0, 1) | 213 user_nick = self.plugin_0045.joinRoom(0, 1) |
218 self.plugin.games[ROOM_JID_S]['players'].append(user_nick) | 214 self.plugin.games[ROOM_JID]['players'].append(user_nick) |
219 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) | 215 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) |
220 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 2))) | 216 self.assertFalse(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 2))) |
221 | 217 |
222 def test_checkWaitAuth(self): | 218 def test_checkWaitAuth(self): |
223 | 219 |
224 def check(value, other_players, confirmed, rest): | 220 def check(value, other_players, confirmed, rest): |
225 room = self.plugin_0045.getRoom(0, 0) | 221 room = self.plugin_0045.getRoom(0, 0) |
251 self.plugin_0045.getNickOfUser(0, 2, 0)], []) | 247 self.plugin_0045.getNickOfUser(0, 2, 0)], []) |
252 | 248 |
253 def test_prepareRoom_trivial(self): | 249 def test_prepareRoom_trivial(self): |
254 self.reinit() | 250 self.reinit() |
255 other_players = [] | 251 other_players = [] |
256 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 252 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
257 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 253 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
258 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user)) | 254 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user)) |
259 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[0].user)) | 255 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[0].user)) |
260 self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID_S, [])) | 256 self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID, [])) |
261 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) | 257 self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) |
262 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[0].user)) | 258 self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[0].user)) |
263 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 259 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) |
264 | 260 |
265 def test_prepareRoom_invite(self): | 261 def test_prepareRoom_invite(self): |
266 self.reinit() | 262 self.reinit() |
267 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 263 other_players = [Const.JID[1], Const.JID[2]] |
268 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 264 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
269 room = self.plugin_0045.getRoom(0, 0) | 265 room = self.plugin_0045.getRoom(0, 0) |
270 | 266 |
271 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 267 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
272 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user)) | 268 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user)) |
273 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user)) | 269 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user)) |
274 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user)) | 270 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) |
275 self.assertEqual((True, [], other_players), self.plugin._checkWaitAuth(room, other_players)) | 271 self.assertEqual((True, [], other_players), self.plugin._checkWaitAuth(room, other_players)) |
276 | 272 |
277 player2_nick = self.plugin_0045.joinRoom(0, 1) | 273 player2_nick = self.plugin_0045.joinRoom(0, 1) |
278 self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE) | 274 self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE) |
279 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick)) | 275 self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) |
280 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, player2_nick)) | 276 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, player2_nick)) |
281 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, player2_nick)) | 277 self.assertFalse(self.plugin.isReferee(ROOM_JID, player2_nick)) |
282 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick)) | 278 self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) |
283 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0))) | 279 self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0))) |
284 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, Const.JID_STR[3])) | 280 self.assertFalse(self.plugin.isPlayer(ROOM_JID, "xxx")) |
285 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1])) | 281 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[1])) |
286 | 282 |
287 def test_prepareRoom_score1(self): | 283 def test_prepareRoom_score1(self): |
288 self.reinit(player_init={'score': 0}) | 284 self.reinit(player_init={'score': 0}) |
289 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 285 other_players = [Const.JID[1], Const.JID[2]] |
290 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 286 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
291 room = self.plugin_0045.getRoom(0, 0) | 287 room = self.plugin_0045.getRoom(0, 0) |
292 | 288 |
293 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) | 289 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) |
294 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user)) | 290 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user)) |
295 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user)) | 291 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user)) |
296 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user)) | 292 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) |
297 self.assertEqual((False, [], other_players), self.plugin._checkWaitAuth(room, other_players)) | 293 self.assertEqual((False, [], other_players), self.plugin._checkWaitAuth(room, other_players)) |
298 | 294 |
299 user_nick = self.plugin_0045.joinRoom(0, 1) | 295 user_nick = self.plugin_0045.joinRoom(0, 1) |
300 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) | 296 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) |
301 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) | 297 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) |
302 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, user_nick)) | 298 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, user_nick)) |
303 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, user_nick)) | 299 self.assertFalse(self.plugin.isReferee(ROOM_JID, user_nick)) |
304 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) | 300 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) |
305 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost | 301 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost |
306 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0))) | 302 self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0))) |
307 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user | 303 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user |
308 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[3].user)) | 304 self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[3].user)) |
309 # but Const.JID[3] is actually not in the room | 305 # but Const.JID[3] is actually not in the room |
310 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) | 306 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) |
311 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0])) | 307 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[0])) |
312 | 308 |
313 def test_prepareRoom_score2(self): | 309 def test_prepareRoom_score2(self): |
314 self.reinit(player_init={'score': 0}) | 310 self.reinit(player_init={'score': 0}) |
315 other_players = [Const.JID_STR[1], Const.JID_STR[4]] | 311 other_players = [Const.JID[1], Const.JID[4]] |
316 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 312 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
317 room = self.plugin_0045.getRoom(0, 0) | 313 room = self.plugin_0045.getRoom(0, 0) |
318 | 314 |
319 user_nick = self.plugin_0045.joinRoom(0, 1) | 315 user_nick = self.plugin_0045.joinRoom(0, 1) |
320 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) | 316 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) |
321 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 317 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) |
322 user_nick = self.plugin_0045.joinRoom(0, 4) | 318 user_nick = self.plugin_0045.joinRoom(0, 4) |
323 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) | 319 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) |
324 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 320 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) |
325 | 321 |
326 def test_userJoinedTrigger(self): | 322 def test_userJoinedTrigger(self): |
327 self.reinit(player_init={"xxx": "xyz"}) | 323 self.reinit(player_init={"xxx": "xyz"}) |
328 other_players = [Const.JID_STR[1], Const.JID_STR[3]] | 324 other_players = [Const.JID[1], Const.JID[3]] |
329 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 325 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
330 nicks = [self.plugin_0045.getNick(0, 0)] | 326 nicks = [self.plugin_0045.getNick(0, 0)] |
331 | 327 |
332 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) | 328 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", nicks)) |
333 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1) | 329 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1) |
334 | 330 |
335 # wrong profile | 331 # wrong profile |
336 user_nick = self.plugin_0045.joinRoom(0, 1) | 332 user_nick = self.plugin_0045.joinRoom(0, 1) |
337 room = self.plugin_0045.getRoom(0, 1) | 333 room = self.plugin_0045.getRoom(0, 1) |
338 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) | 334 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) |
339 self.assertEqual(self.host.getSentMessage(0), None) # no new message has been sent | 335 self.assertEqual(self.host.getSentMessage(0), None) # no new message has been sent |
340 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started | 336 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started |
341 | 337 |
342 # referee profile, user is allowed, wait for one more | 338 # referee profile, user is allowed, wait for one more |
343 room = self.plugin_0045.getRoom(0, 0) | 339 room = self.plugin_0045.getRoom(0, 0) |
344 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) | 340 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) |
345 nicks.append(user_nick) | 341 nicks.append(user_nick) |
346 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) | 342 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", nicks)) |
347 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started | 343 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started |
348 | 344 |
349 # referee profile, user is not allowed | 345 # referee profile, user is not allowed |
350 user_nick = self.plugin_0045.joinRoom(0, 4) | 346 user_nick = self.plugin_0045.joinRoom(0, 4) |
351 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) | 347 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
352 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks)) | 348 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(JID(ROOM_JID.userhost() + '/' + user_nick), "normal", "players", nicks)) |
353 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started | 349 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started |
354 | 350 |
355 # referee profile, user is allowed, everybody here | 351 # referee profile, user is allowed, everybody here |
356 user_nick = self.plugin_0045.joinRoom(0, 3) | 352 user_nick = self.plugin_0045.joinRoom(0, 3) |
357 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 353 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
358 nicks.append(user_nick) | 354 nicks.append(user_nick) |
359 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 355 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks)) |
360 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) # game started | 356 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) # game started |
361 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) | 357 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) |
362 | 358 |
363 # wait for none | 359 # wait for none |
364 self.reinit() | 360 self.reinit() |
365 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 361 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
366 self.assertNotEqual(self.host.getSentMessage(0), None) # init messages | 362 self.assertNotEqual(self.host.getSentMessage(0), None) # init messages |
367 room = self.plugin_0045.getRoom(0, 0) | 363 room = self.plugin_0045.getRoom(0, 0) |
368 nicks = [self.plugin_0045.getNick(0, 0)] | 364 nicks = [self.plugin_0045.getNick(0, 0)] |
369 user_nick = self.plugin_0045.joinRoom(0, 3) | 365 user_nick = self.plugin_0045.joinRoom(0, 3) |
370 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 366 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
371 nicks.append(user_nick) | 367 nicks.append(user_nick) |
372 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 368 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks)) |
373 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 369 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
374 | 370 |
375 def test_userLeftTrigger(self): | 371 def test_userLeftTrigger(self): |
376 self.reinit(player_init={"xxx": "xyz"}) | 372 self.reinit(player_init={"xxx": "xyz"}) |
377 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]] | 373 other_players = [Const.JID[1], Const.JID[3], Const.JID[4]] |
378 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 374 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) |
379 room = self.plugin_0045.getRoom(0, 0) | 375 room = self.plugin_0045.getRoom(0, 0) |
380 nicks = [self.plugin_0045.getNick(0, 0)] | 376 nicks = [self.plugin_0045.getNick(0, 0)] |
381 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()]) | 377 self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[1].userhostJID(), Const.JID[3].userhostJID(), Const.JID[4].userhostJID()]) |
382 | 378 |
383 # one user joins | 379 # one user joins |
384 user_nick = self.plugin_0045.joinRoom(0, 1) | 380 user_nick = self.plugin_0045.joinRoom(0, 1) |
385 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) | 381 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) |
386 nicks.append(user_nick) | 382 nicks.append(user_nick) |
387 | 383 |
388 # the user leaves | 384 # the user leaves |
389 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 385 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
390 room = self.plugin_0045.getRoom(0, 1) | 386 room = self.plugin_0045.getRoom(0, 1) |
391 # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile | 387 # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile |
392 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # not the referee | 388 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # not the referee |
393 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 389 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
394 room = self.plugin_0045.getRoom(0, 0) | 390 room = self.plugin_0045.getRoom(0, 0) |
395 user_nick = self.plugin_0045.leaveRoom(0, 1) | 391 user_nick = self.plugin_0045.leaveRoom(0, 1) |
396 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee | 392 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee |
397 nicks.pop() | 393 nicks.pop() |
398 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 394 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
399 | 395 |
400 # all the users join | 396 # all the users join |
401 user_nick = self.plugin_0045.joinRoom(0, 1) | 397 user_nick = self.plugin_0045.joinRoom(0, 1) |
402 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) | 398 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) |
403 nicks.append(user_nick) | 399 nicks.append(user_nick) |
405 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 401 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
406 nicks.append(user_nick) | 402 nicks.append(user_nick) |
407 user_nick = self.plugin_0045.joinRoom(0, 4) | 403 user_nick = self.plugin_0045.joinRoom(0, 4) |
408 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) | 404 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
409 nicks.append(user_nick) | 405 nicks.append(user_nick) |
410 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 406 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
411 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) | 407 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) |
412 | 408 |
413 # one user leaves | 409 # one user leaves |
414 user_nick = self.plugin_0045.leaveRoom(0, 4) | 410 user_nick = self.plugin_0045.leaveRoom(0, 4) |
415 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) | 411 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
416 nicks.pop() | 412 nicks.pop() |
417 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost()]) | 413 self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()]) |
418 | 414 |
419 # another leaves | 415 # another leaves |
420 user_nick = self.plugin_0045.leaveRoom(0, 3) | 416 user_nick = self.plugin_0045.leaveRoom(0, 3) |
421 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 417 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
422 nicks.pop() | 418 nicks.pop() |
423 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost(), Const.JID[3].userhost()]) | 419 self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()]) |
424 | 420 |
425 # they can join again | 421 # they can join again |
426 user_nick = self.plugin_0045.joinRoom(0, 3) | 422 user_nick = self.plugin_0045.joinRoom(0, 3) |
427 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 423 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
428 nicks.append(user_nick) | 424 nicks.append(user_nick) |
429 user_nick = self.plugin_0045.joinRoom(0, 4) | 425 user_nick = self.plugin_0045.joinRoom(0, 4) |
430 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) | 426 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
431 nicks.append(user_nick) | 427 nicks.append(user_nick) |
432 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 428 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
433 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) | 429 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) |
434 | 430 |
435 def test__checkCreateGameAndInit(self): | 431 def test__checkCreateGameAndInit(self): |
436 self.reinit() | 432 self.reinit() |
437 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error | 433 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) # print internal error |
438 | 434 |
439 nick = self.plugin_0045.joinRoom(0, 0) | 435 nick = self.plugin_0045.joinRoom(0, 0) |
440 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 436 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) |
441 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) | 437 self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) |
442 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) | 438 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) |
443 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, nick)) | 439 self.assertTrue(self.plugin.isReferee(ROOM_JID, nick)) |
444 | 440 |
445 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) # print internal error | 441 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) # print internal error |
446 | 442 |
447 self.plugin_0045.joinRoom(0, 1) | 443 self.plugin_0045.joinRoom(0, 1) |
448 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) | 444 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) |
449 | 445 |
450 self.plugin.createGame(ROOM_JID_S, [Const.JID_STR[1]], PROFILE) | 446 self.plugin.createGame(ROOM_JID, [Const.JID[1]], PROFILE) |
451 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 447 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) |
452 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) | 448 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) |
453 | 449 |
454 def test_createGame(self): | 450 def test_createGame(self): |
455 | 451 |
456 self.reinit(player_init={"xxx": "xyz"}) | 452 self.reinit(player_init={"xxx": "xyz"}) |
457 nicks = [] | 453 nicks = [] |
458 for i in [0, 1, 3, 4]: | 454 for i in [0, 1, 3, 4]: |
459 nicks.append(self.plugin_0045.joinRoom(0, i)) | 455 nicks.append(self.plugin_0045.joinRoom(0, i)) |
460 | 456 |
461 # game not exists | 457 # game not exists |
462 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) | 458 self.plugin.createGame(ROOM_JID, nicks, PROFILE) |
463 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 459 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) |
464 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 460 self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks) |
465 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 461 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks)) |
466 for nick in nicks: | 462 for nick in nicks: |
467 self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick]) | 463 self.assertEqual('init', self.plugin.games[ROOM_JID]['status'][nick]) |
468 self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick]) | 464 self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID]['players_data'][nick]) |
469 self.plugin.games[ROOM_JID_S]['players_data'][nick]["xxx"] = nick | 465 self.plugin.games[ROOM_JID]['players_data'][nick]["xxx"] = nick |
470 for nick in nicks: | 466 for nick in nicks: |
471 # checks that a copy of self.player_init has been done and not a reference | 467 # checks that a copy of self.player_init has been done and not a reference |
472 self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx']) | 468 self.assertEqual(nick, self.plugin.games[ROOM_JID]['players_data'][nick]['xxx']) |
473 | 469 |
474 # game exists, current profile is referee | 470 # game exists, current profile is referee |
475 self.reinit(player_init={"xxx": "xyz"}) | 471 self.reinit(player_init={"xxx": "xyz"}) |
476 self.initGame(0, 0) | 472 self.initGame(0, 0) |
477 self.plugin.games[ROOM_JID_S]['started'] = True | 473 self.plugin.games[ROOM_JID]['started'] = True |
478 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) | 474 self.plugin.createGame(ROOM_JID, nicks, PROFILE) |
479 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 475 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks)) |
480 | 476 |
481 # game exists, current profile is not referee | 477 # game exists, current profile is not referee |
482 self.reinit(player_init={"xxx": "xyz"}) | 478 self.reinit(player_init={"xxx": "xyz"}) |
483 self.initGame(0, 0) | 479 self.initGame(0, 0) |
484 self.plugin.games[ROOM_JID_S]['started'] = True | 480 self.plugin.games[ROOM_JID]['started'] = True |
485 self.plugin_0045.joinRoom(0, 1) | 481 self.plugin_0045.joinRoom(0, 1) |
486 self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE) | 482 self.plugin.createGame(ROOM_JID, nicks, OTHER_PROFILE) |
487 self.assertEqual(self.host.getSentMessage(0), None) # no sync message has been sent by other_profile | 483 self.assertEqual(self.host.getSentMessage(0), None) # no sync message has been sent by other_profile |