Mercurial > libervia-backend
comparison src/test/test_plugin_misc_room_game.py @ 1271:2308f8405ffb
test: refactoring:
- rename internal init methods to reinit
- rename getSentMessage to getSentMessageXml
- rename getSentMessageRaw to getSentMessage
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 19 Dec 2014 11:36:00 +0100 |
parents | b3f383ab39da |
children | 069ad98b360d |
comparison
equal
deleted
inserted
replaced
1270:037ec0795a85 | 1271:2308f8405ffb |
---|---|
52 class RoomGameTest(helpers.SatTestCase): | 52 class RoomGameTest(helpers.SatTestCase): |
53 | 53 |
54 def setUp(self): | 54 def setUp(self): |
55 self.host = helpers.FakeSAT() | 55 self.host = helpers.FakeSAT() |
56 | 56 |
57 def init(self, game_init={}, player_init={}): | 57 def reinit(self, game_init={}, player_init={}): |
58 self.host.init() | 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() | 63 logger = getLogger() |
81 content += "<player index='%s'>%s</player>" % (i, players[i]) | 81 content += "<player index='%s'>%s</player>" % (i, players[i]) |
82 content += "</%s>" % tag | 82 content += "</%s>" % tag |
83 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content) | 83 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content) |
84 | 84 |
85 def test_createOrInvite_solo(self): | 85 def test_createOrInvite_solo(self): |
86 self.init() | 86 self.reinit() |
87 self.plugin_0045.joinRoom(0, 0) | 87 self.plugin_0045.joinRoom(0, 0) |
88 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) | 88 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) |
89 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 89 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
90 | 90 |
91 def test_createOrInvite_multi_not_waiting(self): | 91 def test_createOrInvite_multi_not_waiting(self): |
92 self.init() | 92 self.reinit() |
93 self.plugin_0045.joinRoom(0, 0) | 93 self.plugin_0045.joinRoom(0, 0) |
94 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 94 other_players = [Const.JID_STR[1], Const.JID_STR[2]] |
95 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) | 95 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) |
96 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 96 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
97 | 97 |
98 def test_createOrInvite_multi_waiting(self): | 98 def test_createOrInvite_multi_waiting(self): |
99 self.init(player_init={'score': 0}) | 99 self.reinit(player_init={'score': 0}) |
100 self.plugin_0045.joinRoom(0, 0) | 100 self.plugin_0045.joinRoom(0, 0) |
101 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 101 other_players = [Const.JID_STR[1], Const.JID_STR[2]] |
102 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) | 102 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) |
103 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) | 103 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) |
104 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) | 104 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) |
105 | 105 |
106 def test_initGame(self): | 106 def test_initGame(self): |
107 self.init() | 107 self.reinit() |
108 self.initGame(0, 0) | 108 self.initGame(0, 0) |
109 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) | 109 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) |
110 self.assertEqual([], self.plugin.games[ROOM_JID_S]['players']) | 110 self.assertEqual([], self.plugin.games[ROOM_JID_S]['players']) |
111 | 111 |
112 def test_checkJoinAuth(self): | 112 def test_checkJoinAuth(self): |
113 self.init() | 113 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)) | 114 check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user)) |
115 check(False) | 115 check(False) |
116 # to test the "invited" mode, the referee must be different than the user to test | 116 # to test the "invited" mode, the referee must be different than the user to test |
117 self.initGame(0, 1) | 117 self.initGame(0, 1) |
118 self.plugin.join_mode = self.plugin.ALL | 118 self.plugin.join_mode = self.plugin.ALL |
125 check(False) | 125 check(False) |
126 self.plugin.games[ROOM_JID_S]['players'].append(Const.JID[0].user) | 126 self.plugin.games[ROOM_JID_S]['players'].append(Const.JID[0].user) |
127 check(True) | 127 check(True) |
128 | 128 |
129 def test_updatePlayers(self): | 129 def test_updatePlayers(self): |
130 self.init() | 130 self.reinit() |
131 self.initGame(0, 0) | 131 self.initGame(0, 0) |
132 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) | 132 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) |
133 self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0]) | 133 self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0]) |
134 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) | 134 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) |
135 self.plugin._updatePlayers(ROOM_JID_S, ["user1"], True, Const.PROFILE[0]) | 135 self.plugin._updatePlayers(ROOM_JID_S, ["user1"], True, Const.PROFILE[0]) |
138 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) | 138 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) |
139 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice | 139 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice |
140 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) | 140 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) |
141 | 141 |
142 def test_synchronizeRoom(self): | 142 def test_synchronizeRoom(self): |
143 self.init() | 143 self.reinit() |
144 self.initGame(0, 0) | 144 self.initGame(0, 0) |
145 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 145 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
146 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", [])) | 146 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", [])) |
147 self.plugin.games[ROOM_JID_S]['players'].append("test1") | 147 self.plugin.games[ROOM_JID_S]['players'].append("test1") |
148 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 148 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
149 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"])) | 149 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"])) |
150 self.plugin.games[ROOM_JID_S]['started'] = True | 150 self.plugin.games[ROOM_JID_S]['started'] = True |
151 self.plugin.games[ROOM_JID_S]['players'].append("test2") | 151 self.plugin.games[ROOM_JID_S]['players'].append("test2") |
152 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) | 152 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
153 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"])) | 153 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"])) |
154 self.plugin.games[ROOM_JID_S]['players'].append("test3") | 154 self.plugin.games[ROOM_JID_S]['players'].append("test3") |
155 self.plugin.games[ROOM_JID_S]['players'].append("test4") | 155 self.plugin.games[ROOM_JID_S]['players'].append("test4") |
156 user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user) | 156 user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user) |
157 user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user) | 157 user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user) |
158 self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0]) | 158 self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0]) |
159 self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) | 159 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) |
160 self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) | 160 self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) |
161 | 161 |
162 def test_invitePlayers(self): | 162 def test_invitePlayers(self): |
163 self.init() | 163 self.reinit() |
164 self.initGame(0, 0) | 164 self.initGame(0, 0) |
165 self.plugin_0045.joinRoom(0, 1) | 165 self.plugin_0045.joinRoom(0, 1) |
166 self.assertEqual(self.plugin.invitations[ROOM_JID_S], []) | 166 self.assertEqual(self.plugin.invitations[ROOM_JID_S], []) |
167 room = self.plugin_0045.getRoom(0, 0) | 167 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]) | 168 nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[2]], Const.JID[0].user, Const.PROFILE[0]) |
179 | 179 |
180 def check(value, index): | 180 def check(value, index): |
181 nick = self.plugin_0045.getNick(0, index) | 181 nick = self.plugin_0045.getNick(0, index) |
182 getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID_S, nick)) | 182 getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID_S, nick)) |
183 | 183 |
184 self.init() | 184 self.reinit() |
185 | 185 |
186 for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]: | 186 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 | 187 self.plugin.invite_mode = mode |
188 check(True, 0) | 188 check(True, 0) |
189 | 189 |
203 check(True, 0) | 203 check(True, 0) |
204 check(True, 1) | 204 check(True, 1) |
205 check(False, 2) | 205 check(False, 2) |
206 | 206 |
207 def test_isReferee(self): | 207 def test_isReferee(self): |
208 self.init() | 208 self.reinit() |
209 self.initGame(0, 0) | 209 self.initGame(0, 0) |
210 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) | 210 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) |
211 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1))) | 211 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1))) |
212 | 212 |
213 def test_isPlayer(self): | 213 def test_isPlayer(self): |
214 self.init() | 214 self.reinit() |
215 self.initGame(0, 0) | 215 self.initGame(0, 0) |
216 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) | 216 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) |
217 user_nick = self.plugin_0045.joinRoom(0, 1) | 217 user_nick = self.plugin_0045.joinRoom(0, 1) |
218 self.plugin.games[ROOM_JID_S]['players'].append(user_nick) | 218 self.plugin.games[ROOM_JID_S]['players'].append(user_nick) |
219 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) | 219 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) |
223 | 223 |
224 def check(value, other_players, confirmed, rest): | 224 def check(value, other_players, confirmed, rest): |
225 room = self.plugin_0045.getRoom(0, 0) | 225 room = self.plugin_0045.getRoom(0, 0) |
226 self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players)) | 226 self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players)) |
227 | 227 |
228 self.init() | 228 self.reinit() |
229 self.initGame(0, 0) | 229 self.initGame(0, 0) |
230 other_players = [Const.JID[1], Const.JID[3]] | 230 other_players = [Const.JID[1], Const.JID[3]] |
231 self.plugin.wait_mode = self.plugin.FOR_NONE | 231 self.plugin.wait_mode = self.plugin.FOR_NONE |
232 check(True, [], [], []) | 232 check(True, [], [], []) |
233 check(True, [Const.JID[0]], [], [Const.JID[0]]) # getRoomNickOfUser checks for the other users only | 233 check(True, [Const.JID[0]], [], [Const.JID[0]]) # getRoomNickOfUser checks for the other users only |
249 check(True, other_players, [self.plugin_0045.getNickOfUser(0, 1, 0), | 249 check(True, other_players, [self.plugin_0045.getNickOfUser(0, 1, 0), |
250 self.plugin_0045.getNickOfUser(0, 3, 0), | 250 self.plugin_0045.getNickOfUser(0, 3, 0), |
251 self.plugin_0045.getNickOfUser(0, 2, 0)], []) | 251 self.plugin_0045.getNickOfUser(0, 2, 0)], []) |
252 | 252 |
253 def test_prepareRoom_trivial(self): | 253 def test_prepareRoom_trivial(self): |
254 self.init() | 254 self.reinit() |
255 other_players = [] | 255 other_players = [] |
256 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 256 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
257 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 257 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
258 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user)) | 258 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user)) |
259 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[0].user)) | 259 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[0].user)) |
261 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) | 261 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) |
262 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[0].user)) | 262 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[0].user)) |
263 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 263 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) |
264 | 264 |
265 def test_prepareRoom_invite(self): | 265 def test_prepareRoom_invite(self): |
266 self.init() | 266 self.reinit() |
267 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 267 other_players = [Const.JID_STR[1], Const.JID_STR[2]] |
268 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 268 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
269 room = self.plugin_0045.getRoom(0, 0) | 269 room = self.plugin_0045.getRoom(0, 0) |
270 | 270 |
271 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 271 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
283 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0))) | 283 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0))) |
284 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, Const.JID_STR[3])) | 284 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, Const.JID_STR[3])) |
285 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1])) | 285 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1])) |
286 | 286 |
287 def test_prepareRoom_score1(self): | 287 def test_prepareRoom_score1(self): |
288 self.init(player_init={'score': 0}) | 288 self.reinit(player_init={'score': 0}) |
289 other_players = [Const.JID_STR[1], Const.JID_STR[2]] | 289 other_players = [Const.JID_STR[1], Const.JID_STR[2]] |
290 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 290 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
291 room = self.plugin_0045.getRoom(0, 0) | 291 room = self.plugin_0045.getRoom(0, 0) |
292 | 292 |
293 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) | 293 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) |
309 # but Const.JID[3] is actually not in the room | 309 # but Const.JID[3] is actually not in the room |
310 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) | 310 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) |
311 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0])) | 311 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0])) |
312 | 312 |
313 def test_prepareRoom_score2(self): | 313 def test_prepareRoom_score2(self): |
314 self.init(player_init={'score': 0}) | 314 self.reinit(player_init={'score': 0}) |
315 other_players = [Const.JID_STR[1], Const.JID_STR[4]] | 315 other_players = [Const.JID_STR[1], Const.JID_STR[4]] |
316 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 316 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
317 room = self.plugin_0045.getRoom(0, 0) | 317 room = self.plugin_0045.getRoom(0, 0) |
318 | 318 |
319 user_nick = self.plugin_0045.joinRoom(0, 1) | 319 user_nick = self.plugin_0045.joinRoom(0, 1) |
322 user_nick = self.plugin_0045.joinRoom(0, 4) | 322 user_nick = self.plugin_0045.joinRoom(0, 4) |
323 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) | 323 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) |
324 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 324 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) |
325 | 325 |
326 def test_userJoinedTrigger(self): | 326 def test_userJoinedTrigger(self): |
327 self.init(player_init={"xxx": "xyz"}) | 327 self.reinit(player_init={"xxx": "xyz"}) |
328 other_players = [Const.JID_STR[1], Const.JID_STR[3]] | 328 other_players = [Const.JID_STR[1], Const.JID_STR[3]] |
329 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 329 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
330 nicks = [self.plugin_0045.getNick(0, 0)] | 330 nicks = [self.plugin_0045.getNick(0, 0)] |
331 | 331 |
332 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) | 332 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) |
333 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1) | 333 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1) |
334 | 334 |
335 # wrong profile | 335 # wrong profile |
336 user_nick = self.plugin_0045.joinRoom(0, 1) | 336 user_nick = self.plugin_0045.joinRoom(0, 1) |
337 room = self.plugin_0045.getRoom(0, 1) | 337 room = self.plugin_0045.getRoom(0, 1) |
338 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) | 338 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) |
339 self.assertEqual(self.host.getSentMessageRaw(0), None) # no new message has been sent | 339 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 | 340 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started |
341 | 341 |
342 # referee profile, user is allowed, wait for one more | 342 # referee profile, user is allowed, wait for one more |
343 room = self.plugin_0045.getRoom(0, 0) | 343 room = self.plugin_0045.getRoom(0, 0) |
344 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) | 344 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) |
345 nicks.append(user_nick) | 345 nicks.append(user_nick) |
346 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) | 346 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) |
347 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started | 347 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started |
348 | 348 |
349 # referee profile, user is not allowed | 349 # referee profile, user is not allowed |
350 user_nick = self.plugin_0045.joinRoom(0, 4) | 350 user_nick = self.plugin_0045.joinRoom(0, 4) |
351 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) | 351 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
352 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks)) | 352 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks)) |
353 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started | 353 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started |
354 | 354 |
355 # referee profile, user is allowed, everybody here | 355 # referee profile, user is allowed, everybody here |
356 user_nick = self.plugin_0045.joinRoom(0, 3) | 356 user_nick = self.plugin_0045.joinRoom(0, 3) |
357 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 357 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
358 nicks.append(user_nick) | 358 nicks.append(user_nick) |
359 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 359 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
360 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) # game started | 360 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) # game started |
361 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) | 361 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) |
362 | 362 |
363 # wait for none | 363 # wait for none |
364 self.init() | 364 self.reinit() |
365 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 365 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
366 self.assertNotEqual(self.host.getSentMessageRaw(0), None) # init messages | 366 self.assertNotEqual(self.host.getSentMessage(0), None) # init messages |
367 room = self.plugin_0045.getRoom(0, 0) | 367 room = self.plugin_0045.getRoom(0, 0) |
368 nicks = [self.plugin_0045.getNick(0, 0)] | 368 nicks = [self.plugin_0045.getNick(0, 0)] |
369 user_nick = self.plugin_0045.joinRoom(0, 3) | 369 user_nick = self.plugin_0045.joinRoom(0, 3) |
370 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) | 370 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) |
371 nicks.append(user_nick) | 371 nicks.append(user_nick) |
372 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 372 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
373 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 373 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
374 | 374 |
375 def test_userLeftTrigger(self): | 375 def test_userLeftTrigger(self): |
376 self.init(player_init={"xxx": "xyz"}) | 376 self.reinit(player_init={"xxx": "xyz"}) |
377 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]] | 377 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]] |
378 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) | 378 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) |
379 room = self.plugin_0045.getRoom(0, 0) | 379 room = self.plugin_0045.getRoom(0, 0) |
380 nicks = [self.plugin_0045.getNick(0, 0)] | 380 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()]) | 381 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()]) |
431 nicks.append(user_nick) | 431 nicks.append(user_nick) |
432 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 432 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) |
433 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) | 433 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) |
434 | 434 |
435 def test__checkCreateGameAndInit(self): | 435 def test__checkCreateGameAndInit(self): |
436 self.init() | 436 self.reinit() |
437 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error | 437 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error |
438 | 438 |
439 nick = self.plugin_0045.joinRoom(0, 0) | 439 nick = self.plugin_0045.joinRoom(0, 0) |
440 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 440 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) |
441 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) | 441 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False)) |
451 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) | 451 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) |
452 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) | 452 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) |
453 | 453 |
454 def test_createGame(self): | 454 def test_createGame(self): |
455 | 455 |
456 self.init(player_init={"xxx": "xyz"}) | 456 self.reinit(player_init={"xxx": "xyz"}) |
457 nicks = [] | 457 nicks = [] |
458 for i in [0, 1, 3, 4]: | 458 for i in [0, 1, 3, 4]: |
459 nicks.append(self.plugin_0045.joinRoom(0, i)) | 459 nicks.append(self.plugin_0045.joinRoom(0, i)) |
460 | 460 |
461 # game not exists | 461 # game not exists |
462 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) | 462 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) |
463 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 463 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
464 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) | 464 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) |
465 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 465 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
466 for nick in nicks: | 466 for nick in nicks: |
467 self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick]) | 467 self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick]) |
468 self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick]) | 468 self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick]) |
469 self.plugin.games[ROOM_JID_S]['players_data'][nick]["xxx"] = nick | 469 self.plugin.games[ROOM_JID_S]['players_data'][nick]["xxx"] = nick |
470 for nick in nicks: | 470 for nick in nicks: |
471 # checks that a copy of self.player_init has been done and not a reference | 471 # 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']) | 472 self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx']) |
473 | 473 |
474 # game exists, current profile is referee | 474 # game exists, current profile is referee |
475 self.init(player_init={"xxx": "xyz"}) | 475 self.reinit(player_init={"xxx": "xyz"}) |
476 self.initGame(0, 0) | 476 self.initGame(0, 0) |
477 self.plugin.games[ROOM_JID_S]['started'] = True | 477 self.plugin.games[ROOM_JID_S]['started'] = True |
478 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) | 478 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) |
479 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) | 479 self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
480 | 480 |
481 # game exists, current profile is not referee | 481 # game exists, current profile is not referee |
482 self.init(player_init={"xxx": "xyz"}) | 482 self.reinit(player_init={"xxx": "xyz"}) |
483 self.initGame(0, 0) | 483 self.initGame(0, 0) |
484 self.plugin.games[ROOM_JID_S]['started'] = True | 484 self.plugin.games[ROOM_JID_S]['started'] = True |
485 self.plugin_0045.joinRoom(0, 1) | 485 self.plugin_0045.joinRoom(0, 1) |
486 self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE) | 486 self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE) |
487 self.assertEqual(self.host.getSentMessageRaw(0), None) # no sync message has been sent by other_profile | 487 self.assertEqual(self.host.getSentMessage(0), None) # no sync message has been sent by other_profile |