Mercurial > libervia-backend
annotate src/test/test_plugin_misc_radiocol.py @ 857:3c270d691e56
test: fix the tests for plugin room game
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 20 Feb 2014 17:51:51 +0100 |
parents | c5a8f602662b |
children | 4d091738275c |
rev | line source |
---|---|
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # SAT: a jabber client |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # This program is free software: you can redistribute it and/or modify |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # it under the terms of the GNU Affero General Public License as published by |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # the Free Software Foundation, either version 3 of the License, or |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 # (at your option) any later version. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # This program is distributed in the hope that it will be useful, |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 # GNU Affero General Public License for more details. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Affero General Public License |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 """ Tests for the plugin radiocol """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from sat.core import exceptions |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 from sat.test import helpers, helpers_plugins |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 from sat.plugins import plugin_misc_radiocol as plugin |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 from sat.plugins import plugin_misc_room_game as plugin_room_game |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 from constants import Const |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 from twisted.words.protocols.jabber.jid import JID |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 from twisted.words.xish import domish |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 from twisted.internet import reactor |
849
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
830
diff
changeset
|
33 from twisted.internet import defer |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
34 from twisted.python.failure import Failure |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
35 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
36 from mutagen.oggvorbis import OggVorbis |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 import uuid |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 import logging |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 import os |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 import copy |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 import shutil |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 ROOM_JID_S = Const.MUC_STR[0] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 PROFILE = Const.PROFILE[0] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 REFEREE_FULL = ROOM_JID_S + '/' + Const.JID[0].user |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 PLAYERS_INDICES = [0, 1, 3] # referee included |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
48 OTHER_PROFILES = [Const.PROFILE[1], Const.PROFILE[3]] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
49 OTHER_PLAYERS = [Const.JID_STR[1], Const.JID_STR[3]] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
50 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
52 class RadiocolTest(helpers.SatTestCase): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
53 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
54 def setUp(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
55 self.host = helpers.FakeSAT() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 def init(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 self.host.init() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 self.host.plugins['ROOM-GAME'] = plugin_room_game.RoomGame(self.host) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 self.plugin = plugin.Radiocol(self.host) # must be init after ROOM-GAME |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 self.plugin.testing = True |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 logger = logging.getLogger() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 level = logger.getEffectiveLevel() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 logger.setLevel(logging.WARNING) # remove info pollution |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 for profile in Const.PROFILE: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 self.host.getClient(profile) # init self.host.profiles[profile] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 logger.setLevel(level) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
70 self.songs = [] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 self.playlist = [] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 self.sound_dir = self.host.memory.getConfig('', 'media_dir') + '/test/sound/' |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 for filename in os.listdir(self.sound_dir): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 if filename.endswith('.ogg'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 self.songs.append(filename) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 def _buildPlayers(self, players=[]): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 """@return: the "started" content built with the given players""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 content = "<started" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 if not players: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 content += "/>" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 else: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 content += ">" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 for i in xrange(0, len(players)): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 content += "<player index='%s'>%s</player>" % (i, players[i]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 content += "</started>" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 return content |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 def _expectedMessage(self, to_s, type_, content): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 @param to_s: recipient full jid as unicode |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 @param type_: message type ('normal' or 'groupchat') |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 @param content: content as unicode or list of domish elements |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 @return: the message XML built from the given recipient, message type and content |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 if isinstance(content, list): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 new_content = copy.deepcopy(content) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 for element in new_content: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 if not element.hasAttribute('xmlns'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 element['xmlns'] = '' |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 content = "".join([element.toXml() for element in new_content]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</%s></message>" % (to_s, type_, plugin.RADIOC_TAG, plugin.NC_RADIOCOL, content, plugin.RADIOC_TAG) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 def _rejectSongCb(self, profile_index): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 """Check if the message "song_rejected" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 and process the command with the profile of the uploader |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 @param profile_index: uploader's profile""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S + '/' + self.plugin_0045.getNick(0, profile_index), 'normal', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 self._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID_S, 'Too many songs in queue']) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 def _noUploadCb(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 """Check if the message "no_upload" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 and process the command with the profiles of each room users""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
116 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
117 content = "<no_upload xmlns=''/>" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
119 self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
120 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 def _uploadOkCb(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 """Check if the message "upload_ok" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 and process the command with the profiles of each room users""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 content = "<upload_ok xmlns=''/>" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 def _preloadCb(self, attrs, profile_index): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 """Check if the message "preload" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 and process the command with the profiles of each room users |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 @param attrs: information dict about the song |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 @param profile_index: profile index of the uploader |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 attrs['sender'] = self.plugin_0045.getNick(0, profile_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
137 radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
139 attrs['timestamp'] = preload_elt['timestamp'] # we could not guess it... |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 content = "<preload xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 if sent.hasAttribute('from'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
142 del sent['from'] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
143 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID_S, attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album']]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
146 def _playNextSongCb(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 """Check if the message "play" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 and process the command with the profiles of each room users""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
149 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 filename = self.playlist.pop(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 content = "<play xmlns='' filename='%s' />" % filename |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
153 self._roomGameCmd(sent, ['radiocolPlay', ROOM_JID_S, filename]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
155 game_data = self.plugin.games[ROOM_JID_S] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 if len(game_data['queue']) == plugin.QUEUE_LIMIT - 1: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 self._uploadOkCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 def _addSongCb(self, d, filepath, profile_index): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
160 """Check if the message "song_added" has been sent by the uploader |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
161 and process the command with the profile of the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 @param d: deferred value or failure got from self.plugin.radiocolSongAdded |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 @param filepath: full path to the sound file |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 @param profile_index: the profile index of the uploader |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 if isinstance(d, Failure): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
167 self.fail("OGG song could not be added!") |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
168 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
169 game_data = self.plugin.games[ROOM_JID_S] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 song = OggVorbis(filepath) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
171 attrs = {'filename': os.path.basename(filepath), |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 'title': song.get("title", ["Unknown"])[0], |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 'artist': song.get("artist", ["Unknown"])[0], |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
174 'album': song.get("album", ["Unknown"])[0], |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
175 'length': str(song.info.length) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 } |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 self.assertEqual(game_data['to_delete'][attrs['filename']], filepath) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
178 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
179 content = "<song_added xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 sent = self.host.getSentMessageRaw(profile_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 self.assertEqualXML(sent.toXml(), self._expectedMessage(REFEREE_FULL, 'normal', content)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 no_upload = len(game_data['queue']) + 1 >= plugin.QUEUE_LIMIT |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 play_next = not game_data['playing'] and len(game_data['queue']) + 1 == plugin.QUEUE_TO_START |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 self._roomGameCmd(sent, profile_index) # queue unchanged or +1 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
188 if reject_song: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
189 self._rejectSongCb(profile_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
190 return |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
191 if no_upload: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
192 self._noUploadCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 self._preloadCb(attrs, profile_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 self.playlist.append(attrs['filename']) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 if play_next: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 self._playNextSongCb() # queue -1 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 def _roomGameCmd(self, sent, from_index=0, call=[]): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 """Process a command. It is also possible to call this method as |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 _roomGameCmd(sent, call) instead of _roomGameCmd(sent, from_index, call). |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 If from index is a list, it is assumed that it is containing the value |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 for call and from_index will take its default value. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
203 @param sent: the sent message that we need to process |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
204 @param from_index: index of the message sender |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
205 @param call: list containing the name of the expected bridge call |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 followed by its arguments, or empty list if no call is expected |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
207 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 if isinstance(from_index, list): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
209 call = from_index |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
210 from_index = 0 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
211 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 sent['from'] = ROOM_JID_S + '/' + self.plugin_0045.getNick(0, from_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 recipient = JID(sent['to']).resource |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 # The message could have been sent to a room user (room_jid + '/' + nick), |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 # but when it is received, the 'to' attribute of the message has been |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 # changed to the recipient own JID. We need to simulate that here. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 if recipient: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 room = self.plugin_0045.getRoom(0, 0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 sent['to'] = Const.JID_STR[0] if recipient == room.nick else room.roster[recipient].entity.full() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
222 for index in xrange(0, len(Const.PROFILE)): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
223 nick = self.plugin_0045.getNick(0, index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
224 if nick: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 if not recipient or nick == recipient: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
226 if call and (self.plugin.isPlayer(ROOM_JID_S, nick) or call[0] == 'radiocolStarted'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
227 args = copy.deepcopy(call) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
228 args.append(Const.PROFILE[index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
229 self.host.bridge.expectCall(*args) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
230 self.plugin.room_game_cmd(sent, Const.PROFILE[index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
231 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
232 def _syncCb(self, sync_data, profile_index): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 """Synchronize one player when he joins a running game. |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 @param sync_data: result from self.plugin.getSyncData |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 @param profile_index: index of the profile to be synchronized |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 for nick in sync_data: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 self.assertEqualXML(sent.toXml(), expected) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
241 for elt in sync_data[nick]: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
242 if elt.name == 'preload': |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
243 self.host.bridge.expectCall('radiocolPreload', ROOM_JID_S, elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], Const.PROFILE[profile_index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
244 elif elt.name == 'play': |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
245 self.host.bridge.expectCall('radiocolPlay', ROOM_JID_S, elt['filename'], Const.PROFILE[profile_index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
246 elif elt.name == 'no_upload': |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
247 self.host.bridge.expectCall('radiocolNoUpload', ROOM_JID_S, Const.PROFILE[profile_index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
248 sync_data[nick] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
249 self._roomGameCmd(sent, []) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
250 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 def _joinRoom(self, room, nicks, player_index, sync=True): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
252 """Make a player join a room and update the list of nicks |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
253 @param room: wokkel.muc.Room instance from the referee perspective |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
254 @param nicks: list of the players which will be updated |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
255 @param player_index: profile index of the new player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 @param sync: set to True to synchronize data |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 user_nick = self.plugin_0045.joinRoom(0, player_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 if player_index not in PLAYERS_INDICES: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 # this user is actually not a player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, user_nick)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 to_jid, type_ = (ROOM_JID_S + '/' + user_nick, 'normal') |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
264 else: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
265 # this user is a player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
267 nicks.append(user_nick) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
268 to_jid, type_ = (ROOM_JID_S, 'groupchat') |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
269 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 # Check that the message "players" has been sent by the referee |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
271 expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
272 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
273 self.assertEqualXML(sent.toXml(), expected) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
274 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 # Process the command with the profiles of each room users |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
276 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
277 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
278 if sync: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
279 self._syncCb(self.plugin._getSyncData(ROOM_JID_S, [user_nick]), player_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 def _leaveRoom(self, room, nicks, player_index): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 """Make a player leave a room and update the list of nicks |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 @param room: wokkel.muc.Room instance from the referee perspective |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 @param nicks: list of the players which will be updated |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 @param player_index: profile index of the new player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 user_nick = self.plugin_0045.getNick(0, player_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 user = room.roster[user_nick] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 self.plugin_0045.leaveRoom(0, player_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 self.plugin.userLeftTrigger(room, user, PROFILE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
291 nicks.remove(user_nick) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
292 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
293 def _uploadSong(self, song_index, profile_index, ext='ogg'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
294 """Upload the song of index song_index (modulo self.songs size) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 from the profile of index profile_index. All the songs in self.songs |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
296 are OGG, but you can set ext to a value different than 'ogg': |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
297 - 'mp3' to test unsupported file format (MP3 file should exist) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 - 'xxx' to test non existent files |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 @param song_index: index of the song |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 @param profile_index: index of the uploader's profile |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 @param new_ext: change the extension from "ogg" to this value |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 """ |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 song_index = song_index % len(self.songs) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 src_filename = self.songs[song_index] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 if ext != 'ogg': |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 src_filename.replace('ogg', ext) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 dst_filepath = '/tmp/%s.%s' % (uuid.uuid1(), ext) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 expect_io_error = ext == 'xxx' |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
309 if not expect_io_error: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
310 shutil.copy(self.sound_dir + src_filename, dst_filepath) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
311 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
312 try: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
313 d = self.plugin.radiocolSongAdded(REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
314 except IOError: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
315 self.assertTrue(expect_io_error) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
316 return |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
317 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
318 self.assertFalse(expect_io_error) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
319 cb = lambda defer: self._addSongCb(defer, dst_filepath, profile_index) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
320 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
321 def eb(failure): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
322 if not isinstance(failure, Failure): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
323 self.fail("Adding a song which is not OGG should fail!") |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
324 self.assertEqual(failure.value.__class__, exceptions.DataError) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
325 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
326 if self.songs[song_index].endswith('.ogg'): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
327 d.addCallbacks(cb, cb) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
328 else: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
329 d.addCallbacks(eb, eb) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
330 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 def test_init(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 self.init() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 def test_game(self): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 self.init() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 # create game |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 room = self.plugin_0045.getRoom(0, 0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 nicks = [self.plugin_0045.getNick(0, 0)] |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 sent = self.host.getSentMessageRaw(0) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', self._buildPlayers(nicks))) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
349 self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]]) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
351 self._joinRoom(room, nicks, 1) # player joins |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
352 self._joinRoom(room, nicks, 4) # user not playing joins |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
353 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 song_index = 0 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 self._uploadSong(song_index, 0) # ogg file should exist in sat_media/test/song |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 self._uploadSong(song_index, 0, 'mp3') # mp3 file should exist in sat_media/test/song |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 self._uploadSong(song_index, 0, 'xxx') # file should not exist |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
359 # another songs are added by Const.JID[1] until the radio starts + 1 to fill the queue |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
360 # when the first song starts + 1 to be rejected because the queue is full |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 for song_index in xrange(1, plugin.QUEUE_TO_START + 1): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 self._uploadSong(song_index, 1) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
364 self.plugin.playNext(Const.MUC[0], PROFILE) # simulate the end of the first song |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 self._playNextSongCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 self._uploadSong(song_index, 1) # now the song is accepted and the queue is full again |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
368 self._joinRoom(room, nicks, 3) # new player joins |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
370 self.plugin.playNext(Const.MUC[0], PROFILE) # the second song finishes |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 self._playNextSongCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
372 self._uploadSong(0, 3) # the player who recently joined re-upload the first file |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 self._leaveRoom(room, nicks, 1) # one player leaves |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 self._joinRoom(room, nicks, 1) # and join again |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 self.plugin.playNext(Const.MUC[0], PROFILE) # empty the queue |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 self._playNextSongCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
379 self.plugin.playNext(Const.MUC[0], PROFILE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 self._playNextSongCb() |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
382 for filename in self.playlist: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
383 self.plugin.deleteFile('/tmp/' + filename) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
384 |
849
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
830
diff
changeset
|
385 return defer.succeed(None) |
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
830
diff
changeset
|
386 |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
387 def tearDown(self, *args, **kwargs): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
388 """Clean the reactor""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 helpers.SatTestCase.tearDown(self, *args, **kwargs) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 for delayed_call in reactor.getDelayedCalls(): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
391 delayed_call.cancel() |