diff src/test/test_plugin_misc_radiocol.py @ 1412:979210da778a

test: fix the tests
author souliane <souliane@mailoo.org>
date Fri, 17 Apr 2015 19:06:39 +0200
parents 2308f8405ffb
children 0681d69cbe0a
line wrap: on
line diff
--- a/src/test/test_plugin_misc_radiocol.py	Fri Apr 17 19:05:37 2015 +0200
+++ b/src/test/test_plugin_misc_radiocol.py	Fri Apr 17 19:06:39 2015 +0200
@@ -42,12 +42,12 @@
 import shutil
 from logging import WARNING
 
-ROOM_JID_S = Const.MUC_STR[0]
+ROOM_JID = JID(Const.MUC_STR[0])
 PROFILE = Const.PROFILE[0]
-REFEREE_FULL = ROOM_JID_S + '/' + Const.JID[0].user
+REFEREE_FULL = JID(ROOM_JID.userhost() + '/' + Const.JID[0].user)
 PLAYERS_INDICES = [0, 1, 3]  # referee included
 OTHER_PROFILES = [Const.PROFILE[1], Const.PROFILE[3]]
-OTHER_PLAYERS = [Const.JID_STR[1], Const.JID_STR[3]]
+OTHER_PLAYERS = [Const.JID[1], Const.JID[3]]
 
 
 class RadiocolTest(helpers.SatTestCase):
@@ -62,12 +62,8 @@
         self.plugin.testing = True
         self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host)
         self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host)
-        logger = getLogger()
-        level = logger.getEffectiveLevel()
-        logger.setLevel(WARNING)  # remove log.info pollution
         for profile in Const.PROFILE:
             self.host.getClient(profile)  # init self.host.profiles[profile]
-        logger.setLevel(level)
         self.songs = []
         self.playlist = []
         self.sound_dir = self.host.memory.getConfig('', 'media_dir') + '/test/sound/'
@@ -90,9 +86,9 @@
             content += "</started>"
         return content
 
-    def _expectedMessage(self, to_s, type_, content):
+    def _expectedMessage(self, to_jid, type_, content):
         """
-        @param to_s: recipient full jid as unicode
+        @param to_jid: recipient full jid
         @param type_: message type ('normal' or 'groupchat')
         @param content: content as unicode or list of domish elements
         @return: the message XML built from the given recipient, message type and content
@@ -103,7 +99,7 @@
                 if not element.hasAttribute('xmlns'):
                     element['xmlns'] = ''
             content = "".join([element.toXml() for element in new_content])
-        return "<message to='%s' type='%s'><%s xmlns='%s'>%s</%s></message>" % (to_s, type_, plugin.RADIOC_TAG, plugin.NC_RADIOCOL, content, plugin.RADIOC_TAG)
+        return "<message to='%s' type='%s'><%s xmlns='%s'>%s</%s></message>" % (to_jid.full(), type_, plugin.RADIOC_TAG, plugin.NC_RADIOCOL, content, plugin.RADIOC_TAG)
 
     def _rejectSongCb(self, profile_index):
         """Check if the message "song_rejected" has been sent by the referee
@@ -111,24 +107,24 @@
         @param profile_index: uploader's profile"""
         sent = self.host.getSentMessage(0)
         content = "<song_rejected xmlns='' reason='Too many songs in queue'/>"
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S + '/' + self.plugin_0045.getNick(0, profile_index), 'normal', content))
-        self._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID_S, 'Too many songs in queue'])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(JID(ROOM_JID.userhost() + '/' + self.plugin_0045.getNick(0, profile_index), 'normal', content)))
+        self._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID.full(), 'Too many songs in queue'])
 
     def _noUploadCb(self):
         """Check if the message "no_upload" has been sent by the referee
         and process the command with the profiles of each room users"""
         sent = self.host.getSentMessage(0)
         content = "<no_upload xmlns=''/>"
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
-        self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID, 'groupchat', content))
+        self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID.full()])
 
     def _uploadOkCb(self):
         """Check if the message "upload_ok" has been sent by the referee
         and process the command with the profiles of each room users"""
         sent = self.host.getSentMessage(0)
         content = "<upload_ok xmlns=''/>"
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
-        self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID, 'groupchat', content))
+        self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID.full()])
 
     def _preloadCb(self, attrs, profile_index):
         """Check if the message "preload" has been sent by the referee
@@ -144,8 +140,8 @@
         content = "<preload xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs])
         if sent.hasAttribute('from'):
             del sent['from']
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
-        self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID_S, attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album'], attrs['sender']])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID, 'groupchat', content))
+        self._roomGameCmd(sent, ['radiocolPreload', ROOM_JID.full(), attrs['timestamp'], attrs['filename'], attrs['title'], attrs['artist'], attrs['album'], attrs['sender']])
 
     def _playNextSongCb(self):
         """Check if the message "play" has been sent by the referee
@@ -153,10 +149,10 @@
         sent = self.host.getSentMessage(0)
         filename = self.playlist.pop(0)
         content = "<play xmlns='' filename='%s' />" % filename
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
-        self._roomGameCmd(sent, ['radiocolPlay', ROOM_JID_S, filename])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID, 'groupchat', content))
+        self._roomGameCmd(sent, ['radiocolPlay', ROOM_JID.full(), filename])
 
