Mercurial > libervia-backend
annotate libervia/backend/test/test_plugin_misc_radiocol.py @ 4322:00837fa13e5a default tip @
tools (common/template), cli (call/gui): use font-awesome instead of fontello:
following change in Libervia Media, code has been updated to use font-awesome now instead
of fontello.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 22:42:17 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
830
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 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.test import helpers, helpers_plugins |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.plugins import plugin_misc_radiocol as plugin |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.plugins import plugin_misc_room_game as plugin_room_game |
3028 | 27 from .constants import Const |
830
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( |
3028 | 43 "Missing module Mutagen, please download/install from https://bitbucket.org/lazka/mutagen" |
2624
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 | 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 | 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 | 64 def reinit(self): |
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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
76 self.host.get_client(profile) # init self.host.profiles[profile] |
830
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 = [] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
79 self.sound_dir = self.host.memory.config_get("", "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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
87 def _build_players(self, players=[]): |
830
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 += ">" |
3028 | 94 for i in range(0, len(players)): |
830
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
99 def _expected_message(self, to_jid, type_, content): |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 """ |
1412 | 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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
121 def _reject_song_cb(self, profile_index): |
830
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""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
125 sent = self.host.get_sent_message(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'/>" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
127 self.assert_equal_xml( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 sent.toXml(), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
129 self._expected_message( |
2624
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 + "/" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
133 + self.plugin_0045.get_nick(0, profile_index), |
2624
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 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
139 self._room_game_cmd( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
140 sent, ["radiocol_song_rejected", ROOM_JID.full(), "Too many songs in queue"] |
2624
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
143 def _no_upload_cb(self): |
830
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""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
146 sent = self.host.get_sent_message(0) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 content = "<no_upload xmlns=''/>" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
148 self.assert_equal_xml( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
149 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
151 self._room_game_cmd(sent, ["radiocol_no_upload", ROOM_JID.full()]) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
153 def _upload_ok_cb(self): |
830
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""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
156 sent = self.host.get_sent_message(0) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 content = "<upload_ok xmlns=''/>" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
158 self.assert_equal_xml( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
159 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
161 self._room_game_cmd(sent, ["radiocol_upload_ok", ROOM_JID.full()]) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
163 def _preload_cb(self, attrs, profile_index): |
830
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 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
169 sent = self.host.get_sent_message(0) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
170 attrs["sender"] = self.plugin_0045.get_nick(0, profile_index) |
3028 | 171 radiocol_elt = next(domish.generateElementsNamed(sent.elements(), "radiocol")) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
172 preload_elt = next( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
173 domish.generateElementsNamed(radiocol_elt.elements(), "preload") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
174 ) |
2624
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"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
181 self.assert_equal_xml( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
182 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
183 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
184 self._room_game_cmd( |
2624
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 [ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
187 "radiocol_preload", |
2624
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
198 def _play_next_song_cb(self): |
830
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""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
201 sent = self.host.get_sent_message(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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
204 self.assert_equal_xml( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
205 sent.toXml(), self._expected_message(ROOM_JID, "groupchat", content) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
206 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
207 self._room_game_cmd(sent, ["radiocol_play", ROOM_JID.full(), filename]) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
208 |
1412 | 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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
211 self._upload_ok_cb() |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
213 def _add_song_cb(self, d, filepath, profile_index): |
830
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
216 @param d: deferred value or failure got from self.plugin.radiocol_song_added |
830
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 | 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 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
253 sent = self.host.get_sent_message(profile_index) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
254 self.assert_equal_xml( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
255 sent.toXml(), self._expected_message(REFEREE_FULL, "normal", content) |
2624
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
265 self._room_game_cmd(sent, profile_index) # queue unchanged or +1 |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
266 if reject_song: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
267 self._reject_song_cb(profile_index) |
830
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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
270 self._no_upload_cb() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
271 self._preload_cb(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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
274 self._play_next_song_cb() # queue -1 |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
275 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
276 def _room_game_cmd(self, sent, from_index=0, call=[]): |
830
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
278 _room_game_cmd(sent, call) instead of _room_game_cmd(sent, from_index, call). |
830
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
290 sent["from"] = ROOM_JID.full() + "/" + self.plugin_0045.get_nick(0, from_index) |
2624
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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
297 room = self.plugin_0045.get_room(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 |
3028 | 304 for index in range(0, len(Const.PROFILE)): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
305 nick = self.plugin_0045.get_nick(0, index) |
830
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 ( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
309 self.plugin.is_player(ROOM_JID, nick) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
310 or call[0] == "radiocol_started" |
2624
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]) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
314 self.host.bridge.expect_call(*args) |
830
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
317 def _sync_cb(self, sync_data, profile_index): |
830
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: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
323 expected = self._expected_message( |
2624
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 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
326 sent = self.host.get_sent_message(0) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
327 self.assert_equal_xml(sent.toXml(), expected) |
830
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": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
330 self.host.bridge.expect_call( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
331 "radiocol_preload", |
2624
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": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
342 self.host.bridge.expect_call( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
343 "radiocol_play", |
2624
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": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
349 self.host.bridge.expect_call( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
350 "radiocol_no_upload", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
351 ROOM_JID.full(), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
352 Const.PROFILE[profile_index], |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
353 ) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 sync_data[nick] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
355 self._room_game_cmd(sent, []) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
356 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
357 def _join_room(self, room, nicks, player_index, sync=True): |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
358 """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
|
359 @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
|
360 @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
|
361 @param player_index: profile index of the new player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 @param sync: set to True to synchronize data |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
363 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
364 user_nick = self.plugin_0045.join_room(0, player_index) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
365 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 if player_index not in PLAYERS_INDICES: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 # this user is actually not a player |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
368 self.assertFalse(self.plugin.is_player(ROOM_JID, user_nick)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 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
|
370 else: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
371 # this user is a player |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
372 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick)) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
373 nicks.append(user_nick) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
374 to_jid, type_ = (ROOM_JID, "groupchat") |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
376 # Check that the message "players" has been sent by the referee |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
377 expected = self._expected_message(to_jid, type_, self._build_players(nicks)) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
378 sent = self.host.get_sent_message(0) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
379 self.assert_equal_xml(sent.toXml(), expected) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
380 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
381 # Process the command with the profiles of each room users |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
382 self._room_game_cmd( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
383 sent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
384 [ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
385 "radiocol_started", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
386 ROOM_JID.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 REFEREE_FULL.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 nicks, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
391 ) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
392 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
393 if sync: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
394 self._sync_cb(self.plugin._get_sync_data(ROOM_JID, [user_nick]), player_index) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
395 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
396 def _leave_room(self, room, nicks, player_index): |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
397 """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
|
398 @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
|
399 @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
|
400 @param player_index: profile index of the new player |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
401 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
402 user_nick = self.plugin_0045.get_nick(0, player_index) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
403 user = room.roster[user_nick] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
404 self.plugin_0045.leave_room(0, player_index) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
405 self.plugin.user_left_trigger(room, user, PROFILE) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
406 nicks.remove(user_nick) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
407 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
408 def _upload_song(self, song_index, profile_index): |
1915
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
409 """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
|
410 |
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
411 @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
|
412 @param profile_index: index of the uploader's profile |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
413 """ |
1915
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
414 if song_index is None: |
3028 | 415 dst_filepath = str(uuid.uuid1()) |
1915
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
416 expect_io_error = True |
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
417 else: |
fd959c8f64b6
test (plugin radiocol): fixes the test to also handle MP3 files
souliane <souliane@mailoo.org>
parents:
1909
diff
changeset
|
418 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
|
419 src_filename = self.songs[song_index] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 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
|
421 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
|
422 expect_io_error = False |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
423 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
424 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
425 d = self.plugin.radiocol_song_added( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 REFEREE_FULL, dst_filepath, Const.PROFILE[profile_index] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
427 ) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
428 except IOError: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
429 self.assertTrue(expect_io_error) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
430 return |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
431 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 self.assertFalse(expect_io_error) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
433 cb = lambda defer: self._add_song_cb(defer, dst_filepath, profile_index) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
435 def eb(failure): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 if not isinstance(failure, Failure): |
904
95dabdb0c799
test: update radiocol test regarding the last changes
souliane <souliane@mailoo.org>
parents:
861
diff
changeset
|
437 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
|
438 self.assertEqual(failure.value.__class__, exceptions.DataError) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
439 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 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
|
441 d.addCallbacks(cb, cb) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
442 else: |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
443 d.addCallbacks(eb, eb) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
444 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 def test_init(self): |
1271 | 446 self.reinit() |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 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
|
448 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
|
449 self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
450 self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 def test_game(self): |
1271 | 453 self.reinit() |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
454 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 # create game |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
456 self.plugin.prepare_room(OTHER_PLAYERS, ROOM_JID, PROFILE) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
457 self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
458 room = self.plugin_0045.get_room(0, 0) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
459 nicks = [self.plugin_0045.get_nick(0, 0)] |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
460 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
461 sent = self.host.get_sent_message(0) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
462 self.assert_equal_xml( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 sent.toXml(), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
464 self._expected_message(ROOM_JID, "groupchat", self._build_players(nicks)), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
465 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
466 self._room_game_cmd( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
467 sent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
468 [ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
469 "radiocol_started", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
470 ROOM_JID.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
471 REFEREE_FULL.full(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
472 nicks, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
473 [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
474 ], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
475 ) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
476 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
477 self._join_room(room, nicks, 1) # player joins |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
478 self._join_room(room, nicks, 4) # user not playing joins |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
479 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
480 song_index = 0 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
481 self._upload_song( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
482 song_index, 0 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
483 ) # ogg or mp3 file should exist in sat_media/test/song |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
484 self._upload_song(None, 0) # non existing file |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
485 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
486 # 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
|
487 # when the first song starts + 1 to be rejected because the queue is full |
3028 | 488 for song_index in range(1, plugin.QUEUE_TO_START + 1): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
489 self._upload_song(song_index, 1) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
490 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
491 self.plugin.play_next(Const.MUC[0], PROFILE) # simulate the end of the first song |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
492 self._play_next_song_cb() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
493 self._upload_song( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
494 song_index, 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
495 ) # 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
|
496 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
497 self._join_room(room, nicks, 3) # new player joins |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
498 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
499 self.plugin.play_next(Const.MUC[0], PROFILE) # the second song finishes |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
500 self._play_next_song_cb() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
501 self._upload_song(0, 3) # the player who recently joined re-upload the first file |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
502 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
503 self._leave_room(room, nicks, 1) # one player leaves |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
504 self._join_room(room, nicks, 1) # and join again |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
505 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
506 self.plugin.play_next(Const.MUC[0], PROFILE) # empty the queue |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
507 self._play_next_song_cb() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
508 self.plugin.play_next(Const.MUC[0], PROFILE) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
509 self._play_next_song_cb() |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
510 |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
511 for filename in self.playlist: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
512 self.plugin.delete_file("/tmp/" + filename) |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
513 |
849
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
830
diff
changeset
|
514 return defer.succeed(None) |
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
830
diff
changeset
|
515 |
830
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
516 def tearDown(self, *args, **kwargs): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
517 """Clean the reactor""" |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
518 helpers.SatTestCase.tearDown(self, *args, **kwargs) |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
519 for delayed_call in reactor.getDelayedCalls(): |
d6bdf6022180
test radiocol: added a full scenario test
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
520 delayed_call.cancel() |