Mercurial > libervia-backend
comparison src/test/test_plugin_misc_radiocol.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 | 979210da778a |
comparison
equal
deleted
inserted
replaced
1270:037ec0795a85 | 1271:2308f8405ffb |
---|---|
53 class RadiocolTest(helpers.SatTestCase): | 53 class RadiocolTest(helpers.SatTestCase): |
54 | 54 |
55 def setUp(self): | 55 def setUp(self): |
56 self.host = helpers.FakeSAT() | 56 self.host = helpers.FakeSAT() |
57 | 57 |
58 def init(self): | 58 def reinit(self): |
59 self.host.init() | 59 self.host.reinit() |
60 self.host.plugins['ROOM-GAME'] = plugin_room_game.RoomGame(self.host) | 60 self.host.plugins['ROOM-GAME'] = plugin_room_game.RoomGame(self.host) |
61 self.plugin = plugin.Radiocol(self.host) # must be init after ROOM-GAME | 61 self.plugin = plugin.Radiocol(self.host) # must be init after ROOM-GAME |
62 self.plugin.testing = True | 62 self.plugin.testing = True |
63 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host) | 63 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host) |
64 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host) | 64 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host) |
107 | 107 |
108 def _rejectSongCb(self, profile_index): | 108 def _rejectSongCb(self, profile_index): |
109 """Check if the message "song_rejected" has been sent by the referee | 109 """Check if the message "song_rejected" has been sent by the referee |
110 and process the command with the profile of the uploader | 110 and process the command with the profile of the uploader |
111 @param profile_index: uploader's profile""" | 111 @param profile_index: uploader's profile""" |
112 sent = self.host.getSentMessageRaw(0) | 112 sent = self.host.getSentMessage(0) |
113 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>" | 113 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>" |
114 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S + '/' + self.plugin_0045.getNick(0, profile_index), 'normal', content)) | 114 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S + '/' + self.plugin_0045.getNick(0, profile_index), 'normal', content)) |
115 self._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID_S, 'Too many songs in queue']) | 115 self._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID_S, 'Too many songs in queue']) |
116 | 116 |
117 def _noUploadCb(self): | 117 def _noUploadCb(self): |
118 """Check if the message "no_upload" has been sent by the referee | 118 """Check if the message "no_upload" has been sent by the referee |
119 and process the command with the profiles of each room users""" | 119 and process the command with the profiles of each room users""" |
120 sent = self.host.getSentMessageRaw(0) | 120 sent = self.host.getSentMessage(0) |
121 content = "<no_upload xmlns=''/>" | 121 content = "<no_upload xmlns=''/>" |
122 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) | 122 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
123 self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S]) | 123 self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S]) |
124 | 124 |
125 def _uploadOkCb(self): | 125 def _uploadOkCb(self): |
126 """Check if the message "upload_ok" has been sent by the referee | 126 """Check if the message "upload_ok" has been sent by the referee |
127 and process the command with the profiles of each room users""" | 127 and process the command with the profiles of each room users""" |
128 sent = self.host.getSentMessageRaw(0) | 128 sent = self.host.getSentMessage(0) |
129 content = "<upload_ok xmlns=''/>" | 129 content = "<upload_ok xmlns=''/>" |
130 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) | 130 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
131 self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S]) | 131 self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S]) |
132 | 132 |
133 def _preloadCb(self, attrs, profile_index): | 133 def _preloadCb(self, attrs, profile_index): |
134 """Check if the message "preload" has been sent by the referee | 134 """Check if the message "preload" has been sent by the referee |
135 and process the command with the profiles of each room users | 135 and process the command with the profiles of each room users |
136 @param attrs: information dict about the song | 136 @param attrs: information dict about the song |
137 @param profile_index: profile index of the uploader | 137 @param profile_index: profile index of the uploader |
138 """ | 138 """ |
139 sent = self.host.getSentMessageRaw(0) | 139 sent = self.host.getSentMessage(0) |
140 attrs['sender'] = self.plugin_0045.getNick(0, profile_index) | 140 attrs['sender'] = self.plugin_0045.getNick(0, profile_index) |
141 radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next() | 141 radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next() |
142 preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next() | 142 preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next() |
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]) |
148 self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID_S, attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album'], attrs['sender']]) | 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.getSentMessage(0) |
154 filename = self.playlist.pop(0) | 154 filename = self.playlist.pop(0) |
155 content = "<play xmlns='' filename='%s' />" % filename | 155 content = "<play xmlns='' filename='%s' />" % filename |
156 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) | 156 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
157 self._roomGameCmd(sent, ['radiocolPlay', ROOM_JID_S, filename]) | 157 self._roomGameCmd(sent, ['radiocolPlay', ROOM_JID_S, filename]) |
158 | 158 |
179 'length': str(song.info.length) | 179 'length': str(song.info.length) |
180 } | 180 } |
181 self.assertEqual(game_data['to_delete'][attrs['filename']], filepath) | 181 self.assertEqual(game_data['to_delete'][attrs['filename']], filepath) |
182 | 182 |
183 content = "<song_added xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) | 183 content = "<song_added xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) |
184 sent = self.host.getSentMessageRaw(profile_index) | 184 sent = self.host.getSentMessage(profile_index) |
185 self.assertEqualXML(sent.toXml(), self._expectedMessage(REFEREE_FULL, 'normal', content)) | 185 self.assertEqualXML(sent.toXml(), self._expectedMessage(REFEREE_FULL, 'normal', content)) |
186 | 186 |
187 reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT | 187 reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT |
188 no_upload = len(game_data['queue']) + 1 >= plugin.QUEUE_LIMIT | 188 no_upload = len(game_data['queue']) + 1 >= plugin.QUEUE_LIMIT |
189 play_next = not game_data['playing'] and len(game_data['queue']) + 1 == plugin.QUEUE_TO_START | 189 play_next = not game_data['playing'] and len(game_data['queue']) + 1 == plugin.QUEUE_TO_START |
238 @param sync_data: result from self.plugin.getSyncData | 238 @param sync_data: result from self.plugin.getSyncData |
239 @param profile_index: index of the profile to be synchronized | 239 @param profile_index: index of the profile to be synchronized |
240 """ | 240 """ |
241 for nick in sync_data: | 241 for nick in sync_data: |
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.getSentMessage(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'], elt['sender'], 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': |
271 nicks.append(user_nick) | 271 nicks.append(user_nick) |
272 to_jid, type_ = (ROOM_JID_S, 'groupchat') | 272 to_jid, type_ = (ROOM_JID_S, 'groupchat') |
273 | 273 |
274 # Check that the message "players" has been sent by the referee | 274 # Check that the message "players" has been sent by the referee |
275 expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) | 275 expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) |
276 sent = self.host.getSentMessageRaw(0) | 276 sent = self.host.getSentMessage(0) |
277 self.assertEqualXML(sent.toXml(), expected) | 277 self.assertEqualXML(sent.toXml(), expected) |
278 | 278 |
279 # Process the command with the profiles of each room users | 279 # Process the command with the profiles of each room users |
280 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) | 280 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) |
281 | 281 |
330 d.addCallbacks(cb, cb) | 330 d.addCallbacks(cb, cb) |
331 else: | 331 else: |
332 d.addCallbacks(eb, eb) | 332 d.addCallbacks(eb, eb) |
333 | 333 |
334 def test_init(self): | 334 def test_init(self): |
335 self.init() | 335 self.reinit() |
336 self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS) | 336 self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS) |
337 self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE) | 337 self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE) |
338 self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) | 338 self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) |
339 self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) | 339 self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) |
340 | 340 |
341 def test_game(self): | 341 def test_game(self): |
342 self.init() | 342 self.reinit() |
343 | 343 |
344 # create game | 344 # create game |
345 self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE) | 345 self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE) |
346 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) | 346 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
347 room = self.plugin_0045.getRoom(0, 0) | 347 room = self.plugin_0045.getRoom(0, 0) |
348 nicks = [self.plugin_0045.getNick(0, 0)] | 348 nicks = [self.plugin_0045.getNick(0, 0)] |
349 | 349 |
350 sent = self.host.getSentMessageRaw(0) | 350 sent = self.host.getSentMessage(0) |
351 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', self._buildPlayers(nicks))) | 351 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', self._buildPlayers(nicks))) |
352 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) | 352 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) |
353 | 353 |
354 self._joinRoom(room, nicks, 1) # player joins | 354 self._joinRoom(room, nicks, 1) # player joins |
355 self._joinRoom(room, nicks, 4) # user not playing joins | 355 self._joinRoom(room, nicks, 4) # user not playing joins |