-        game_data = self.plugin.games[ROOM_JID_S]
+        game_data = self.plugin.games[ROOM_JID]
         if len(game_data['queue']) == plugin.QUEUE_LIMIT - 1:
             self._uploadOkCb()
 
@@ -170,7 +166,7 @@
         if isinstance(d, Failure):
             self.fail("OGG song could not be added!")
 
-        game_data = self.plugin.games[ROOM_JID_S]
+        game_data = self.plugin.games[ROOM_JID]
         song = OggVorbis(filepath)
         attrs = {'filename': os.path.basename(filepath),
                  'title': song.get("title", ["Unknown"])[0],
@@ -213,7 +209,7 @@
             call = from_index
             from_index = 0
 
-        sent['from'] = ROOM_JID_S + '/' + self.plugin_0045.getNick(0, from_index)
+        sent['from'] = ROOM_JID.full() + '/' + self.plugin_0045.getNick(0, from_index)
         recipient = JID(sent['to']).resource
 
         # The message could have been sent to a room user (room_jid + '/' + nick),
@@ -227,7 +223,7 @@
             nick = self.plugin_0045.getNick(0, index)
             if nick:
                 if not recipient or nick == recipient:
-                    if call and (self.plugin.isPlayer(ROOM_JID_S, nick) or call[0] == 'radiocolStarted'):
+                    if call and (self.plugin.isPlayer(ROOM_JID, nick) or call[0] == 'radiocolStarted'):
                         args = copy.deepcopy(call)
                         args.append(Const.PROFILE[index])
                         self.host.bridge.expectCall(*args)
@@ -239,16 +235,16 @@
         @param profile_index: index of the profile to be synchronized
         """
         for nick in sync_data:
-            expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick])
+            expected = self._expectedMessage(JID(ROOM_JID.userhost() + '/' + nick), 'normal', sync_data[nick])
             sent = self.host.getSentMessage(0)
             self.assertEqualXML(sent.toXml(), expected)
             for elt in sync_data[nick]:
                 if elt.name == 'preload':
-                    self.host.bridge.expectCall('radiocolPreload', ROOM_JID_S, elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], elt['sender'], Const.PROFILE[profile_index])
+                    self.host.bridge.expectCall('radiocolPreload', ROOM_JID.full(), elt['timestamp'], elt['filename'], elt['title'], elt['artist'], elt['album'], elt['sender'], Const.PROFILE[profile_index])
                 elif elt.name == 'play':
-                    self.host.bridge.expectCall('radiocolPlay', ROOM_JID_S, elt['filename'], Const.PROFILE[profile_index])
+                    self.host.bridge.expectCall('radiocolPlay', ROOM_JID.full(), elt['filename'], Const.PROFILE[profile_index])
                 elif elt.name == 'no_upload':
-                    self.host.bridge.expectCall('radiocolNoUpload', ROOM_JID_S, Const.PROFILE[profile_index])
+                    self.host.bridge.expectCall('radiocolNoUpload', ROOM_JID.full(), Const.PROFILE[profile_index])
             sync_data[nick]
             self._roomGameCmd(sent, [])
 
@@ -263,13 +259,13 @@
         self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
         if player_index not in PLAYERS_INDICES:
             # this user is actually not a player
-            self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, user_nick))
-            to_jid, type_ = (ROOM_JID_S + '/' + user_nick, 'normal')
+            self.assertFalse(self.plugin.isPlayer(ROOM_JID, user_nick))
+            to_jid, type_ = (JID(ROOM_JID.userhost() + '/' + user_nick), 'normal')
         else:
             # this user is a player
-            self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
+            self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
             nicks.append(user_nick)
-            to_jid, type_ = (ROOM_JID_S, 'groupchat')
+            to_jid, type_ = (ROOM_JID, 'groupchat')
 
         # Check that the message "players" has been sent by the referee
         expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks))
@@ -277,10 +273,10 @@
         self.assertEqualXML(sent.toXml(), expected)
 
         # Process the command with the profiles of each room users
-        self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])
+        self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID.full(), REFEREE_FULL.full(), nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])
 
         if sync:
-            self._syncCb(self.plugin._getSyncData(ROOM_JID_S, [user_nick]), player_index)
+            self._syncCb(self.plugin._getSyncData(ROOM_JID, [user_nick]), player_index)
 
     def _leaveRoom(self, room, nicks, player_index):
         """Make a player leave a room and update the list of nicks
@@ -342,14 +338,14 @@
         self.reinit()
 
         # create game
-        self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE)
-        self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
+        self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID, PROFILE)
+        self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
         room = self.plugin_0045.getRoom(0, 0)
         nicks = [self.plugin_0045.getNick(0, 0)]
 
         sent = self.host.getSentMessage(0)
-        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', self._buildPlayers(nicks)))
-        self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])
+        self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID, 'groupchat', self._buildPlayers(nicks)))
+        self._roomGameCmd(sent, ['radiocolStarted', ROOM_JID.full(), REFEREE_FULL.full(), nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])
 
         self._joinRoom(room, nicks, 1)  # player joins
         self._joinRoom(room, nicks, 4)  # user not playing joins