comparison sat/test/test_plugin_misc_radiocol.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 559a625a236b
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
71 ) 71 )
72 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249( 72 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249(
73 self.host 73 self.host
74 ) 74 )
75 for profile in Const.PROFILE: 75 for profile in Const.PROFILE:
76 self.host.getClient(profile) # init self.host.profiles[profile] 76 self.host.get_client(profile) # init self.host.profiles[profile]
77 self.songs = [] 77 self.songs = []
78 self.playlist = [] 78 self.playlist = []
79 self.sound_dir = self.host.memory.getConfig("", "media_dir") + "/test/sound/" 79 self.sound_dir = self.host.memory.config_get("", "media_dir") + "/test/sound/"
80 try: 80 try:
81 for filename in os.listdir(self.sound_dir): 81 for filename in os.listdir(self.sound_dir):
82 if filename.endswith(".ogg") or filename.endswith(".mp3"): 82 if filename.endswith(".ogg") or filename.endswith(".mp3"):
83 self.songs.append(filename) 83 self.songs.append(filename)
84 except OSError: 84 except OSError:
85 raise SkipTest("The sound samples in sat_media/test/sound were not found") 85 raise SkipTest("The sound samples in sat_media/test/sound were not found")
86 86
87 def _buildPlayers(self, players=[]): 87 def _build_players(self, players=[]):
88 """@return: the "started" content built with the given players""" 88 """@return: the "started" content built with the given players"""
89 content = "<started" 89 content = "<started"
90 if not players: 90 if not players:
91 content += "/>" 91 content += "/>"
92 else: 92 else:
94 for i in range(0, len(players)): 94 for i in range(0, len(players)):
95 content += "<player index='%s'>%s</player>" % (i, players[i]) 95 content += "<player index='%s'>%s</player>" % (i, players[i])
96 content += "</started>" 96 content += "</started>"
97 return content 97 return content
98 98
99 def _expectedMessage(self, to_jid, type_, content): 99 def _expected_message(self, to_jid, type_, content):
100 """ 100 """
101 @param to_jid: recipient full jid 101 @param to_jid: recipient full jid
102 @param type_: message type ('normal' or 'groupchat') 102 @param type_: message type ('normal' or 'groupchat')
103 @param content: content as unicode or list of domish elements 103 @param content: content as unicode or list of domish elements
104 @return: the message XML built from the given recipient, message type and content 104 @return: the message XML built from the given recipient, message type and content
116 plugin.NC_RADIOCOL, 116 plugin.NC_RADIOCOL,
117 content, 117 content,
118 plugin.RADIOC_TAG, 118 plugin.RADIOC_TAG,
119 ) 119 )
120 120
121 def _rejectSongCb(self, profile_index): 121 def _reject_song_cb(self, profile_index):
122 """Check if the message "song_rejected" has been sent by the referee 122 """Check if the message "song_rejected" has been sent by the referee
123 and process the command with the profile of the uploader 123 and process the command with the profile of the uploader
124 @param profile_index: uploader's profile""" 124 @param profile_index: uploader's profile"""
125 sent = self.host.getSentMessage(0) 125 sent = self.host.get_sent_message(0)
126 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>" 126 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>"
127 self.assertEqualXML( 127 self.assert_equal_xml(
128 sent.toXml(), 128 sent.toXml(),
129 self._expectedMessage( 129 self._expected_message(
130 JID( 130 JID(
131 ROOM_JID.userhost() 131 ROOM_JID.userhost()
132 + "/" 132 + "/"
133 + self.plugin_0045.getNick(0, profile_index), 133 + self.plugin_0045.get_nick(0, profile_index),
134 "normal", 134 "normal",
135 content, 135 content,
136 ) 136 )
137 ), 137 ),
138 ) 138 )
139 self._roomGameCmd( 139 self._room_game_cmd(
140 sent, ["radiocolSongRejected", ROOM_JID.full(), "Too many songs in queue"] 140 sent, ["radiocol_song_rejected", ROOM_JID.full(), "Too many songs in queue"]
141 ) 141 )
142 142
143 def _noUploadCb(self): 143 def _no_upload_cb(self):
144 """Check if the message "no_upload" has been sent by the referee 144 """Check if the message "no_upload" has been sent by the referee
145 and process the command with the profiles of each room users""" 145 and process the command with the profiles of each room users"""
146 sent = self.host.getSentMessage(0) 146 sent = self.host.get_sent_message(0)
147 content = "<no_upload xmlns=''/>" 147 content = "<no_upload xmlns=''/>"
148 self.assertEqualXML( 148 self.assert_equal_xml(
149 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content) 149 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
150 ) 150 )
151 self._roomGameCmd(sent, ["radiocolNoUpload", ROOM_JID.full()]) 151 self._room_game_cmd(sent, ["radiocol_no_upload", ROOM_JID.full()])
152 152
153 def _uploadOkCb(self): 153 def _upload_ok_cb(self):
154 """Check if the message "upload_ok" has been sent by the referee 154 """Check if the message "upload_ok" has been sent by the referee
155 and process the command with the profiles of each room users""" 155 and process the command with the profiles of each room users"""
156 sent = self.host.getSentMessage(0) 156 sent = self.host.get_sent_message(0)
157 content = "<upload_ok xmlns=''/>" 157 content = "<upload_ok xmlns=''/>"
158 self.assertEqualXML( 158 self.assert_equal_xml(
159 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content) 159 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
160 ) 160 )
161 self._roomGameCmd(sent, ["radiocolUploadOk", ROOM_JID.full()]) 161 self._room_game_cmd(sent, ["radiocol_upload_ok", ROOM_JID.full()])
162 162
163 def _preloadCb(self, attrs, profile_index): 163 def _preload_cb(self, attrs, profile_index):
164 """Check if the message "preload" has been sent by the referee 164 """Check if the message "preload" has been sent by the referee
165 and process the command with the profiles of each room users 165 and process the command with the profiles of each room users
166 @param attrs: information dict about the song 166 @param attrs: information dict about the song
167 @param profile_index: profile index of the uploader 167 @param profile_index: profile index of the uploader
168 """ 168 """
169 sent = self.host.getSentMessage(0) 169 sent = self.host.get_sent_message(0)
170 attrs["sender"] = self.plugin_0045.getNick(0, profile_index) 170 attrs["sender"] = self.plugin_0045.get_nick(0, profile_index)
171 radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol")) 171 radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol"))
172 preload_elt = next(domish.generateElementsNamed( 172 preload_elt = next(domish.generateElementsNamed(
173 radiocol_elt.elements(), "preload" 173 radiocol_elt.elements(), "preload"
174 )) 174 ))
175 attrs["timestamp"] = preload_elt["timestamp"] # we could not guess it... 175 attrs["timestamp"] = preload_elt["timestamp"] # we could not guess it...
176 content = "<preload xmlns='' %s/>" % " ".join( 176 content = "<preload xmlns='' %s/>" % " ".join(
177 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs] 177 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
178 ) 178 )
179 if sent.hasAttribute("from"): 179 if sent.hasAttribute("from"):
180 del sent["from"] 180 del sent["from"]
181 self.assertEqualXML( 181 self.assert_equal_xml(
182 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content) 182 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
183 ) 183 )
184 self._roomGameCmd( 184 self._room_game_cmd(
185 sent, 185 sent,
186 [ 186 [
187 "radiocolPreload", 187 "radiocol_preload",
188 ROOM_JID.full(), 188 ROOM_JID.full(),
189 attrs["timestamp"], 189 attrs["timestamp"],
190 attrs["filename"], 190 attrs["filename"],
191 attrs["title"], 191 attrs["title"],
192 attrs["artist"], 192 attrs["artist"],
193 attrs["album"], 193 attrs["album"],
194 attrs["sender"], 194 attrs["sender"],
195 ], 195 ],
196 ) 196 )
197 197
198 def _playNextSongCb(self): 198 def _play_next_song_cb(self):
199 """Check if the message "play" has been sent by the referee 199 """Check if the message "play" has been sent by the referee
200 and process the command with the profiles of each room users""" 200 and process the command with the profiles of each room users"""
201 sent = self.host.getSentMessage(0) 201 sent = self.host.get_sent_message(0)
202 filename = self.playlist.pop(0) 202 filename = self.playlist.pop(0)
203 content = "<play xmlns='' filename='%s' />" % filename 203 content = "<play xmlns='' filename='%s' />" % filename
204 self.assertEqualXML( 204 self.assert_equal_xml(
205 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content) 205 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content)
206 ) 206 )
207 self._roomGameCmd(sent, ["radiocolPlay", ROOM_JID.full(), filename]) 207 self._room_game_cmd(sent, ["radiocol_play", ROOM_JID.full(), filename])
208 208
209 game_data = self.plugin.games[ROOM_JID] 209 game_data = self.plugin.games[ROOM_JID]
210 if len(game_data["queue"]) == plugin.QUEUE_LIMIT - 1: 210 if len(game_data["queue"]) == plugin.QUEUE_LIMIT - 1:
211 self._uploadOkCb() 211 self._upload_ok_cb()
212 212
213 def _addSongCb(self, d, filepath, profile_index): 213 def _add_song_cb(self, d, filepath, profile_index):
214 """Check if the message "song_added" has been sent by the uploader 214 """Check if the message "song_added" has been sent by the uploader
215 and process the command with the profile of the referee 215 and process the command with the profile of the referee
216 @param d: deferred value or failure got from self.plugin.radiocolSongAdded 216 @param d: deferred value or failure got from self.plugin.radiocol_song_added
217 @param filepath: full path to the sound file 217 @param filepath: full path to the sound file
218 @param profile_index: the profile index of the uploader 218 @param profile_index: the profile index of the uploader
219 """ 219 """
220 if isinstance(d, Failure): 220 if isinstance(d, Failure):
221 self.fail("OGG or MP3 song could not be added!") 221 self.fail("OGG or MP3 song could not be added!")
248 self.assertEqual(game_data["to_delete"][attrs["filename"]], filepath) 248 self.assertEqual(game_data["to_delete"][attrs["filename"]], filepath)
249 249
250 content = "<song_added xmlns='' %s/>" % " ".join( 250 content = "<song_added xmlns='' %s/>" % " ".join(
251 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs] 251 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
252 ) 252 )
253 sent = self.host.getSentMessage(profile_index) 253 sent = self.host.get_sent_message(profile_index)
254 self.assertEqualXML( 254 self.assert_equal_xml(
255 sent.toXml(), self._expectedMessage(REFEREE_FULL, "normal", content) 255 sent.toXml(), self._expected_message(REFEREE_FULL, "normal", content)
256 ) 256 )
257 257
258 reject_song = len(game_data["queue"]) >= plugin.QUEUE_LIMIT 258 reject_song = len(game_data["queue"]) >= plugin.QUEUE_LIMIT
259 no_upload = len(game_data["queue"]) + 1 >= plugin.QUEUE_LIMIT 259 no_upload = len(game_data["queue"]) + 1 >= plugin.QUEUE_LIMIT
260 play_next = ( 260 play_next = (
261 not game_data["playing"] 261 not game_data["playing"]
262 and len(game_data["queue"]) + 1 == plugin.QUEUE_TO_START 262 and len(game_data["queue"]) + 1 == plugin.QUEUE_TO_START
263 ) 263 )
264 264
265 self._roomGameCmd(sent, profile_index) # queue unchanged or +1 265 self._room_game_cmd(sent, profile_index) # queue unchanged or +1
266 if reject_song: 266 if reject_song:
267 self._rejectSongCb(profile_index) 267 self._reject_song_cb(profile_index)
268 return 268 return
269 if no_upload: 269 if no_upload:
270 self._noUploadCb() 270 self._no_upload_cb()
271 self._preloadCb(attrs, profile_index) 271 self._preload_cb(attrs, profile_index)
272 self.playlist.append(attrs["filename"]) 272 self.playlist.append(attrs["filename"])
273 if play_next: 273 if play_next:
274 self._playNextSongCb() # queue -1 274 self._play_next_song_cb() # queue -1
275 275
276 def _roomGameCmd(self, sent, from_index=0, call=[]): 276 def _room_game_cmd(self, sent, from_index=0, call=[]):
277 """Process a command. It is also possible to call this method as 277 """Process a command. It is also possible to call this method as
278 _roomGameCmd(sent, call) instead of _roomGameCmd(sent, from_index, call). 278 _room_game_cmd(sent, call) instead of _room_game_cmd(sent, from_index, call).
279 If from index is a list, it is assumed that it is containing the value 279 If from index is a list, it is assumed that it is containing the value
280 for call and from_index will take its default value. 280 for call and from_index will take its default value.
281 @param sent: the sent message that we need to process 281 @param sent: the sent message that we need to process
282 @param from_index: index of the message sender 282 @param from_index: index of the message sender
283 @param call: list containing the name of the expected bridge call 283 @param call: list containing the name of the expected bridge call
285 """ 285 """
286 if isinstance(from_index, list): 286 if isinstance(from_index, list):
287 call = from_index 287 call = from_index
288 from_index = 0 288 from_index = 0
289 289
290 sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.getNick(0, from_index) 290 sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.get_nick(0, from_index)
291 recipient = JID(sent["to"]).resource 291 recipient = JID(sent["to"]).resource
292 292
293 # The message could have been sent to a room user (room_jid + '/' + nick), 293 # The message could have been sent to a room user (room_jid + '/' + nick),
294 # but when it is received, the 'to' attribute of the message has been 294 # but when it is received, the 'to' attribute of the message has been
295 # changed to the recipient own JID. We need to simulate that here. 295 # changed to the recipient own JID. We need to simulate that here.
296 if recipient: 296 if recipient:
297 room = self.plugin_0045.getRoom(0, 0) 297 room = self.plugin_0045.get_room(0, 0)
298 sent["to"] = ( 298 sent["to"] = (
299 Const.JID_STR[0] 299 Const.JID_STR[0]
300 if recipient == room.nick 300 if recipient == room.nick
301 else room.roster[recipient].entity.full() 301 else room.roster[recipient].entity.full()
302 ) 302 )
303 303
304 for index in range(0, len(Const.PROFILE)): 304 for index in range(0, len(Const.PROFILE)):
305 nick = self.plugin_0045.getNick(0, index) 305 nick = self.plugin_0045.get_nick(0, index)
306 if nick: 306 if nick:
307 if not recipient or nick == recipient: 307 if not recipient or nick == recipient:
308 if call and ( 308 if call and (
309 self.plugin.isPlayer(ROOM_JID, nick) 309 self.plugin.is_player(ROOM_JID, nick)
310 or call[0] == "radiocolStarted" 310 or call[0] == "radiocol_started"
311 ): 311 ):
312 args = copy.deepcopy(call) 312 args = copy.deepcopy(call)
313 args.append(Const.PROFILE[index]) 313 args.append(Const.PROFILE[index])
314 self.host.bridge.expectCall(*args) 314 self.host.bridge.expect_call(*args)
315 self.plugin.room_game_cmd(sent, Const.PROFILE[index]) 315 self.plugin.room_game_cmd(sent, Const.PROFILE[index])
316 316
317 def _syncCb(self, sync_data, profile_index): 317 def _sync_cb(self, sync_data, profile_index):
318 """Synchronize one player when he joins a running game. 318 """Synchronize one player when he joins a running game.
319 @param sync_data: result from self.plugin.getSyncData 319 @param sync_data: result from self.plugin.getSyncData
320 @param profile_index: index of the profile to be synchronized 320 @param profile_index: index of the profile to be synchronized
321 """ 321 """
322 for nick in sync_data: 322 for nick in sync_data:
323 expected = self._expectedMessage( 323 expected = self._expected_message(
324 JID(ROOM_JID.userhost() + "/" + nick), "normal", sync_data[nick] 324 JID(ROOM_JID.userhost() + "/" + nick), "normal", sync_data[nick]
325 ) 325 )
326 sent = self.host.getSentMessage(0) 326 sent = self.host.get_sent_message(0)
327 self.assertEqualXML(sent.toXml(), expected) 327 self.assert_equal_xml(sent.toXml(), expected)
328 for elt in sync_data[nick]: 328 for elt in sync_data[nick]:
329 if elt.name == "preload": 329 if elt.name == "preload":
330 self.host.bridge.expectCall( 330 self.host.bridge.expect_call(
331 "radiocolPreload", 331 "radiocol_preload",
332 ROOM_JID.full(), 332 ROOM_JID.full(),
333 elt["timestamp"], 333 elt["timestamp"],
334 elt["filename"], 334 elt["filename"],
335 elt["title"], 335 elt["title"],
336 elt["artist"], 336 elt["artist"],
337 elt["album"], 337 elt["album"],
338 elt["sender"], 338 elt["sender"],
339 Const.PROFILE[profile_index], 339 Const.PROFILE[profile_index],
340 ) 340 )
341 elif elt.name == "play": 341 elif elt.name == "play":
342 self.host.bridge.expectCall( 342 self.host.bridge.expect_call(
343 "radiocolPlay", 343 "radiocol_play",
344 ROOM_JID.full(), 344 ROOM_JID.full(),
345 elt["filename"], 345 elt["filename"],
346 Const.PROFILE[profile_index], 346 Const.PROFILE[profile_index],
347 ) 347 )
348 elif elt.name == "no_upload": 348 elif elt.name == "no_upload":
349 self.host.bridge.expectCall( 349 self.host.bridge.expect_call(
350 "radiocolNoUpload", ROOM_JID.full(), Const.PROFILE[profile_index] 350 "radiocol_no_upload", ROOM_JID.full(), Const.PROFILE[profile_index]
351 ) 351 )
352 sync_data[nick] 352 sync_data[nick]
353 self._roomGameCmd(sent, []) 353 self._room_game_cmd(sent, [])
354 354
355 def _joinRoom(self, room, nicks, player_index, sync=True): 355 def _join_room(self, room, nicks, player_index, sync=True):
356 """Make a player join a room and update the list of nicks 356 """Make a player join a room and update the list of nicks
357 @param room: wokkel.muc.Room instance from the referee perspective 357 @param room: wokkel.muc.Room instance from the referee perspective
358 @param nicks: list of the players which will be updated 358 @param nicks: list of the players which will be updated
359 @param player_index: profile index of the new player 359 @param player_index: profile index of the new player
360 @param sync: set to True to synchronize data 360 @param sync: set to True to synchronize data
361 """ 361 """
362 user_nick = self.plugin_0045.joinRoom(0, player_index) 362 user_nick = self.plugin_0045.join_room(0, player_index)
363 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) 363 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
364 if player_index not in PLAYERS_INDICES: 364 if player_index not in PLAYERS_INDICES:
365 # this user is actually not a player 365 # this user is actually not a player
366 self.assertFalse(self.plugin.isPlayer(ROOM_JID, user_nick)) 366 self.assertFalse(self.plugin.is_player(ROOM_JID, user_nick))
367 to_jid, type_ = (JID(ROOM_JID.userhost() + "/" + user_nick), "normal") 367 to_jid, type_ = (JID(ROOM_JID.userhost() + "/" + user_nick), "normal")
368 else: 368 else:
369 # this user is a player 369 # this user is a player
370 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) 370 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
371 nicks.append(user_nick) 371 nicks.append(user_nick)
372 to_jid, type_ = (ROOM_JID, "groupchat") 372 to_jid, type_ = (ROOM_JID, "groupchat")
373 373
374 # Check that the message "players" has been sent by the referee 374 # Check that the message "players" has been sent by the referee
375 expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) 375 expected = self._expected_message(to_jid, type_, self._build_players(nicks))
376 sent = self.host.getSentMessage(0) 376 sent = self.host.get_sent_message(0)
377 self.assertEqualXML(sent.toXml(), expected) 377 self.assert_equal_xml(sent.toXml(), expected)
378 378
379 # Process the command with the profiles of each room users 379 # Process the command with the profiles of each room users
380 self._roomGameCmd( 380 self._room_game_cmd(
381 sent, 381 sent,
382 [ 382 [
383 "radiocolStarted", 383 "radiocol_started",
384 ROOM_JID.full(), 384 ROOM_JID.full(),
385 REFEREE_FULL.full(), 385 REFEREE_FULL.full(),
386 nicks, 386 nicks,
387 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT], 387 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT],
388 ], 388 ],
389 ) 389 )
390 390
391 if sync: 391 if sync:
392 self._syncCb(self.plugin._getSyncData(ROOM_JID, [user_nick]), player_index) 392 self._sync_cb(self.plugin._get_sync_data(ROOM_JID, [user_nick]), player_index)
393 393
394 def _leaveRoom(self, room, nicks, player_index): 394 def _leave_room(self, room, nicks, player_index):
395 """Make a player leave a room and update the list of nicks 395 """Make a player leave a room and update the list of nicks
396 @param room: wokkel.muc.Room instance from the referee perspective 396 @param room: wokkel.muc.Room instance from the referee perspective
397 @param nicks: list of the players which will be updated 397 @param nicks: list of the players which will be updated
398 @param player_index: profile index of the new player 398 @param player_index: profile index of the new player
399 """ 399 """
400 user_nick = self.plugin_0045.getNick(0, player_index) 400 user_nick = self.plugin_0045.get_nick(0, player_index)
401 user = room.roster[user_nick] 401 user = room.roster[user_nick]
402 self.plugin_0045.leaveRoom(0, player_index) 402 self.plugin_0045.leave_room(0, player_index)
403 self.plugin.userLeftTrigger(room, user, PROFILE) 403 self.plugin.user_left_trigger(room, user, PROFILE)
404 nicks.remove(user_nick) 404 nicks.remove(user_nick)
405 405
406 def _uploadSong(self, song_index, profile_index): 406 def _upload_song(self, song_index, profile_index):
407 """Upload the song of index song_index (modulo self.songs size) from the profile of index profile_index. 407 """Upload the song of index song_index (modulo self.songs size) from the profile of index profile_index.
408 408
409 @param song_index: index of the song or None to test with non existing file 409 @param song_index: index of the song or None to test with non existing file
410 @param profile_index: index of the uploader's profile 410 @param profile_index: index of the uploader's profile
411 """ 411 """
418 dst_filepath = "/tmp/%s%s" % (uuid.uuid1(), os.path.splitext(src_filename)[1]) 418 dst_filepath = "/tmp/%s%s" % (uuid.uuid1(), os.path.splitext(src_filename)[1])
419 shutil.copy(self.sound_dir + src_filename, dst_filepath) 419 shutil.copy(self.sound_dir + src_filename, dst_filepath)
420 expect_io_error = False 420 expect_io_error = False
421 421
422 try: 422 try:
423 d = self.plugin.radiocolSongAdded( 423 d = self.plugin.radiocol_song_added(
424 REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index] 424 REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index]
425 ) 425 )
426 except IOError: 426 except IOError:
427 self.assertTrue(expect_io_error) 427 self.assertTrue(expect_io_error)
428 return 428 return
429 429
430 self.assertFalse(expect_io_error) 430 self.assertFalse(expect_io_error)
431 cb = lambda defer: self._addSongCb(defer, dst_filepath, profile_index) 431 cb = lambda defer: self._add_song_cb(defer, dst_filepath, profile_index)
432 432
433 def eb(failure): 433 def eb(failure):
434 if not isinstance(failure, Failure): 434 if not isinstance(failure, Failure):
435 self.fail("Adding a song which is not OGG nor MP3 should fail!") 435 self.fail("Adding a song which is not OGG nor MP3 should fail!")
436 self.assertEqual(failure.value.__class__, exceptions.DataError) 436 self.assertEqual(failure.value.__class__, exceptions.DataError)
449 449
450 def test_game(self): 450 def test_game(self):
451 self.reinit() 451 self.reinit()
452 452
453 # create game 453 # create game
454 self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID, PROFILE) 454 self.plugin.prepare_room(OTHER_PLAYERS, ROOM_JID, PROFILE)
455 self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) 455 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
456 room = self.plugin_0045.getRoom(0, 0) 456 room = self.plugin_0045.get_room(0, 0)
457 nicks = [self.plugin_0045.getNick(0, 0)] 457 nicks = [self.plugin_0045.get_nick(0, 0)]
458 458
459 sent = self.host.getSentMessage(0) 459 sent = self.host.get_sent_message(0)
460 self.assertEqualXML( 460 self.assert_equal_xml(
461 sent.toXml(), 461 sent.toXml(),
462 self._expectedMessage(ROOM_JID, "groupchat", self._buildPlayers(nicks)), 462 self._expected_message(ROOM_JID, "groupchat", self._build_players(nicks)),
463 ) 463 )
464 self._roomGameCmd( 464 self._room_game_cmd(
465 sent, 465 sent,
466 [ 466 [
467 "radiocolStarted", 467 "radiocol_started",
468 ROOM_JID.full(), 468 ROOM_JID.full(),
469 REFEREE_FULL.full(), 469 REFEREE_FULL.full(),
470 nicks, 470 nicks,
471 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT], 471 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT],
472 ], 472 ],
473 ) 473 )
474 474
475 self._joinRoom(room, nicks, 1) # player joins 475 self._join_room(room, nicks, 1) # player joins
476 self._joinRoom(room, nicks, 4) # user not playing joins 476 self._join_room(room, nicks, 4) # user not playing joins
477 477
478 song_index = 0 478 song_index = 0
479 self._uploadSong( 479 self._upload_song(
480 song_index, 0 480 song_index, 0
481 ) # ogg or mp3 file should exist in sat_media/test/song 481 ) # ogg or mp3 file should exist in sat_media/test/song
482 self._uploadSong(None, 0) # non existing file 482 self._upload_song(None, 0) # non existing file
483 483
484 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue 484 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue
485 # when the first song starts + 1 to be rejected because the queue is full 485 # when the first song starts + 1 to be rejected because the queue is full
486 for song_index in range(1, plugin.QUEUE_TO_START + 1): 486 for song_index in range(1, plugin.QUEUE_TO_START + 1):
487 self._uploadSong(song_index, 1) 487 self._upload_song(song_index, 1)
488 488
489 self.plugin.playNext(Const.MUC[0], PROFILE) # simulate the end of the first song 489 self.plugin.play_next(Const.MUC[0], PROFILE) # simulate the end of the first song
490 self._playNextSongCb() 490 self._play_next_song_cb()
491 self._uploadSong( 491 self._upload_song(
492 song_index, 1 492 song_index, 1
493 ) # now the song is accepted and the queue is full again 493 ) # now the song is accepted and the queue is full again
494 494
495 self._joinRoom(room, nicks, 3) # new player joins 495 self._join_room(room, nicks, 3) # new player joins
496 496
497 self.plugin.playNext(Const.MUC[0], PROFILE) # the second song finishes 497 self.plugin.play_next(Const.MUC[0], PROFILE) # the second song finishes
498 self._playNextSongCb() 498 self._play_next_song_cb()
499 self._uploadSong(0, 3) # the player who recently joined re-upload the first file 499 self._upload_song(0, 3) # the player who recently joined re-upload the first file
500 500
501 self._leaveRoom(room, nicks, 1) # one player leaves 501 self._leave_room(room, nicks, 1) # one player leaves
502 self._joinRoom(room, nicks, 1) # and join again 502 self._join_room(room, nicks, 1) # and join again
503 503
504 self.plugin.playNext(Const.MUC[0], PROFILE) # empty the queue 504 self.plugin.play_next(Const.MUC[0], PROFILE) # empty the queue
505 self._playNextSongCb() 505 self._play_next_song_cb()
506 self.plugin.playNext(Const.MUC[0], PROFILE) 506 self.plugin.play_next(Const.MUC[0], PROFILE)
507 self._playNextSongCb() 507 self._play_next_song_cb()
508 508
509 for filename in self.playlist: 509 for filename in self.playlist:
510 self.plugin.deleteFile("/tmp/" + filename) 510 self.plugin.delete_file("/tmp/" + filename)
511 511
512 return defer.succeed(None) 512 return defer.succeed(None)
513 513
514 def tearDown(self, *args, **kwargs): 514 def tearDown(self, *args, **kwargs):
515 """Clean the reactor""" 515 """Clean the reactor"""