diff --git a/src/test/helpers.py b/src/test/helpers.py
index 9bdc843c..5e2ad2b9 100644
--- a/src/test/helpers.py
+++ b/src/test/helpers.py
@@ -339,6 +339,7 @@ class FakeRosterProtocol(SatRosterProtocol):
def __init__(self, host, parent):
SatRosterProtocol.__init__(self, host)
self.parent = parent
+ self._jids = {}
self.addItem(parent.jid)
def addItem(self, jid, *args, **kwargs):
@@ -351,7 +352,8 @@ class FakeRosterProtocol(SatRosterProtocol):
if roster_item.name:
attrs['name'] = roster_item.name
self.host.bridge.expectCall("newContact", jid.full(), attrs, roster_item.groups, self.parent.profile)
- self.onRosterSet(roster_item)
+ self._jids[jid] = roster_item
+ self._registerItem(roster_item)
class FakeXmlStream(object):
diff --git a/src/test/helpers_plugins.py b/src/test/helpers_plugins.py
index af265f19..28a85056 100644
--- a/src/test/helpers_plugins.py
+++ b/src/test/helpers_plugins.py
@@ -40,13 +40,15 @@ class FakeMUCClient(object):
self.host = plugin_parent.host
self.joined_rooms = {}
- def join(self, roomJID, nick, profile):
+ def join(self, room_jid, nick, options=None, profile_key=C.PROF_KEY_NONE):
"""
- @param roomJID: the room JID
+ @param room_jid: the room JID
@param nick: nick to be used in the room
- @param profile: the profile of the user joining the room
+ @param options: joining options
+ @param profile_key: the profile key of the user joining the room
@return: the deferred joined wokkel.muc.Room instance
"""
+ profile = self.host.memory.getProfileName(profile_key)
roster = {}
# ask the other profiles to fill our roster
@@ -55,7 +57,7 @@ class FakeMUCClient(object):
if other_profile == profile:
continue
try:
- other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
+ other_room = self.plugin_parent.clients[other_profile].joined_rooms[room_jid]
roster.setdefault(other_room.nick, User(other_room.nick, C.PROFILE_DICT[other_profile]))
for other_nick in other_room.roster:
roster.setdefault(other_nick, other_room.roster[other_nick])
@@ -68,9 +70,9 @@ class FakeMUCClient(object):
break # same user with different resource --> same nickname
nick = nick + "_"
- room = Room(roomJID, nick)
+ room = Room(room_jid, nick)
room.roster = roster
- self.joined_rooms[roomJID.userhost()] = room
+ self.joined_rooms[room_jid] = room
# fill the other rosters with the new entry
for i in xrange(0, len(C.PROFILE)):
@@ -78,31 +80,32 @@ class FakeMUCClient(object):
if other_profile == profile:
continue
try:
- other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
+ other_room = self.plugin_parent.clients[other_profile].joined_rooms[room_jid]
other_room.roster.setdefault(room.nick, User(room.nick, C.PROFILE_DICT[profile]))
except (AttributeError, KeyError):
pass
return defer.succeed(room)
- def leave(self, roomJID, profile):
+ def leave(self, roomJID, profile_key=C.PROF_KEY_NONE):
"""
@param roomJID: the room JID
- @param profile: the profile of the user joining the room
+ @param profile_key: the profile key of the user joining the room
@return: a dummy deferred
"""
- room = self.joined_rooms[roomJID.userhost()]
+ profile = self.host.memory.getProfileName(profile_key)
+ room = self.joined_rooms[roomJID]
# remove ourself from the other rosters
for i in xrange(0, len(C.PROFILE)):
other_profile = C.PROFILE[i]
if other_profile == profile:
continue
try:
- other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
+ other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID]
del other_room.roster[room.nick]
except (AttributeError, KeyError):
pass
- del self.joined_rooms[roomJID.userhost()]
+ del self.joined_rooms[roomJID]
return defer.Deferred()
@@ -123,10 +126,9 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
@return: the deferred joined wokkel.muc.Room instance or None
"""
profile = self.host.memory.getProfileName(profile_key)
- room_jid_s = room_jid.userhost()
- if room_jid_s in self.clients[profile].joined_rooms:
+ if room_jid in self.clients[profile].joined_rooms:
return defer.succeed(None)
- room = self.clients[profile].join(room_jid, nick, profile)
+ room = self.clients[profile].join(room_jid, nick, profile_key=profile)
return room
def joinRoom(self, muc_index, user_index):
@@ -145,8 +147,7 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
@return: a dummy deferred
"""
profile = self.host.memory.getProfileName(profile_key)
- room_jid_s = room_jid.userhost()
- if room_jid_s not in self.clients[profile].joined_rooms:
+ if room_jid not in self.clients[profile].joined_rooms:
raise plugin_xep_0045.UnknownRoom("This room has not been joined")
return self.clients[profile].leave(room_jid, profile)
@@ -163,22 +164,22 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
"""Called by tests
@return: a wokkel.muc.Room instance"""
profile = C.PROFILE[user_index]
- muc_s = C.MUC_STR[muc_index]
+ muc_jid = C.MUC[muc_index]
try:
- return self.clients[profile].joined_rooms[muc_s]
+ return self.clients[profile].joined_rooms[muc_jid]
except (AttributeError, KeyError):
return None
def getNick(self, muc_index, user_index):
try:
- return self.getRoomNick(C.MUC_STR[muc_index], C.PROFILE[user_index])
+ return self.getRoomNick(C.MUC[muc_index], C.PROFILE[user_index])
except (KeyError, AttributeError):
return ''
def getNickOfUser(self, muc_index, user_index, profile_index, secure=True):
try:
- room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC_STR[muc_index]]
- return self.getRoomNickOfUser(room, C.JID_STR[user_index])
+ room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC[muc_index]]
+ return self.getRoomNickOfUser(room, C.JID[user_index])
except (KeyError, AttributeError):
return None
diff --git a/src/test/test_core_xmpp.py b/src/test/test_core_xmpp.py
index f0db2c22..18612677 100644
--- a/src/test/test_core_xmpp.py
+++ b/src/test/test_core_xmpp.py
@@ -64,7 +64,7 @@ class SatRosterProtocolTest(unittest.TestCase):
self.roster = xmpp.SatRosterProtocol(self.host)
self.roster.parent = helpers.FakeClient(self.host)
- def test_onRosterSet(self):
+ def test__registerItem(self):
roster_item = RosterItem(Const.JID[0])
roster_item.name = u"Test Man"
roster_item.subscriptionTo = True
@@ -72,7 +72,7 @@ class SatRosterProtocolTest(unittest.TestCase):
roster_item.ask = False
roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"])
self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), Const.PROFILE[0])
- self.roster.onRosterSet(roster_item)
+ self.roster._registerItem(roster_item)
class SatPresenceProtocolTest(unittest.TestCase):
diff --git a/src/test/test_plugin_misc_radiocol.py b/src/test/test_plugin_misc_radiocol.py
index b54fa24d..219e4e90 100644
--- a/src/test/test_plugin_misc_radiocol.py
+++ b/src/test/test_plugin_misc_radiocol.py
@@ -42,12 +42,12 @@ import copy
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
content += ""
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 @@ class RadiocolTest(helpers.SatTestCase):
if not element.hasAttribute('xmlns'):
element['xmlns'] = ''
content = "".join([element.toXml() for element in new_content])
- return "<%s xmlns='%s'>%s%s>" % (to_s, type_, plugin.RADIOC_TAG, plugin.NC_RADIOCOL, content, plugin.RADIOC_TAG)
+ return "<%s xmlns='%s'>%s%s>" % (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 @@ class RadiocolTest(helpers.SatTestCase):
@param profile_index: uploader's profile"""
sent = self.host.getSentMessage(0)
content = ""
- 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 = ""
- 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 = ""
- 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 @@ class RadiocolTest(helpers.SatTestCase):
content = "" % " ".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 @@ class RadiocolTest(helpers.SatTestCase):
sent = self.host.getSentMessage(0)
filename = self.playlist.pop(0)
content = "" % 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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
@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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
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 @@ class RadiocolTest(helpers.SatTestCase):
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
diff --git a/src/test/test_plugin_misc_room_game.py b/src/test/test_plugin_misc_room_game.py
index 149e8141..931a1eb0 100644
--- a/src/test/test_plugin_misc_room_game.py
+++ b/src/test/test_plugin_misc_room_game.py
@@ -44,7 +44,7 @@ PLUGIN_INFO = {
"description": _("""Dummy plugin to test room game""")
}
-ROOM_JID_S = Const.MUC_STR[0]
+ROOM_JID = JID(Const.MUC_STR[0])
PROFILE = Const.PROFILE[0]
OTHER_PROFILE = Const.PROFILE[1]
@@ -60,16 +60,12 @@ class RoomGameTest(helpers.SatTestCase):
self.plugin._init_(self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init)
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)
def initGame(self, muc_index, user_index):
self.plugin_0045.joinRoom(user_index, muc_index)
- self.plugin._initGame(Const.MUC_STR[muc_index], Const.JID[user_index].user)
+ self.plugin._initGame(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user)
def _expectedMessage(self, to, type_, tag, players=[]):
content = "<%s" % tag
@@ -80,38 +76,38 @@ class RoomGameTest(helpers.SatTestCase):
for i in xrange(0, len(players)):
content += "%s" % (i, players[i])
content += "%s>" % tag
- return "<%s xmlns='%s'>%s" % (to, type_, TAG, NAMESERVICE, content)
+ return "<%s xmlns='%s'>%s" % (to.full(), type_, TAG, NAMESERVICE, content)
def test_createOrInvite_solo(self):
self.reinit()
self.plugin_0045.joinRoom(0, 0)
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0])
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
def test_createOrInvite_multi_not_waiting(self):
self.reinit()
self.plugin_0045.joinRoom(0, 0)
- other_players = [Const.JID_STR[1], Const.JID_STR[2]]
+ other_players = [Const.JID[1], Const.JID[2]]
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0])
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
def test_createOrInvite_multi_waiting(self):
self.reinit(player_init={'score': 0})
self.plugin_0045.joinRoom(0, 0)
- other_players = [Const.JID_STR[1], Const.JID_STR[2]]
+ other_players = [Const.JID[1], Const.JID[2]]
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0])
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False))
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, False))
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
def test_initGame(self):
self.reinit()
self.initGame(0, 0)
- self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user))
- self.assertEqual([], self.plugin.games[ROOM_JID_S]['players'])
+ self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user))
+ self.assertEqual([], self.plugin.games[ROOM_JID]['players'])
def test_checkJoinAuth(self):
self.reinit()
- check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user))
+ check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user))
check(False)
# to test the "invited" mode, the referee must be different than the user to test
self.initGame(0, 1)
@@ -119,59 +115,59 @@ class RoomGameTest(helpers.SatTestCase):
check(True)
self.plugin.join_mode = self.plugin.INVITED
check(False)
- self.plugin.invitations[ROOM_JID_S] = [(None, [Const.JID[0].userhost()])]
+ self.plugin.invitations[ROOM_JID] = [(None, [Const.JID[0].userhostJID()])]
check(True)
self.plugin.join_mode = self.plugin.NONE
check(False)
- self.plugin.games[ROOM_JID_S]['players'].append(Const.JID[0].user)
+ self.plugin.games[ROOM_JID]['players'].append(Const.JID[0].user)
check(True)
def test_updatePlayers(self):
self.reinit()
self.initGame(0, 0)
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
- self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0])
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
- self.plugin._updatePlayers(ROOM_JID_S, ["user1"], True, Const.PROFILE[0])
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1"])
- self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0])
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"])
- self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"])
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], [])
+ self.plugin._updatePlayers(ROOM_JID, [], True, Const.PROFILE[0])
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], [])
+ self.plugin._updatePlayers(ROOM_JID, ["user1"], True, Const.PROFILE[0])
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1"])
+ self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0])
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1", "user2", "user3"])
+ self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], ["user1", "user2", "user3"])
def test_synchronizeRoom(self):
self.reinit()
self.initGame(0, 0)
- self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", []))
- self.plugin.games[ROOM_JID_S]['players'].append("test1")
- self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"]))
- self.plugin.games[ROOM_JID_S]['started'] = True
- self.plugin.games[ROOM_JID_S]['players'].append("test2")
- self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"]))
- self.plugin.games[ROOM_JID_S]['players'].append("test3")
- self.plugin.games[ROOM_JID_S]['players'].append("test4")
- user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user)
- user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user)
- self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0])
- self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
- self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
+ self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", []))
+ self.plugin.games[ROOM_JID]['players'].append("test1")
+ self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", ["test1"]))
+ self.plugin.games[ROOM_JID]['started'] = True
+ self.plugin.games[ROOM_JID]['players'].append("test2")
+ self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", ["test1", "test2"]))
+ self.plugin.games[ROOM_JID]['players'].append("test3")
+ self.plugin.games[ROOM_JID]['players'].append("test4")
+ user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
+ user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user)
+ self.plugin._synchronizeRoom(ROOM_JID, [user1, user2], Const.PROFILE[0])
+ self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1, "normal", "started", ["test1", "test2", "test3", "test4"]))
+ self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2, "normal", "started", ["test1", "test2", "test3", "test4"]))
def test_invitePlayers(self):
self.reinit()
self.initGame(0, 0)
self.plugin_0045.joinRoom(0, 1)
- self.assertEqual(self.plugin.invitations[ROOM_JID_S], [])
+ self.assertEqual(self.plugin.invitations[ROOM_JID], [])
room = self.plugin_0045.getRoom(0, 0)
- nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[2]], Const.JID[0].user, Const.PROFILE[0])
- self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[2].userhost()])
+ nicks = self.plugin._invitePlayers(room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0])
+ self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()])
# the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user])
- nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[3]], Const.JID[0].user, Const.PROFILE[0])
- self.assertEqual(self.plugin.invitations[ROOM_JID_S][1][1], [Const.JID[1].userhost(), Const.JID[3].userhost()])
+ nicks = self.plugin._invitePlayers(room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0])
+ self.assertEqual(self.plugin.invitations[ROOM_JID][1][1], [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()])
# this time Const.JID[1] and Const.JID[3] have the same user but the host differs
self.assertEqual(nicks, [Const.JID[1].user])
@@ -179,7 +175,7 @@ class RoomGameTest(helpers.SatTestCase):
def check(value, index):
nick = self.plugin_0045.getNick(0, index)
- getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID_S, nick))
+ getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID, nick))
self.reinit()
@@ -198,7 +194,7 @@ class RoomGameTest(helpers.SatTestCase):
check(True, 0)
check(False, 1)
user_nick = self.plugin_0045.joinRoom(0, 1)
- self.plugin.games[ROOM_JID_S]['players'].append(user_nick)
+ self.plugin.games[ROOM_JID]['players'].append(user_nick)
self.plugin.invite_mode = self.plugin.FROM_PLAYERS
check(True, 0)
check(True, 1)
@@ -207,17 +203,17 @@ class RoomGameTest(helpers.SatTestCase):
def test_isReferee(self):
self.reinit()
self.initGame(0, 0)
- self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 0)))
- self.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1)))
+ self.assertTrue(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 0)))
+ self.assertFalse(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 1)))
def test_isPlayer(self):
self.reinit()
self.initGame(0, 0)
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0)))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 0)))
user_nick = self.plugin_0045.joinRoom(0, 1)
- self.plugin.games[ROOM_JID_S]['players'].append(user_nick)
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
- self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 2)))
+ self.plugin.games[ROOM_JID]['players'].append(user_nick)
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
+ self.assertFalse(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 2)))
def test_checkWaitAuth(self):
@@ -253,132 +249,132 @@ class RoomGameTest(helpers.SatTestCase):
def test_prepareRoom_trivial(self):
self.reinit()
other_players = []
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
- self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user))
- self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[0].user))
- self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID_S, []))
- self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user))
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[0].user))
- self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
+ self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user))
+ self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[0].user))
+ self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID, []))
+ self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[0].user))
+ self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE))
def test_prepareRoom_invite(self):
self.reinit()
- other_players = [Const.JID_STR[1], Const.JID_STR[2]]
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ other_players = [Const.JID[1], Const.JID[2]]
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
room = self.plugin_0045.getRoom(0, 0)
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
- self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user))
- self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user))
- self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
+ self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user))
+ self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user))
+ self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user))
self.assertEqual((True, [], other_players), self.plugin._checkWaitAuth(room, other_players))
player2_nick = self.plugin_0045.joinRoom(0, 1)
self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE)
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick))
- self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, player2_nick))
- self.assertFalse(self.plugin.isReferee(ROOM_JID_S, player2_nick))
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick))
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0)))
- self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, Const.JID_STR[3]))
- self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1]))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick))
+ self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, player2_nick))
+ self.assertFalse(self.plugin.isReferee(ROOM_JID, player2_nick))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)))
+ self.assertFalse(self.plugin.isPlayer(ROOM_JID, "xxx"))
+ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[1]))
def test_prepareRoom_score1(self):
self.reinit(player_init={'score': 0})
- other_players = [Const.JID_STR[1], Const.JID_STR[2]]
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ other_players = [Const.JID[1], Const.JID[2]]
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
room = self.plugin_0045.getRoom(0, 0)
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
- self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user))
- self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user))
- self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user))
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
+ self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user))
+ self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user))
+ self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user))
self.assertEqual((False, [], other_players), self.plugin._checkWaitAuth(room, other_players))
user_nick = self.plugin_0045.joinRoom(0, 1)
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
- self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, user_nick))
- self.assertFalse(self.plugin.isReferee(ROOM_JID_S, user_nick))
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
+ self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, user_nick))
+ self.assertFalse(self.plugin.isReferee(ROOM_JID, user_nick))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick))
# the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0)))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)))
# the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user
- self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[3].user))
+ self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[3].user))
# but Const.JID[3] is actually not in the room
self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None)
- self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0]))
+ self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[0]))
def test_prepareRoom_score2(self):
self.reinit(player_init={'score': 0})
- other_players = [Const.JID_STR[1], Const.JID_STR[4]]
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ other_players = [Const.JID[1], Const.JID[4]]
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
room = self.plugin_0045.getRoom(0, 0)
user_nick = self.plugin_0045.joinRoom(0, 1)
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
- self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
+ self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE))
user_nick = self.plugin_0045.joinRoom(0, 4)
self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
- self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
+ self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE))
def test_userJoinedTrigger(self):
self.reinit(player_init={"xxx": "xyz"})
- other_players = [Const.JID_STR[1], Const.JID_STR[3]]
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ other_players = [Const.JID[1], Const.JID[3]]
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
nicks = [self.plugin_0045.getNick(0, 0)]
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
- self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1)
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", nicks))
+ self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1)
# wrong profile
user_nick = self.plugin_0045.joinRoom(0, 1)
room = self.plugin_0045.getRoom(0, 1)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
self.assertEqual(self.host.getSentMessage(0), None) # no new message has been sent
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
# referee profile, user is allowed, wait for one more
room = self.plugin_0045.getRoom(0, 0)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
nicks.append(user_nick)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "players", nicks))
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
# referee profile, user is not allowed
user_nick = self.plugin_0045.joinRoom(0, 4)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks))
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(JID(ROOM_JID.userhost() + '/' + user_nick), "normal", "players", nicks))
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started
# referee profile, user is allowed, everybody here
user_nick = self.plugin_0045.joinRoom(0, 3)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
nicks.append(user_nick)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) # game started
- self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) # game started
+ self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
# wait for none
self.reinit()
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
self.assertNotEqual(self.host.getSentMessage(0), None) # init messages
room = self.plugin_0045.getRoom(0, 0)
nicks = [self.plugin_0045.getNick(0, 0)]
user_nick = self.plugin_0045.joinRoom(0, 3)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
nicks.append(user_nick)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
def test_userLeftTrigger(self):
self.reinit(player_init={"xxx": "xyz"})
- other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]]
- self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
+ other_players = [Const.JID[1], Const.JID[3], Const.JID[4]]
+ self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE)
room = self.plugin_0045.getRoom(0, 0)
nicks = [self.plugin_0045.getNick(0, 0)]
- self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()])
+ self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[1].userhostJID(), Const.JID[3].userhostJID(), Const.JID[4].userhostJID()])
# one user joins
user_nick = self.plugin_0045.joinRoom(0, 1)
@@ -386,16 +382,16 @@ class RoomGameTest(helpers.SatTestCase):
nicks.append(user_nick)
# the user leaves
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
room = self.plugin_0045.getRoom(0, 1)
# to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # not the referee
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
room = self.plugin_0045.getRoom(0, 0)
user_nick = self.plugin_0045.leaveRoom(0, 1)
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee
nicks.pop()
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
# all the users join
user_nick = self.plugin_0045.joinRoom(0, 1)
@@ -407,20 +403,20 @@ class RoomGameTest(helpers.SatTestCase):
user_nick = self.plugin_0045.joinRoom(0, 4)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
nicks.append(user_nick)
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
- self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
+ self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
# one user leaves
user_nick = self.plugin_0045.leaveRoom(0, 4)
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
nicks.pop()
- self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost()])
+ self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()])
# another leaves
user_nick = self.plugin_0045.leaveRoom(0, 3)
self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
nicks.pop()
- self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost(), Const.JID[3].userhost()])
+ self.assertEqual(self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()])
# they can join again
user_nick = self.plugin_0045.joinRoom(0, 3)
@@ -429,27 +425,27 @@ class RoomGameTest(helpers.SatTestCase):
user_nick = self.plugin_0045.joinRoom(0, 4)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
nicks.append(user_nick)
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
- self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
+ self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
def test__checkCreateGameAndInit(self):
self.reinit()
- self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error
+ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE)) # print internal error
nick = self.plugin_0045.joinRoom(0, 0)
- self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False))
- self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
- self.assertTrue(self.plugin.isReferee(ROOM_JID_S, nick))
+ self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE))
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, False))
+ self.assertFalse(self.plugin._gameExists(ROOM_JID, True))
+ self.assertTrue(self.plugin.isReferee(ROOM_JID, nick))
- self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) # print internal error
+ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE)) # print internal error
self.plugin_0045.joinRoom(0, 1)
- self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE))
+ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE))
- self.plugin.createGame(ROOM_JID_S, [Const.JID_STR[1]], PROFILE)
- self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
- self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE))
+ self.plugin.createGame(ROOM_JID, [Const.JID[1]], PROFILE)
+ self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE))
+ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE))
def test_createGame(self):
@@ -459,29 +455,29 @@ class RoomGameTest(helpers.SatTestCase):
nicks.append(self.plugin_0045.joinRoom(0, i))
# game not exists
- self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
- self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
- self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
+ self.plugin.createGame(ROOM_JID, nicks, PROFILE)
+ self.assertTrue(self.plugin._gameExists(ROOM_JID, True))
+ self.assertEqual(self.plugin.games[ROOM_JID]['players'], nicks)
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks))
for nick in nicks:
- self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick])
- self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick])
- self.plugin.games[ROOM_JID_S]['players_data'][nick]["xxx"] = nick
+ self.assertEqual('init', self.plugin.games[ROOM_JID]['status'][nick])
+ self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID]['players_data'][nick])
+ self.plugin.games[ROOM_JID]['players_data'][nick]["xxx"] = nick
for nick in nicks:
# checks that a copy of self.player_init has been done and not a reference
- self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx'])
+ self.assertEqual(nick, self.plugin.games[ROOM_JID]['players_data'][nick]['xxx'])
# game exists, current profile is referee
self.reinit(player_init={"xxx": "xyz"})
self.initGame(0, 0)
- self.plugin.games[ROOM_JID_S]['started'] = True
- self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
- self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
+ self.plugin.games[ROOM_JID]['started'] = True
+ self.plugin.createGame(ROOM_JID, nicks, PROFILE)
+ self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID, "groupchat", "started", nicks))
# game exists, current profile is not referee
self.reinit(player_init={"xxx": "xyz"})
self.initGame(0, 0)
- self.plugin.games[ROOM_JID_S]['started'] = True
+ self.plugin.games[ROOM_JID]['started'] = True
self.plugin_0045.joinRoom(0, 1)
- self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE)
+ self.plugin.createGame(ROOM_JID, nicks, OTHER_PROFILE)
self.assertEqual(self.host.getSentMessage(0), None) # no sync message has been sent by other_profile
diff --git a/src/test/test_plugin_misc_text_syntaxes.py b/src/test/test_plugin_misc_text_syntaxes.py
index c34c4833..35e6ced6 100644
--- a/src/test/test_plugin_misc_text_syntaxes.py
+++ b/src/test/test_plugin_misc_text_syntaxes.py
@@ -61,7 +61,7 @@ class SanitisationTest(helpers.SatTestCase):
self.text_syntaxes = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
def test_xhtml_sanitise(self):
- expected = """
+ expected = u"""
a link
@@ -81,7 +81,7 @@ class SanitisationTest(helpers.SatTestCase):
return d
def test_styles_sanitise(self):
- expected = """
test retest
toto
"""
+ expected = u"""
test retest
toto
"""
d = self.text_syntaxes.clean_xhtml(self.EVIL_HTML2)
d.addCallback(self.assertEqualXML, expected)
@@ -100,11 +100,11 @@ class SanitisationTest(helpers.SatTestCase):
return d
def test_removeXHTMLMarkups(self):
- expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL!spam spam SPAM! """
+ expected = u""" a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL!spam spam SPAM! """
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1)
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())
- expected = """test retest toto"""
+ expected = u"""test retest toto"""
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML2)
self.assertEqual(re.sub(r"\s+", " ", result).rstrip(), expected.rstrip())