comparison sat/test/test_plugin_misc_room_game.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
63 ) 63 )
64 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249( 64 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249(
65 self.host 65 self.host
66 ) 66 )
67 for profile in Const.PROFILE: 67 for profile in Const.PROFILE:
68 self.host.getClient(profile) # init self.host.profiles[profile] 68 self.host.get_client(profile) # init self.host.profiles[profile]
69 69
70 def initGame(self, muc_index, user_index): 70 def init_game(self, muc_index, user_index):
71 self.plugin_0045.joinRoom(user_index, muc_index) 71 self.plugin_0045.join_room(user_index, muc_index)
72 self.plugin._initGame(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user) 72 self.plugin._init_game(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user)
73 73
74 def _expectedMessage(self, to, type_, tag, players=[]): 74 def _expected_message(self, to, type_, tag, players=[]):
75 content = "<%s" % tag 75 content = "<%s" % tag
76 if not players: 76 if not players:
77 content += "/>" 77 content += "/>"
78 else: 78 else:
79 content += ">" 79 content += ">"
86 TAG, 86 TAG,
87 NAMESERVICE, 87 NAMESERVICE,
88 content, 88 content,
89 ) 89 )
90 90
91 def test_createOrInvite_solo(self): 91 def test_create_or_invite_solo(self):
92 self.reinit() 92 self.reinit()
93 self.plugin_0045.joinRoom(0, 0) 93 self.plugin_0045.join_room(0, 0)
94 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) 94 self.plugin._create_or_invite(self.plugin_0045.get_room(0, 0), [], Const.PROFILE[0])
95 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 95 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
96 96
97 def test_createOrInvite_multi_not_waiting(self): 97 def test_create_or_invite_multi_not_waiting(self):
98 self.reinit() 98 self.reinit()
99 self.plugin_0045.joinRoom(0, 0) 99 self.plugin_0045.join_room(0, 0)
100 other_players = [Const.JID[1], Const.JID[2]] 100 other_players = [Const.JID[1], Const.JID[2]]
101 self.plugin._createOrInvite( 101 self.plugin._create_or_invite(
102 self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0] 102 self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
103 ) 103 )
104 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 104 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
105 105
106 def test_createOrInvite_multi_waiting(self): 106 def test_create_or_invite_multi_waiting(self):
107 self.reinit(player_init={"score": 0}) 107 self.reinit(player_init={"score": 0})
108 self.plugin_0045.joinRoom(0, 0) 108 self.plugin_0045.join_room(0, 0)
109 other_players = [Const.JID[1], Const.JID[2]] 109 other_players = [Const.JID[1], Const.JID[2]]
110 self.plugin._createOrInvite( 110 self.plugin._create_or_invite(
111 self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0] 111 self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
112 ) 112 )
113 self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) 113 self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
114 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) 114 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
115 115
116 def test_initGame(self): 116 def test_init_game(self):
117 self.reinit() 117 self.reinit()
118 self.initGame(0, 0) 118 self.init_game(0, 0)
119 self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) 119 self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
120 self.assertEqual([], self.plugin.games[ROOM_JID]["players"]) 120 self.assertEqual([], self.plugin.games[ROOM_JID]["players"])
121 121
122 def test_checkJoinAuth(self): 122 def test_check_join_auth(self):
123 self.reinit() 123 self.reinit()
124 check = lambda value: getattr(self, "assert%s" % value)( 124 check = lambda value: getattr(self, "assert%s" % value)(
125 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user) 125 self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
126 ) 126 )
127 check(False) 127 check(False)
128 # to test the "invited" mode, the referee must be different than the user to test 128 # to test the "invited" mode, the referee must be different than the user to test
129 self.initGame(0, 1) 129 self.init_game(0, 1)
130 self.plugin.join_mode = self.plugin.ALL 130 self.plugin.join_mode = self.plugin.ALL
131 check(True) 131 check(True)
132 self.plugin.join_mode = self.plugin.INVITED 132 self.plugin.join_mode = self.plugin.INVITED
133 check(False) 133 check(False)
134 self.plugin.invitations[ROOM_JID] = [(None, [Const.JID[0].userhostJID()])] 134 self.plugin.invitations[ROOM_JID] = [(None, [Const.JID[0].userhostJID()])]
136 self.plugin.join_mode = self.plugin.NONE 136 self.plugin.join_mode = self.plugin.NONE
137 check(False) 137 check(False)
138 self.plugin.games[ROOM_JID]["players"].append(Const.JID[0].user) 138 self.plugin.games[ROOM_JID]["players"].append(Const.JID[0].user)
139 check(True) 139 check(True)
140 140
141 def test_updatePlayers(self): 141 def test_update_players(self):
142 self.reinit() 142 self.reinit()
143 self.initGame(0, 0) 143 self.init_game(0, 0)
144 self.assertEqual(self.plugin.games[ROOM_JID]["players"], []) 144 self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
145 self.plugin._updatePlayers(ROOM_JID, [], True, Const.PROFILE[0]) 145 self.plugin._update_players(ROOM_JID, [], True, Const.PROFILE[0])
146 self.assertEqual(self.plugin.games[ROOM_JID]["players"], []) 146 self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
147 self.plugin._updatePlayers(ROOM_JID, ["user1"], True, Const.PROFILE[0]) 147 self.plugin._update_players(ROOM_JID, ["user1"], True, Const.PROFILE[0])
148 self.assertEqual(self.plugin.games[ROOM_JID]["players"], ["user1"]) 148 self.assertEqual(self.plugin.games[ROOM_JID]["players"], ["user1"])
149 self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) 149 self.plugin._update_players(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0])
150 self.assertEqual( 150 self.assertEqual(
151 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"] 151 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
152 ) 152 )
153 self.plugin._updatePlayers( 153 self.plugin._update_players(
154 ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0] 154 ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]
155 ) # should not be stored twice 155 ) # should not be stored twice
156 self.assertEqual( 156 self.assertEqual(
157 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"] 157 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
158 ) 158 )
159 159
160 def test_synchronizeRoom(self): 160 def test_synchronize_room(self):
161 self.reinit() 161 self.reinit()
162 self.initGame(0, 0) 162 self.init_game(0, 0)
163 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) 163 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
164 self.assertEqual( 164 self.assertEqual(
165 self.host.getSentMessageXml(0), 165 self.host.get_sent_message_xml(0),
166 self._expectedMessage(ROOM_JID, "groupchat", "players", []), 166 self._expected_message(ROOM_JID, "groupchat", "players", []),
167 ) 167 )
168 self.plugin.games[ROOM_JID]["players"].append("test1") 168 self.plugin.games[ROOM_JID]["players"].append("test1")
169 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) 169 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
170 self.assertEqual( 170 self.assertEqual(
171 self.host.getSentMessageXml(0), 171 self.host.get_sent_message_xml(0),
172 self._expectedMessage(ROOM_JID, "groupchat", "players", ["test1"]), 172 self._expected_message(ROOM_JID, "groupchat", "players", ["test1"]),
173 ) 173 )
174 self.plugin.games[ROOM_JID]["started"] = True 174 self.plugin.games[ROOM_JID]["started"] = True
175 self.plugin.games[ROOM_JID]["players"].append("test2") 175 self.plugin.games[ROOM_JID]["players"].append("test2")
176 self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) 176 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
177 self.assertEqual( 177 self.assertEqual(
178 self.host.getSentMessageXml(0), 178 self.host.get_sent_message_xml(0),
179 self._expectedMessage(ROOM_JID, "groupchat", "started", ["test1", "test2"]), 179 self._expected_message(ROOM_JID, "groupchat", "started", ["test1", "test2"]),
180 ) 180 )
181 self.plugin.games[ROOM_JID]["players"].append("test3") 181 self.plugin.games[ROOM_JID]["players"].append("test3")
182 self.plugin.games[ROOM_JID]["players"].append("test4") 182 self.plugin.games[ROOM_JID]["players"].append("test4")
183 user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user) 183 user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
184 user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user) 184 user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user)
185 self.plugin._synchronizeRoom(ROOM_JID, [user1, user2], Const.PROFILE[0]) 185 self.plugin._synchronize_room(ROOM_JID, [user1, user2], Const.PROFILE[0])
186 self.assertEqualXML( 186 self.assert_equal_xml(
187 self.host.getSentMessageXml(0), 187 self.host.get_sent_message_xml(0),
188 self._expectedMessage( 188 self._expected_message(
189 user1, "normal", "started", ["test1", "test2", "test3", "test4"] 189 user1, "normal", "started", ["test1", "test2", "test3", "test4"]
190 ), 190 ),
191 ) 191 )
192 self.assertEqualXML( 192 self.assert_equal_xml(
193 self.host.getSentMessageXml(0), 193 self.host.get_sent_message_xml(0),
194 self._expectedMessage( 194 self._expected_message(
195 user2, "normal", "started", ["test1", "test2", "test3", "test4"] 195 user2, "normal", "started", ["test1", "test2", "test3", "test4"]
196 ), 196 ),
197 ) 197 )
198 198
199 def test_invitePlayers(self): 199 def test_invite_players(self):
200 self.reinit() 200 self.reinit()
201 self.initGame(0, 0) 201 self.init_game(0, 0)
202 self.plugin_0045.joinRoom(0, 1) 202 self.plugin_0045.join_room(0, 1)
203 self.assertEqual(self.plugin.invitations[ROOM_JID], []) 203 self.assertEqual(self.plugin.invitations[ROOM_JID], [])
204 room = self.plugin_0045.getRoom(0, 0) 204 room = self.plugin_0045.get_room(0, 0)
205 nicks = self.plugin._invitePlayers( 205 nicks = self.plugin._invite_players(
206 room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0] 206 room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0]
207 ) 207 )
208 self.assertEqual( 208 self.assertEqual(
209 self.plugin.invitations[ROOM_JID][0][1], 209 self.plugin.invitations[ROOM_JID][0][1],
210 [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()], 210 [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()],
211 ) 211 )
212 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost 212 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
213 self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user]) 213 self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user])
214 214
215 nicks = self.plugin._invitePlayers( 215 nicks = self.plugin._invite_players(
216 room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0] 216 room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0]
217 ) 217 )
218 self.assertEqual( 218 self.assertEqual(
219 self.plugin.invitations[ROOM_JID][1][1], 219 self.plugin.invitations[ROOM_JID][1][1],
220 [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()], 220 [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()],
221 ) 221 )
222 # this time Const.JID[1] and Const.JID[3] have the same user but the host differs 222 # this time Const.JID[1] and Const.JID[3] have the same user but the host differs
223 self.assertEqual(nicks, [Const.JID[1].user]) 223 self.assertEqual(nicks, [Const.JID[1].user])
224 224
225 def test_checkInviteAuth(self): 225 def test_check_invite_auth(self):
226 def check(value, index): 226 def check(value, index):
227 nick = self.plugin_0045.getNick(0, index) 227 nick = self.plugin_0045.get_nick(0, index)
228 getattr(self, "assert%s" % value)( 228 getattr(self, "assert%s" % value)(
229 self.plugin._checkInviteAuth(ROOM_JID, nick) 229 self.plugin._check_invite_auth(ROOM_JID, nick)
230 ) 230 )
231 231
232 self.reinit() 232 self.reinit()
233 233
234 for mode in [ 234 for mode in [
238 self.plugin.FROM_PLAYERS, 238 self.plugin.FROM_PLAYERS,
239 ]: 239 ]:
240 self.plugin.invite_mode = mode 240 self.plugin.invite_mode = mode
241 check(True, 0) 241 check(True, 0)
242 242
243 self.initGame(0, 0) 243 self.init_game(0, 0)
244 self.plugin.invite_mode = self.plugin.FROM_ALL 244 self.plugin.invite_mode = self.plugin.FROM_ALL
245 check(True, 0) 245 check(True, 0)
246 check(True, 1) 246 check(True, 1)
247 self.plugin.invite_mode = self.plugin.FROM_NONE 247 self.plugin.invite_mode = self.plugin.FROM_NONE
248 check(True, 0) # game initialized but not started yet, referee can invite 248 check(True, 0) # game initialized but not started yet, referee can invite
249 check(False, 1) 249 check(False, 1)
250 self.plugin.invite_mode = self.plugin.FROM_REFEREE 250 self.plugin.invite_mode = self.plugin.FROM_REFEREE
251 check(True, 0) 251 check(True, 0)
252 check(False, 1) 252 check(False, 1)
253 user_nick = self.plugin_0045.joinRoom(0, 1) 253 user_nick = self.plugin_0045.join_room(0, 1)
254 self.plugin.games[ROOM_JID]["players"].append(user_nick) 254 self.plugin.games[ROOM_JID]["players"].append(user_nick)
255 self.plugin.invite_mode = self.plugin.FROM_PLAYERS 255 self.plugin.invite_mode = self.plugin.FROM_PLAYERS
256 check(True, 0) 256 check(True, 0)
257 check(True, 1) 257 check(True, 1)
258 check(False, 2) 258 check(False, 2)
259 259
260 def test_isReferee(self): 260 def test_is_referee(self):
261 self.reinit() 261 self.reinit()
262 self.initGame(0, 0) 262 self.init_game(0, 0)
263 self.assertTrue(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 0))) 263 self.assertTrue(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
264 self.assertFalse(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 1))) 264 self.assertFalse(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 1)))
265 265
266 def test_isPlayer(self): 266 def test_is_player(self):
267 self.reinit() 267 self.reinit()
268 self.initGame(0, 0) 268 self.init_game(0, 0)
269 self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 0))) 269 self.assertTrue(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
270 user_nick = self.plugin_0045.joinRoom(0, 1) 270 user_nick = self.plugin_0045.join_room(0, 1)
271 self.plugin.games[ROOM_JID]["players"].append(user_nick) 271 self.plugin.games[ROOM_JID]["players"].append(user_nick)
272 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) 272 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
273 self.assertFalse(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 2))) 273 self.assertFalse(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 2)))
274 274
275 def test_checkWaitAuth(self): 275 def test_check_wait_auth(self):
276 def check(value, other_players, confirmed, rest): 276 def check(value, other_players, confirmed, rest):
277 room = self.plugin_0045.getRoom(0, 0) 277 room = self.plugin_0045.get_room(0, 0)
278 self.assertEqual( 278 self.assertEqual(
279 (value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players) 279 (value, confirmed, rest), self.plugin._check_wait_auth(room, other_players)
280 ) 280 )
281 281
282 self.reinit() 282 self.reinit()
283 self.initGame(0, 0) 283 self.init_game(0, 0)
284 other_players = [Const.JID[1], Const.JID[3]] 284 other_players = [Const.JID[1], Const.JID[3]]
285 self.plugin.wait_mode = self.plugin.FOR_NONE 285 self.plugin.wait_mode = self.plugin.FOR_NONE
286 check(True, [], [], []) 286 check(True, [], [], [])
287 check( 287 check(
288 True, [Const.JID[0]], [], [Const.JID[0]] 288 True, [Const.JID[0]], [], [Const.JID[0]]
290 check(True, other_players, [], other_players) 290 check(True, other_players, [], other_players)
291 self.plugin.wait_mode = self.plugin.FOR_ALL 291 self.plugin.wait_mode = self.plugin.FOR_ALL
292 check(True, [], [], []) 292 check(True, [], [], [])
293 check(False, [Const.JID[0]], [], [Const.JID[0]]) 293 check(False, [Const.JID[0]], [], [Const.JID[0]])
294 check(False, other_players, [], other_players) 294 check(False, other_players, [], other_players)
295 self.plugin_0045.joinRoom(0, 1) 295 self.plugin_0045.join_room(0, 1)
296 check(False, other_players, [], other_players) 296 check(False, other_players, [], other_players)
297 self.plugin_0045.joinRoom(0, 4) 297 self.plugin_0045.join_room(0, 4)
298 check( 298 check(
299 False, 299 False,
300 other_players, 300 other_players,
301 [self.plugin_0045.getNickOfUser(0, 1, 0)], 301 [self.plugin_0045.get_nick_of_user(0, 1, 0)],
302 [Const.JID[3]], 302 [Const.JID[3]],
303 ) 303 )
304 self.plugin_0045.joinRoom(0, 3) 304 self.plugin_0045.join_room(0, 3)
305 check( 305 check(
306 True, 306 True,
307 other_players, 307 other_players,
308 [ 308 [
309 self.plugin_0045.getNickOfUser(0, 1, 0), 309 self.plugin_0045.get_nick_of_user(0, 1, 0),
310 self.plugin_0045.getNickOfUser(0, 3, 0), 310 self.plugin_0045.get_nick_of_user(0, 3, 0),
311 ], 311 ],
312 [], 312 [],
313 ) 313 )
314 314
315 other_players = [Const.JID[1], Const.JID[3], Const.JID[2]] 315 other_players = [Const.JID[1], Const.JID[3], Const.JID[2]]
316 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost 316 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
317 check( 317 check(
318 True, 318 True,
319 other_players, 319 other_players,
320 [ 320 [
321 self.plugin_0045.getNickOfUser(0, 1, 0), 321 self.plugin_0045.get_nick_of_user(0, 1, 0),
322 self.plugin_0045.getNickOfUser(0, 3, 0), 322 self.plugin_0045.get_nick_of_user(0, 3, 0),
323 self.plugin_0045.getNickOfUser(0, 2, 0), 323 self.plugin_0045.get_nick_of_user(0, 2, 0),
324 ], 324 ],
325 [], 325 [],
326 ) 326 )
327 327
328 def test_prepareRoom_trivial(self): 328 def test_prepare_room_trivial(self):
329 self.reinit() 329 self.reinit()
330 other_players = [] 330 other_players = []
331 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 331 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
332 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 332 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
333 self.assertTrue( 333 self.assertTrue(
334 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user) 334 self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
335 ) 335 )
336 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[0].user)) 336 self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, Const.JID[0].user))
337 self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID, [])) 337 self.assertEqual((True, [], []), self.plugin._check_wait_auth(ROOM_JID, []))
338 self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) 338 self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
339 self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[0].user)) 339 self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[0].user))
340 self.assertEqual( 340 self.assertEqual(
341 (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 341 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
342 ) 342 )
343 343
344 def test_prepareRoom_invite(self): 344 def test_prepare_room_invite(self):
345 self.reinit() 345 self.reinit()
346 other_players = [Const.JID[1], Const.JID[2]] 346 other_players = [Const.JID[1], Const.JID[2]]
347 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 347 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
348 room = self.plugin_0045.getRoom(0, 0) 348 room = self.plugin_0045.get_room(0, 0)
349 349
350 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 350 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
351 self.assertTrue( 351 self.assertTrue(
352 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user) 352 self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
353 ) 353 )
354 self.assertFalse( 354 self.assertFalse(
355 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user) 355 self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
356 ) 356 )
357 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) 357 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
358 self.assertEqual( 358 self.assertEqual(
359 (True, [], other_players), self.plugin._checkWaitAuth(room, other_players) 359 (True, [], other_players), self.plugin._check_wait_auth(room, other_players)
360 ) 360 )
361 361
362 player2_nick = self.plugin_0045.joinRoom(0, 1) 362 player2_nick = self.plugin_0045.join_room(0, 1)
363 self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE) 363 self.plugin.user_joined_trigger(room, room.roster[player2_nick], PROFILE)
364 self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) 364 self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
365 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, player2_nick)) 365 self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, player2_nick))
366 self.assertFalse(self.plugin.isReferee(ROOM_JID, player2_nick)) 366 self.assertFalse(self.plugin.is_referee(ROOM_JID, player2_nick))
367 self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) 367 self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
368 self.assertTrue( 368 self.assertTrue(
369 self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)) 369 self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
370 ) 370 )
371 self.assertFalse(self.plugin.isPlayer(ROOM_JID, "xxx")) 371 self.assertFalse(self.plugin.is_player(ROOM_JID, "xxx"))
372 self.assertEqual( 372 self.assertEqual(
373 (False, False), 373 (False, False),
374 self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[1]), 374 self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[1]),
375 ) 375 )
376 376
377 def test_prepareRoom_score1(self): 377 def test_prepare_room_score_1(self):
378 self.reinit(player_init={"score": 0}) 378 self.reinit(player_init={"score": 0})
379 other_players = [Const.JID[1], Const.JID[2]] 379 other_players = [Const.JID[1], Const.JID[2]]
380 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 380 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
381 room = self.plugin_0045.getRoom(0, 0) 381 room = self.plugin_0045.get_room(0, 0)
382 382
383 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) 383 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
384 self.assertTrue( 384 self.assertTrue(
385 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user) 385 self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
386 ) 386 )
387 self.assertFalse( 387 self.assertFalse(
388 self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user) 388 self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
389 ) 389 )
390 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) 390 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
391 self.assertEqual( 391 self.assertEqual(
392 (False, [], other_players), self.plugin._checkWaitAuth(room, other_players) 392 (False, [], other_players), self.plugin._check_wait_auth(room, other_players)
393 ) 393 )
394 394
395 user_nick = self.plugin_0045.joinRoom(0, 1) 395 user_nick = self.plugin_0045.join_room(0, 1)
396 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) 396 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
397 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) 397 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
398 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, user_nick)) 398 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, user_nick))
399 self.assertFalse(self.plugin.isReferee(ROOM_JID, user_nick)) 399 self.assertFalse(self.plugin.is_referee(ROOM_JID, user_nick))
400 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) 400 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
401 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost 401 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
402 self.assertTrue( 402 self.assertTrue(
403 self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)) 403 self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
404 ) 404 )
405 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user 405 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user
406 self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[3].user)) 406 self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[3].user))
407 # but Const.JID[3] is actually not in the room 407 # but Const.JID[3] is actually not in the room
408 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) 408 self.assertEqual(self.plugin_0045.get_nick_of_user(0, 3, 0), None)
409 self.assertEqual( 409 self.assertEqual(
410 (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[0]) 410 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[0])
411 ) 411 )
412 412
413 def test_prepareRoom_score2(self): 413 def test_prepare_room_score_2(self):
414 self.reinit(player_init={"score": 0}) 414 self.reinit(player_init={"score": 0})
415 other_players = [Const.JID[1], Const.JID[4]] 415 other_players = [Const.JID[1], Const.JID[4]]
416 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 416 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
417 room = self.plugin_0045.getRoom(0, 0) 417 room = self.plugin_0045.get_room(0, 0)
418 418
419 user_nick = self.plugin_0045.joinRoom(0, 1) 419 user_nick = self.plugin_0045.join_room(0, 1)
420 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) 420 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
421 self.assertEqual( 421 self.assertEqual(
422 (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 422 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
423 ) 423 )
424 user_nick = self.plugin_0045.joinRoom(0, 4) 424 user_nick = self.plugin_0045.join_room(0, 4)
425 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) 425 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
426 self.assertEqual( 426 self.assertEqual(
427 (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 427 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
428 ) 428 )
429 429
430 def test_userJoinedTrigger(self): 430 def test_user_joined_trigger(self):
431 self.reinit(player_init={"xxx": "xyz"}) 431 self.reinit(player_init={"xxx": "xyz"})
432 other_players = [Const.JID[1], Const.JID[3]] 432 other_players = [Const.JID[1], Const.JID[3]]
433 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 433 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
434 nicks = [self.plugin_0045.getNick(0, 0)] 434 nicks = [self.plugin_0045.get_nick(0, 0)]
435 435
436 self.assertEqual( 436 self.assertEqual(
437 self.host.getSentMessageXml(0), 437 self.host.get_sent_message_xml(0),
438 self._expectedMessage(ROOM_JID, "groupchat", "players", nicks), 438 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
439 ) 439 )
440 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1) 440 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1)
441 441
442 # wrong profile 442 # wrong profile
443 user_nick = self.plugin_0045.joinRoom(0, 1) 443 user_nick = self.plugin_0045.join_room(0, 1)
444 room = self.plugin_0045.getRoom(0, 1) 444 room = self.plugin_0045.get_room(0, 1)
445 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) 445 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
446 self.assertEqual( 446 self.assertEqual(
447 self.host.getSentMessage(0), None 447 self.host.get_sent_message(0), None
448 ) # no new message has been sent 448 ) # no new message has been sent
449 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started 449 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
450 450
451 # referee profile, user is allowed, wait for one more 451 # referee profile, user is allowed, wait for one more
452 room = self.plugin_0045.getRoom(0, 0) 452 room = self.plugin_0045.get_room(0, 0)
453 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) 453 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
454 nicks.append(user_nick) 454 nicks.append(user_nick)
455 self.assertEqual( 455 self.assertEqual(
456 self.host.getSentMessageXml(0), 456 self.host.get_sent_message_xml(0),
457 self._expectedMessage(ROOM_JID, "groupchat", "players", nicks), 457 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
458 ) 458 )
459 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started 459 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
460 460
461 # referee profile, user is not allowed 461 # referee profile, user is not allowed
462 user_nick = self.plugin_0045.joinRoom(0, 4) 462 user_nick = self.plugin_0045.join_room(0, 4)
463 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 463 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
464 self.assertEqual( 464 self.assertEqual(
465 self.host.getSentMessageXml(0), 465 self.host.get_sent_message_xml(0),
466 self._expectedMessage( 466 self._expected_message(
467 JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks 467 JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks
468 ), 468 ),
469 ) 469 )
470 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started 470 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
471 471
472 # referee profile, user is allowed, everybody here 472 # referee profile, user is allowed, everybody here
473 user_nick = self.plugin_0045.joinRoom(0, 3) 473 user_nick = self.plugin_0045.join_room(0, 3)
474 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 474 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
475 nicks.append(user_nick) 475 nicks.append(user_nick)
476 self.assertEqual( 476 self.assertEqual(
477 self.host.getSentMessageXml(0), 477 self.host.get_sent_message_xml(0),
478 self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), 478 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
479 ) 479 )
480 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) # game started 480 self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) # game started
481 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) 481 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
482 482
483 # wait for none 483 # wait for none
484 self.reinit() 484 self.reinit()
485 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 485 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
486 self.assertNotEqual(self.host.getSentMessage(0), None) # init messages 486 self.assertNotEqual(self.host.get_sent_message(0), None) # init messages
487 room = self.plugin_0045.getRoom(0, 0) 487 room = self.plugin_0045.get_room(0, 0)
488 nicks = [self.plugin_0045.getNick(0, 0)] 488 nicks = [self.plugin_0045.get_nick(0, 0)]
489 user_nick = self.plugin_0045.joinRoom(0, 3) 489 user_nick = self.plugin_0045.join_room(0, 3)
490 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 490 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
491 nicks.append(user_nick) 491 nicks.append(user_nick)
492 self.assertEqual( 492 self.assertEqual(
493 self.host.getSentMessageXml(0), 493 self.host.get_sent_message_xml(0),
494 self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), 494 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
495 ) 495 )
496 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 496 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
497 497
498 def test_userLeftTrigger(self): 498 def test_user_left_trigger(self):
499 self.reinit(player_init={"xxx": "xyz"}) 499 self.reinit(player_init={"xxx": "xyz"})
500 other_players = [Const.JID[1], Const.JID[3], Const.JID[4]] 500 other_players = [Const.JID[1], Const.JID[3], Const.JID[4]]
501 self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) 501 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
502 room = self.plugin_0045.getRoom(0, 0) 502 room = self.plugin_0045.get_room(0, 0)
503 nicks = [self.plugin_0045.getNick(0, 0)] 503 nicks = [self.plugin_0045.get_nick(0, 0)]
504 self.assertEqual( 504 self.assertEqual(
505 self.plugin.invitations[ROOM_JID][0][1], 505 self.plugin.invitations[ROOM_JID][0][1],
506 [ 506 [
507 Const.JID[1].userhostJID(), 507 Const.JID[1].userhostJID(),
508 Const.JID[3].userhostJID(), 508 Const.JID[3].userhostJID(),
509 Const.JID[4].userhostJID(), 509 Const.JID[4].userhostJID(),
510 ], 510 ],
511 ) 511 )
512 512
513 # one user joins 513 # one user joins
514 user_nick = self.plugin_0045.joinRoom(0, 1) 514 user_nick = self.plugin_0045.join_room(0, 1)
515 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) 515 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
516 nicks.append(user_nick) 516 nicks.append(user_nick)
517 517
518 # the user leaves 518 # the user leaves
519 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 519 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
520 room = self.plugin_0045.getRoom(0, 1) 520 room = self.plugin_0045.get_room(0, 1)
521 # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile 521 # to not call self.plugin_0045.leave_room(0, 1) here, we are testing the trigger with a wrong profile
522 self.plugin.userLeftTrigger( 522 self.plugin.user_left_trigger(
523 room, User(user_nick, Const.JID[1]), Const.PROFILE[1] 523 room, User(user_nick, Const.JID[1]), Const.PROFILE[1]
524 ) # not the referee 524 ) # not the referee
525 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 525 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
526 room = self.plugin_0045.getRoom(0, 0) 526 room = self.plugin_0045.get_room(0, 0)
527 user_nick = self.plugin_0045.leaveRoom(0, 1) 527 user_nick = self.plugin_0045.leave_room(0, 1)
528 self.plugin.userLeftTrigger( 528 self.plugin.user_left_trigger(
529 room, User(user_nick, Const.JID[1]), PROFILE 529 room, User(user_nick, Const.JID[1]), PROFILE
530 ) # referee 530 ) # referee
531 nicks.pop() 531 nicks.pop()
532 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 532 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
533 533
534 # all the users join 534 # all the users join
535 user_nick = self.plugin_0045.joinRoom(0, 1) 535 user_nick = self.plugin_0045.join_room(0, 1)
536 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) 536 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
537 nicks.append(user_nick) 537 nicks.append(user_nick)
538 user_nick = self.plugin_0045.joinRoom(0, 3) 538 user_nick = self.plugin_0045.join_room(0, 3)
539 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 539 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
540 nicks.append(user_nick) 540 nicks.append(user_nick)
541 user_nick = self.plugin_0045.joinRoom(0, 4) 541 user_nick = self.plugin_0045.join_room(0, 4)
542 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 542 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
543 nicks.append(user_nick) 543 nicks.append(user_nick)
544 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 544 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
545 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) 545 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
546 546
547 # one user leaves 547 # one user leaves
548 user_nick = self.plugin_0045.leaveRoom(0, 4) 548 user_nick = self.plugin_0045.leave_room(0, 4)
549 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 549 self.plugin.user_left_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
550 nicks.pop() 550 nicks.pop()
551 self.assertEqual( 551 self.assertEqual(
552 self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()] 552 self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()]
553 ) 553 )
554 554
555 # another leaves 555 # another leaves
556 user_nick = self.plugin_0045.leaveRoom(0, 3) 556 user_nick = self.plugin_0045.leave_room(0, 3)
557 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 557 self.plugin.user_left_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
558 nicks.pop() 558 nicks.pop()
559 self.assertEqual( 559 self.assertEqual(
560 self.plugin.invitations[ROOM_JID][0][1], 560 self.plugin.invitations[ROOM_JID][0][1],
561 [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()], 561 [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()],
562 ) 562 )
563 563
564 # they can join again 564 # they can join again
565 user_nick = self.plugin_0045.joinRoom(0, 3) 565 user_nick = self.plugin_0045.join_room(0, 3)
566 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) 566 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
567 nicks.append(user_nick) 567 nicks.append(user_nick)
568 user_nick = self.plugin_0045.joinRoom(0, 4) 568 user_nick = self.plugin_0045.join_room(0, 4)
569 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) 569 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
570 nicks.append(user_nick) 570 nicks.append(user_nick)
571 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 571 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
572 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) 572 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
573 573
574 def test__checkCreateGameAndInit(self): 574 def test_check_create_game_and_init(self):
575 self.reinit() 575 self.reinit()
576 helpers.muteLogging() 576 helpers.mute_logging()
577 self.assertEqual( 577 self.assertEqual(
578 (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 578 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
579 ) 579 )
580 helpers.unmuteLogging() 580 helpers.unmute_logging()
581 581
582 nick = self.plugin_0045.joinRoom(0, 0) 582 nick = self.plugin_0045.join_room(0, 0)
583 self.assertEqual( 583 self.assertEqual(
584 (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 584 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
585 ) 585 )
586 self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) 586 self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
587 self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) 587 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
588 self.assertTrue(self.plugin.isReferee(ROOM_JID, nick)) 588 self.assertTrue(self.plugin.is_referee(ROOM_JID, nick))
589 589
590 helpers.muteLogging() 590 helpers.mute_logging()
591 self.assertEqual( 591 self.assertEqual(
592 (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) 592 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
593 ) 593 )
594 helpers.unmuteLogging() 594 helpers.unmute_logging()
595 595
596 self.plugin_0045.joinRoom(0, 1) 596 self.plugin_0045.join_room(0, 1)
597 self.assertEqual( 597 self.assertEqual(
598 (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) 598 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
599 ) 599 )
600 600
601 self.plugin.createGame(ROOM_JID, [Const.JID[1]], PROFILE) 601 self.plugin.create_game(ROOM_JID, [Const.JID[1]], PROFILE)
602 self.assertEqual( 602 self.assertEqual(
603 (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) 603 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
604 ) 604 )
605 self.assertEqual( 605 self.assertEqual(
606 (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) 606 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
607 ) 607 )
608 608
609 def test_createGame(self): 609 def test_create_game(self):
610 610
611 self.reinit(player_init={"xxx": "xyz"}) 611 self.reinit(player_init={"xxx": "xyz"})
612 nicks = [] 612 nicks = []
613 for i in [0, 1, 3, 4]: 613 for i in [0, 1, 3, 4]:
614 nicks.append(self.plugin_0045.joinRoom(0, i)) 614 nicks.append(self.plugin_0045.join_room(0, i))
615 615
616 # game not exists 616 # game not exists
617 self.plugin.createGame(ROOM_JID, nicks, PROFILE) 617 self.plugin.create_game(ROOM_JID, nicks, PROFILE)
618 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 618 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
619 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) 619 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
620 self.assertEqual( 620 self.assertEqual(
621 self.host.getSentMessageXml(0), 621 self.host.get_sent_message_xml(0),
622 self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), 622 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
623 ) 623 )
624 for nick in nicks: 624 for nick in nicks:
625 self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick]) 625 self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick])
626 self.assertEqual( 626 self.assertEqual(
627 self.plugin.player_init, self.plugin.games[ROOM_JID]["players_data"][nick] 627 self.plugin.player_init, self.plugin.games[ROOM_JID]["players_data"][nick]
633 nick, self.plugin.games[ROOM_JID]["players_data"][nick]["xxx"] 633 nick, self.plugin.games[ROOM_JID]["players_data"][nick]["xxx"]
634 ) 634 )
635 635
636 # game exists, current profile is referee 636 # game exists, current profile is referee
637 self.reinit(player_init={"xxx": "xyz"}) 637 self.reinit(player_init={"xxx": "xyz"})
638 self.initGame(0, 0) 638 self.init_game(0, 0)
639 self.plugin.games[ROOM_JID]["started"] = True 639 self.plugin.games[ROOM_JID]["started"] = True
640 self.plugin.createGame(ROOM_JID, nicks, PROFILE) 640 self.plugin.create_game(ROOM_JID, nicks, PROFILE)
641 self.assertEqual( 641 self.assertEqual(
642 self.host.getSentMessageXml(0), 642 self.host.get_sent_message_xml(0),
643 self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), 643 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
644 ) 644 )
645 645
646 # game exists, current profile is not referee 646 # game exists, current profile is not referee
647 self.reinit(player_init={"xxx": "xyz"}) 647 self.reinit(player_init={"xxx": "xyz"})
648 self.initGame(0, 0) 648 self.init_game(0, 0)
649 self.plugin.games[ROOM_JID]["started"] = True 649 self.plugin.games[ROOM_JID]["started"] = True
650 self.plugin_0045.joinRoom(0, 1) 650 self.plugin_0045.join_room(0, 1)
651 self.plugin.createGame(ROOM_JID, nicks, OTHER_PROFILE) 651 self.plugin.create_game(ROOM_JID, nicks, OTHER_PROFILE)
652 self.assertEqual( 652 self.assertEqual(
653 self.host.getSentMessage(0), None 653 self.host.get_sent_message(0), None
654 ) # no sync message has been sent by other_profile 654 ) # no sync message has been sent by other_profile