comparison src/test/test_plugin_misc_radiocol.py @ 904:95dabdb0c799

test: update radiocol test regarding the last changes
author souliane <souliane@mailoo.org>
date Sat, 15 Mar 2014 01:19:22 +0100
parents 4d091738275c
children 301b342c697a
comparison
equal deleted inserted replaced
903:c3fdf187a73a 904:95dabdb0c799
71 self.songs = [] 71 self.songs = []
72 self.playlist = [] 72 self.playlist = []
73 self.sound_dir = self.host.memory.getConfig('', 'media_dir') + '/test/sound/' 73 self.sound_dir = self.host.memory.getConfig('', 'media_dir') + '/test/sound/'
74 try: 74 try:
75 for filename in os.listdir(self.sound_dir): 75 for filename in os.listdir(self.sound_dir):
76 if filename.endswith('.ogg'): 76 if filename.endswith('.ogg') or filename.endswith('.mp3'):
77 self.songs.append(filename) 77 self.songs.append(filename)
78 except OSError: 78 except OSError:
79 raise SkipTest('The sound samples in sat_media/test/sound were not found') 79 raise SkipTest('The sound samples in sat_media/test/sound were not found')
80 80
81 def _buildPlayers(self, players=[]): 81 def _buildPlayers(self, players=[]):
143 attrs['timestamp'] = preload_elt['timestamp'] # we could not guess it... 143 attrs['timestamp'] = preload_elt['timestamp'] # we could not guess it...
144 content = "<preload xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) 144 content = "<preload xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs])
145 if sent.hasAttribute('from'): 145 if sent.hasAttribute('from'):
146 del sent['from'] 146 del sent['from']
147 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) 147 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
148 self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID_S, attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album']]) 148 self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID_S, attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album'], attrs['sender']])
149 149
150 def _playNextSongCb(self): 150 def _playNextSongCb(self):
151 """Check if the message "play" has been sent by the referee 151 """Check if the message "play" has been sent by the referee
152 and process the command with the profiles of each room users""" 152 and process the command with the profiles of each room users"""
153 sent = self.host.getSentMessageRaw(0) 153 sent = self.host.getSentMessageRaw(0)
242 expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick]) 242 expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick])
243 sent = self.host.getSentMessageRaw(0) 243 sent = self.host.getSentMessageRaw(0)
244 self.assertEqualXML(sent.toXml(), expected) 244 self.assertEqualXML(sent.toXml(), expected)
245 for elt in sync_data[nick]: 245 for elt in sync_data[nick]:
246 if elt.name == 'preload': 246 if elt.name == 'preload':
247 self.host.bridge.expectCall('radiocolPreload', ROOM_JID_S, elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], Const.PROFILE[profile_index]) 247 self.host.bridge.expectCall('radiocolPreload', ROOM_JID_S, elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], elt['sender'], Const.PROFILE[profile_index])
248 elif elt.name == 'play': 248 elif elt.name == 'play':
249 self.host.bridge.expectCall('radiocolPlay', ROOM_JID_S, elt['filename'], Const.PROFILE[profile_index]) 249 self.host.bridge.expectCall('radiocolPlay', ROOM_JID_S, elt['filename'], Const.PROFILE[profile_index])
250 elif elt.name == 'no_upload': 250 elif elt.name == 'no_upload':
251 self.host.bridge.expectCall('radiocolNoUpload', ROOM_JID_S, Const.PROFILE[profile_index]) 251 self.host.bridge.expectCall('radiocolNoUpload', ROOM_JID_S, Const.PROFILE[profile_index])
252 sync_data[nick] 252 sync_data[nick]
295 nicks.remove(user_nick) 295 nicks.remove(user_nick)
296 296
297 def _uploadSong(self, song_index, profile_index, ext='ogg'): 297 def _uploadSong(self, song_index, profile_index, ext='ogg'):
298 """Upload the song of index song_index (modulo self.songs size) 298 """Upload the song of index song_index (modulo self.songs size)
299 from the profile of index profile_index. All the songs in self.songs 299 from the profile of index profile_index. All the songs in self.songs
300 are OGG, but you can set ext to a value different than 'ogg': 300 are OGG, but you can set ext to a value different than 'ogg' or 'mp3':
301 - 'mp3' to test unsupported file format (MP3 file should exist)
302 - 'xxx' to test non existent files 301 - 'xxx' to test non existent files
303 @param song_index: index of the song 302 @param song_index: index of the song
304 @param profile_index: index of the uploader's profile 303 @param profile_index: index of the uploader's profile
305 @param new_ext: change the extension from "ogg" to this value 304 @param new_ext: change the extension from "ogg" to this value
306 """ 305 """
307 song_index = song_index % len(self.songs) 306 song_index = song_index % len(self.songs)
308 src_filename = self.songs[song_index] 307 src_filename = self.songs[song_index]
309 if ext != 'ogg': 308 if ext not in ('ogg', 'mp3'):
310 src_filename.replace('ogg', ext) 309 src_filename = os.path.splitext(src_filename)[0] + '.' + ext
311 dst_filepath = '/tmp/%s.%s' % (uuid.uuid1(), ext) 310 dst_filepath = '/tmp/%s.%s' % (uuid.uuid1(), ext)
312 expect_io_error = ext == 'xxx' 311 expect_io_error = ext == 'xxx'
313 if not expect_io_error: 312 if not expect_io_error:
314 shutil.copy(self.sound_dir + src_filename, dst_filepath) 313 shutil.copy(self.sound_dir + src_filename, dst_filepath)
315 314
322 self.assertFalse(expect_io_error) 321 self.assertFalse(expect_io_error)
323 cb = lambda defer: self._addSongCb(defer, dst_filepath, profile_index) 322 cb = lambda defer: self._addSongCb(defer, dst_filepath, profile_index)
324 323
325 def eb(failure): 324 def eb(failure):
326 if not isinstance(failure, Failure): 325 if not isinstance(failure, Failure):
327 self.fail("Adding a song which is not OGG should fail!") 326 self.fail("Adding a song which is not OGG nor MP3 should fail!")
328 self.assertEqual(failure.value.__class__, exceptions.DataError) 327 self.assertEqual(failure.value.__class__, exceptions.DataError)
329 328
330 if self.songs[song_index].endswith('.ogg'): 329 if self.songs[song_index].endswith('.ogg') or self.songs[song_index].endswith('.mp3'):
331 d.addCallbacks(cb, cb) 330 d.addCallbacks(cb, cb)
332 else: 331 else:
333 d.addCallbacks(eb, eb) 332 d.addCallbacks(eb, eb)
334 333
335 def test_init(self): 334 def test_init(self):
354 353
355 self._joinRoom(room, nicks, 1) # player joins 354 self._joinRoom(room, nicks, 1) # player joins
356 self._joinRoom(room, nicks, 4) # user not playing joins 355 self._joinRoom(room, nicks, 4) # user not playing joins
357 356
358 song_index = 0 357 song_index = 0
359 self._uploadSong(song_index, 0) # ogg file should exist in sat_media/test/song 358 self._uploadSong(song_index, 0) # ogg or mp3 file should exist in sat_media/test/song
360 self._uploadSong(song_index, 0, 'mp3') # mp3 file should exist in sat_media/test/song
361 self._uploadSong(song_index, 0, 'xxx') # file should not exist 359 self._uploadSong(song_index, 0, 'xxx') # file should not exist
362 360
363 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue 361 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue
364 # when the first song starts + 1 to be rejected because the queue is full 362 # when the first song starts + 1 to be rejected because the queue is full
365 for song_index in xrange(1, plugin.QUEUE_TO_START + 1): 363 for song_index in xrange(1, plugin.QUEUE_TO_START + 1):