annotate sat/test/test_plugin_misc_radiocol.py @ 2993:d58dccd9e4b4

primitivus (contact list): fixed notifications counter for mentions: notifications counter was not properly counting mentions and was not changing colour as expected, this patch fixes this and changed colour to the more readable light red when not focused. fixes 319
author Goffi <goffi@goffi.org>
date Mon, 08 Jul 2019 19:11:29 +0200
parents 56f94936df1e
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1915
diff changeset
1 #!/usr/bin/env python2
830
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 import exceptions
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from sat.test import helpers, helpers_plugins
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from sat.plugins import plugin_misc_radiocol as plugin
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
26 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
27 from constants import Const
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
28
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from twisted.words.protocols.jabber.jid import JID
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from twisted.words.xish import domish
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
31 from twisted.internet import reactor
849
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 830
diff changeset
32 from twisted.internet import defer
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
33 from twisted.python.failure import Failure
861
4d091738275c test: skip radiocol tests if the sound samples are not found
souliane <souliane@mailoo.org>
parents: 849
diff changeset
34 from twisted.trial.unittest import SkipTest
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
35
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
36 try:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
37 from mutagen.oggvorbis import OggVorbis
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
38 from mutagen.mp3 import MP3
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
39 from mutagen.easyid3 import EasyID3
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
40 from mutagen.id3 import ID3NoHeaderError
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
41 except ImportError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 raise exceptions.MissingModule(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 u"Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
45
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
46 import uuid
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
47 import os
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
48 import copy
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
49 import shutil
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
50
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
51
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
52 ROOM_JID = JID(Const.MUC_STR[0])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
53 PROFILE = Const.PROFILE[0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 REFEREE_FULL = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
55 PLAYERS_INDICES = [0, 1, 3] # referee included
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
56 OTHER_PROFILES = [Const.PROFILE[1], Const.PROFILE[3]]
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
57 OTHER_PLAYERS = [Const.JID[1], Const.JID[3]]
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
58
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
59
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
60 class RadiocolTest(helpers.SatTestCase):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
61 def setUp(self):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
62 self.host = helpers.FakeSAT()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
63
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
64 def reinit(self):
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
65 self.host.reinit()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 self.host.plugins["ROOM-GAME"] = plugin_room_game.RoomGame(self.host)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
67 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
68 self.plugin.testing = True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 self.plugin_0045 = self.host.plugins["XEP-0045"] = helpers_plugins.FakeXEP_0045(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 self.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 self.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
75 for profile in Const.PROFILE:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
76 self.host.getClient(profile) # init self.host.profiles[profile]
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
77 self.songs = []
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.playlist = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 self.sound_dir = self.host.memory.getConfig("", "media_dir") + "/test/sound/"
861
4d091738275c test: skip radiocol tests if the sound samples are not found
souliane <souliane@mailoo.org>
parents: 849
diff changeset
80 try:
4d091738275c test: skip radiocol tests if the sound samples are not found
souliane <souliane@mailoo.org>
parents: 849
diff changeset
81 for filename in os.listdir(self.sound_dir):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 if filename.endswith(".ogg") or filename.endswith(".mp3"):
861
4d091738275c test: skip radiocol tests if the sound samples are not found
souliane <souliane@mailoo.org>
parents: 849
diff changeset
83 self.songs.append(filename)
4d091738275c test: skip radiocol tests if the sound samples are not found
souliane <souliane@mailoo.org>
parents: 849
diff changeset
84 except OSError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 raise SkipTest("The sound samples in sat_media/test/sound were not found")
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
86
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
87 def _buildPlayers(self, players=[]):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
88 """@return: the "started" content built with the given players"""
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
89 content = "<started"
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
90 if not players:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
91 content += "/>"
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
92 else:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
93 content += ">"
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
94 for i in xrange(0, len(players)):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
95 content += "<player index='%s'>%s</player>" % (i, players[i])
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
96 content += "</started>"
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
97 return content
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
98
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
99 def _expectedMessage(self, to_jid, type_, content):
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
100 """
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
101 @param to_jid: recipient full jid
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
102 @param type_: message type ('normal' or 'groupchat')
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
103 @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
104 @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
105 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
106 if isinstance(content, list):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
107 new_content = copy.deepcopy(content)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
108 for element in new_content:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 if not element.hasAttribute("xmlns"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 element["xmlns"] = ""
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
111 content = "".join([element.toXml() for element in new_content])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</%s></message>" % (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 to_jid.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 type_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 plugin.RADIOC_TAG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 plugin.NC_RADIOCOL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 content,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 plugin.RADIOC_TAG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 )
830
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 _rejectSongCb(self, profile_index):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
122 """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
123 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
124 @param profile_index: uploader's profile"""
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
125 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
126 content = "<song_rejected xmlns='' reason='Too many songs in queue'/>"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 sent.toXml(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 self._expectedMessage(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 JID(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 ROOM_JID.userhost()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 + "/"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 + self.plugin_0045.getNick(0, profile_index),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 "normal",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 content,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 self._roomGameCmd(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 sent, ["radiocolSongRejected", ROOM_JID.full(), "Too many songs in queue"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
142
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
143 def _noUploadCb(self):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
144 """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
145 and process the command with the profiles of each room users"""
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
146 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
147 content = "<no_upload xmlns=''/>"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
149 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 self._roomGameCmd(sent, ["radiocolNoUpload", ROOM_JID.full()])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
152
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
153 def _uploadOkCb(self):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
154 """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
155 and process the command with the profiles of each room users"""
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
156 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
157 content = "<upload_ok xmlns=''/>"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
161 self._roomGameCmd(sent, ["radiocolUploadOk", ROOM_JID.full()])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
162
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
163 def _preloadCb(self, attrs, profile_index):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
164 """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
165 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
166 @param attrs: information dict about the song
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
167 @param profile_index: profile index of the uploader
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
168 """
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
169 sent = self.host.getSentMessage(0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 attrs["sender"] = self.plugin_0045.getNick(0, profile_index)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 radiocol_elt = domish.generateElementsNamed(sent.elements(), "radiocol").next()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 preload_elt = domish.generateElementsNamed(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 radiocol_elt.elements(), "preload"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 ).next()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 attrs["timestamp"] = preload_elt["timestamp"] # we could not guess it...
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 content = "<preload xmlns='' %s/>" % " ".join(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 if sent.hasAttribute("from"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 del sent["from"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 self._roomGameCmd(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
185 sent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
186 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
187 "radiocolPreload",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
188 ROOM_JID.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 attrs["timestamp"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 attrs["filename"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 attrs["title"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 attrs["artist"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 attrs["album"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 attrs["sender"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 )
830
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 _playNextSongCb(self):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
199 """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
200 and process the command with the profiles of each room users"""
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
201 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
202 filename = self.playlist.pop(0)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
203 content = "<play xmlns='' filename='%s' />" % filename
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 sent.toXml(), self._expectedMessage(ROOM_JID, "groupchat", content)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 self._roomGameCmd(sent, ["radiocolPlay", ROOM_JID.full(), filename])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
208
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
209 game_data = self.plugin.games[ROOM_JID]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 if len(game_data["queue"]) == plugin.QUEUE_LIMIT - 1:
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
211 self._uploadOkCb()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
212
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
213 def _addSongCb(self, d, filepath, profile_index):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
214 """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
215 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
216 @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
217 @param filepath: full path to the sound file
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
218 @param profile_index: the profile index of the uploader
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
219 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
220 if isinstance(d, Failure):
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
221 self.fail("OGG or MP3 song could not be added!")
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
222
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
223 game_data = self.plugin.games[ROOM_JID]
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
224
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
225 # this is copied from the plugin
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
226 if filepath.lower().endswith(".mp3"):
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
227 actual_song = MP3(filepath)
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
228 try:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
229 song = EasyID3(filepath)
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
230
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
231 class Info(object):
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
232 def __init__(self, length):
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
233 self.length = length
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
235 song.info = Info(actual_song.info.length)
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
236 except ID3NoHeaderError:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
237 song = actual_song
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
238 else:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
239 song = OggVorbis(filepath)
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
240
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 attrs = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 "filename": os.path.basename(filepath),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 "title": song.get("title", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 "artist": song.get("artist", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 "album": song.get("album", ["Unknown"])[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
246 "length": str(song.info.length),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
247 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248 self.assertEqual(game_data["to_delete"][attrs["filename"]], filepath)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
249
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 content = "<song_added xmlns='' %s/>" % " ".join(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 ["%s='%s'" % (attr, attrs[attr]) for attr in attrs]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
252 )
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
253 sent = self.host.getSentMessage(profile_index)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 sent.toXml(), self._expectedMessage(REFEREE_FULL, "normal", content)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
257
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
258 reject_song = len(game_data["queue"]) >= plugin.QUEUE_LIMIT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
259 no_upload = len(game_data["queue"]) + 1 >= plugin.QUEUE_LIMIT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 play_next = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
261 not game_data["playing"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
262 and len(game_data["queue"]) + 1 == plugin.QUEUE_TO_START
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
264
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
265 self._roomGameCmd(sent, profile_index) # queue unchanged or +1
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
266 if reject_song:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
267 self._rejectSongCb(profile_index)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
268 return
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
269 if no_upload:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
270 self._noUploadCb()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
271 self._preloadCb(attrs, profile_index)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 self.playlist.append(attrs["filename"])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
273 if play_next:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
274 self._playNextSongCb() # queue -1
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
275
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
276 def _roomGameCmd(self, sent, from_index=0, call=[]):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
277 """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
278 _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
279 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
280 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
281 @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
282 @param from_index: index of the message sender
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
283 @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
284 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
285 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
286 if isinstance(from_index, list):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
287 call = from_index
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
288 from_index = 0
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
289
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
290 sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.getNick(0, from_index)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
291 recipient = JID(sent["to"]).resource
830
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 # 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
294 # 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
295 # 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
296 if recipient:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
297 room = self.plugin_0045.getRoom(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 sent["to"] = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 Const.JID_STR[0]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 if recipient == room.nick
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
301 else room.roster[recipient].entity.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
303
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
304 for index in xrange(0, len(Const.PROFILE)):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
305 nick = self.plugin_0045.getNick(0, index)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
306 if nick:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
307 if not recipient or nick == recipient:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 if call and (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
309 self.plugin.isPlayer(ROOM_JID, nick)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 or call[0] == "radiocolStarted"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 ):
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
312 args = copy.deepcopy(call)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
313 args.append(Const.PROFILE[index])
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
314 self.host.bridge.expectCall(*args)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
315 self.plugin.room_game_cmd(sent, Const.PROFILE[index])
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
316
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
317 def _syncCb(self, sync_data, profile_index):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
318 """Synchronize one player when he joins a running game.
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
319 @param sync_data: result from self.plugin.getSyncData
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
320 @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
321 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
322 for nick in sync_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 expected = self._expectedMessage(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 JID(ROOM_JID.userhost() + "/" + nick), "normal", sync_data[nick]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 )
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
326 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
327 self.assertEqualXML(sent.toXml(), expected)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
328 for elt in sync_data[nick]:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
329 if elt.name == "preload":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 self.host.bridge.expectCall(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 "radiocolPreload",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
332 ROOM_JID.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 elt["timestamp"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
334 elt["filename"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 elt["title"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
336 elt["artist"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
337 elt["album"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
338 elt["sender"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
339 Const.PROFILE[profile_index],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
340 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
341 elif elt.name == "play":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
342 self.host.bridge.expectCall(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
343 "radiocolPlay",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
344 ROOM_JID.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
345 elt["filename"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
346 Const.PROFILE[profile_index],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
347 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
348 elif elt.name == "no_upload":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
349 self.host.bridge.expectCall(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
350 "radiocolNoUpload", ROOM_JID.full(), Const.PROFILE[profile_index]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
351 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
352 sync_data[nick]
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
353 self._roomGameCmd(sent, [])
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
354
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
355 def _joinRoom(self, room, nicks, player_index, sync=True):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
356 """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
357 @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
358 @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
359 @param player_index: profile index of the new player
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
360 @param sync: set to True to synchronize data
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
361 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
362 user_nick = self.plugin_0045.joinRoom(0, player_index)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
363 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
364 if player_index not in PLAYERS_INDICES:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
365 # this user is actually not a player
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
366 self.assertFalse(self.plugin.isPlayer(ROOM_JID, user_nick))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
367 to_jid, type_ = (JID(ROOM_JID.userhost() + "/" + user_nick), "normal")
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
368 else:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
369 # this user is a player
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
370 self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
371 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
372 to_jid, type_ = (ROOM_JID, "groupchat")
830
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 # 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
375 expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks))
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
376 sent = self.host.getSentMessage(0)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
377 self.assertEqualXML(sent.toXml(), expected)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
378
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
379 # Process the command with the profiles of each room users
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
380 self._roomGameCmd(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
381 sent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
382 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
383 "radiocolStarted",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
384 ROOM_JID.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
385 REFEREE_FULL.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
386 nicks,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
387 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
388 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
389 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
390
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
391 if sync:
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
392 self._syncCb(self.plugin._getSyncData(ROOM_JID, [user_nick]), player_index)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
393
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
394 def _leaveRoom(self, room, nicks, player_index):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
395 """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
396 @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
397 @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
398 @param player_index: profile index of the new player
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
399 """
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
400 user_nick = self.plugin_0045.getNick(0, player_index)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
401 user = room.roster[user_nick]
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
402 self.plugin_0045.leaveRoom(0, player_index)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
403 self.plugin.userLeftTrigger(room, user, PROFILE)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
404 nicks.remove(user_nick)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
405
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
406 def _uploadSong(self, song_index, profile_index):
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
407 """Upload the song of index song_index (modulo self.songs size) from the profile of index profile_index.
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
408
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
409 @param song_index: index of the song or None to test with non existing file
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
410 @param profile_index: index of the uploader's profile
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
411 """
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
412 if song_index is None:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
413 dst_filepath = unicode(uuid.uuid1())
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
414 expect_io_error = True
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
415 else:
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
416 song_index = song_index % len(self.songs)
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
417 src_filename = self.songs[song_index]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
418 dst_filepath = "/tmp/%s%s" % (uuid.uuid1(), os.path.splitext(src_filename)[1])
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
419 shutil.copy(self.sound_dir + src_filename, dst_filepath)
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
420 expect_io_error = False
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
421
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
422 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
423 d = self.plugin.radiocolSongAdded(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
424 REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
425 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
426 except IOError:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
427 self.assertTrue(expect_io_error)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
428 return
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
429
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
430 self.assertFalse(expect_io_error)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
431 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
432
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
433 def eb(failure):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
434 if not isinstance(failure, Failure):
904
95dabdb0c799 test: update radiocol test regarding the last changes
souliane <souliane@mailoo.org>
parents: 861
diff changeset
435 self.fail("Adding a song which is not OGG nor MP3 should fail!")
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
436 self.assertEqual(failure.value.__class__, exceptions.DataError)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
437
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
438 if src_filename.endswith(".ogg") or src_filename.endswith(".mp3"):
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
439 d.addCallbacks(cb, cb)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
440 else:
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
441 d.addCallbacks(eb, eb)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
442
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
443 def test_init(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
444 self.reinit()
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
445 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
446 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
447 self.assertEqual(self.plugin.join_mode, self.plugin.INVITED)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
448 self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
449
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
450 def test_game(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
451 self.reinit()
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
452
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
453 # create game
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
454 self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID, PROFILE)
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
455 self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
456 room = self.plugin_0045.getRoom(0, 0)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
457 nicks = [self.plugin_0045.getNick(0, 0)]
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
458
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
459 sent = self.host.getSentMessage(0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
460 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
461 sent.toXml(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
462 self._expectedMessage(ROOM_JID, "groupchat", self._buildPlayers(nicks)),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
463 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
464 self._roomGameCmd(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
465 sent,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
466 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
467 "radiocolStarted",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
468 ROOM_JID.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
469 REFEREE_FULL.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
470 nicks,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
471 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
472 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
473 )
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
474
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
475 self._joinRoom(room, nicks, 1) # player joins
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
476 self._joinRoom(room, nicks, 4) # user not playing joins
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
477
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
478 song_index = 0
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
479 self._uploadSong(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 song_index, 0
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
481 ) # ogg or mp3 file should exist in sat_media/test/song
1915
fd959c8f64b6 test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents: 1909
diff changeset
482 self._uploadSong(None, 0) # non existing file
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
483
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
484 # 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
485 # 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
486 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
487 self._uploadSong(song_index, 1)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
488
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
489 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
490 self._playNextSongCb()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
491 self._uploadSong(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
492 song_index, 1
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
493 ) # now the song is accepted and the queue is full again
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
494
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
495 self._joinRoom(room, nicks, 3) # new player joins
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
496
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
497 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
498 self._playNextSongCb()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
499 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
500
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
501 self._leaveRoom(room, nicks, 1) # one player leaves
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
502 self._joinRoom(room, nicks, 1) # and join again
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
503
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
504 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
505 self._playNextSongCb()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
506 self.plugin.playNext(Const.MUC[0], PROFILE)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
507 self._playNextSongCb()
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
508
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
509 for filename in self.playlist:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
510 self.plugin.deleteFile("/tmp/" + filename)
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
511
849
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 830
diff changeset
512 return defer.succeed(None)
c5a8f602662b plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents: 830
diff changeset
513
830
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
514 def tearDown(self, *args, **kwargs):
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
515 """Clean the reactor"""
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
516 helpers.SatTestCase.tearDown(self, *args, **kwargs)
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
517 for delayed_call in reactor.getDelayedCalls():
d6bdf6022180 test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff changeset
518 delayed_call.cancel()