test: refactoring:

- rename internal init methods to reinit
    - rename getSentMessage to getSentMessageXml
    - rename getSentMessageRaw to getSentMessage
This commit is contained in:
souliane 2014-12-19 11:36:00 +01:00
commit 852106becd
6 changed files with 115 additions and 95 deletions

View file

@ -64,12 +64,15 @@ class FakeSAT(object):
self.bridge = FakeBridge() self.bridge = FakeBridge()
self.memory = FakeMemory(self) self.memory = FakeMemory(self)
self.trigger = FakeTriggerManager() self.trigger = FakeTriggerManager()
self.init() self.profiles = {}
self.reinit()
def init(self): def reinit(self):
"""This can be called by tests that check for sent and stored messages, """This can be called by tests that check for sent and stored messages,
uses FakeClient or get/set some other data that need to be cleaned""" uses FakeClient or get/set some other data that need to be cleaned"""
self.sent_messages = [] for profile in self.profiles:
self.profiles[profile].reinit()
self.memory.reinit()
self.stored_messages = [] self.stored_messages = []
self.plugins = {} self.plugins = {}
self.profiles = {} self.profiles = {}
@ -90,7 +93,7 @@ class FakeSAT(object):
@param mess_data: message data dictionnary @param mess_data: message data dictionnary
@param client: profile's client @param client: profile's client
""" """
self.sent_messages.append(mess_data["to"]) client.xmlstream.send(mess_data['xml'])
return mess_data return mess_data
def _storeMessage(self, mess_data, client): def _storeMessage(self, mess_data, client):
@ -128,13 +131,18 @@ class FakeSAT(object):
def isConnected(self, profile): def isConnected(self, profile):
return True return True
def getSentMessageRaw(self, profile_index): def getSentMessages(self, profile_index):
"""Pop and return the sent message in first position (works like a FIFO). """Return all the sent messages (in the order they have been sent) and
Called by tests. FakeClient instances associated to each profile must have empty the list. Called by tests. FakeClient instances associated to each
been previously initialized with the method FakeSAT.getClient. profile must have been previously initialized with the method
@return: the sent message for given profile, or None""" FakeSAT.getClient.
@param profile_index: index of the profile to consider (cf. C.PROFILE)
@return: the sent messages for given profile, or None"""
try: try:
return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0) tmp = self.profiles[C.PROFILE[profile_index]].xmlstream.sent
self.profiles[C.PROFILE[profile_index]].xmlstream.sent = []
return tmp
except IndexError: except IndexError:
return None return None
@ -142,8 +150,20 @@ class FakeSAT(object):
"""Pop and return the sent message in first position (works like a FIFO). """Pop and return the sent message in first position (works like a FIFO).
Called by tests. FakeClient instances associated to each profile must have Called by tests. FakeClient instances associated to each profile must have
been previously initialized with the method FakeSAT.getClient. been previously initialized with the method FakeSAT.getClient.
@param profile_index: index of the profile to consider (cf. C.PROFILE)
@return: the sent message for given profile, or None"""
try:
return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0)
except IndexError:
return None
def getSentMessageXml(self, profile_index):
"""Pop and return the sent message in first position (works like a FIFO).
Called by tests. FakeClient instances associated to each profile must have
been previously initialized with the method FakeSAT.getClient.
@return: XML representation of the sent message for given profile, or None""" @return: XML representation of the sent message for given profile, or None"""
entry = self.getSentMessageRaw(profile_index) entry = self.getSentMessage(profile_index)
return entry.toXml() if entry else None return entry.toXml() if entry else None
def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None): def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None):
@ -258,9 +278,9 @@ class FakeMemory(Memory):
self.host = host self.host = host
self.params = FakeParams(host, None) self.params = FakeParams(host, None)
self.config = self.parseMainConf() self.config = self.parseMainConf()
self.init() self.reinit()
def init(self): def reinit(self):
"""Tests that manipulate params, entities, features should """Tests that manipulate params, entities, features should
re-initialise the memory first to not fake the result.""" re-initialise the memory first to not fake the result."""
self.params.load_default_params() self.params.load_default_params()
@ -350,6 +370,9 @@ class FakeClient(object):
self.roster = FakeRosterProtocol(host, self) self.roster = FakeRosterProtocol(host, self)
self.xmlstream = FakeXmlStream() self.xmlstream = FakeXmlStream()
def reinit(self):
self.xmlstream = FakeXmlStream()
def send(self, obj): def send(self, obj):
return self.xmlstream.send(obj) return self.xmlstream.send(obj)

View file

@ -136,7 +136,7 @@ class MemoryTest(unittest.TestCase):
return self.host.memory.getParams(security_limit, app, profile_key) return self.host.memory.getParams(security_limit, app, profile_key)
def test_updateParams(self): def test_updateParams(self):
self.host.memory.init() self.host.memory.reinit()
# check if the update works # check if the update works
self.host.memory.updateParams(self._getParamXML()) self.host.memory.updateParams(self._getParamXML())
self.assertParamExists() self.assertParamExists()
@ -145,7 +145,7 @@ class MemoryTest(unittest.TestCase):
self.host.memory.updateParams(self._getParamXML()) self.host.memory.updateParams(self._getParamXML())
self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
self.host.memory.init() self.host.memory.reinit()
# check successive updates (without intersection) # check successive updates (without intersection)
self.host.memory.updateParams(self._getParamXML('1')) self.host.memory.updateParams(self._getParamXML('1'))
self.assertParamExists("1") self.assertParamExists("1")
@ -156,7 +156,7 @@ class MemoryTest(unittest.TestCase):
previous = self.host.memory.params.dom.cloneNode(True) # save for later previous = self.host.memory.params.dom.cloneNode(True) # save for later
self.host.memory.init() self.host.memory.reinit()
# check successive updates (with intersection) # check successive updates (with intersection)
self.host.memory.updateParams(self._getParamXML('1')) self.host.memory.updateParams(self._getParamXML('1'))
self.assertParamExists("1") self.assertParamExists("1")
@ -168,7 +168,7 @@ class MemoryTest(unittest.TestCase):
# successive updates with or without intersection should have the same result # successive updates with or without intersection should have the same result
self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8")) self.assertEqual(previous.toxml().encode("utf-8"), self.host.memory.params.dom.toxml().encode("utf-8"))
self.host.memory.init() self.host.memory.reinit()
# one update with two params in a new category # one update with two params in a new category
self.host.memory.updateParams(self._getParamXML('12')) self.host.memory.updateParams(self._getParamXML('12'))
self.assertParamExists("1") self.assertParamExists("1")
@ -177,21 +177,21 @@ class MemoryTest(unittest.TestCase):
def test_getParams(self): def test_getParams(self):
# tests with no security level on the parameter (most secure) # tests with no security level on the parameter (most secure)
params = self._getParamXML() params = self._getParamXML()
self.host.memory.init() self.host.memory.reinit()
self.host.memory.updateParams(params) self.host.memory.updateParams(params)
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
self._getParams(0).addCallback(self.assertParamNotExists_async) self._getParams(0).addCallback(self.assertParamNotExists_async)
self._getParams(1).addCallback(self.assertParamNotExists_async) self._getParams(1).addCallback(self.assertParamNotExists_async)
# tests with security level 0 on the parameter (not secure) # tests with security level 0 on the parameter (not secure)
params = self._getParamXML(security_level=0) params = self._getParamXML(security_level=0)
self.host.memory.init() self.host.memory.reinit()
self.host.memory.updateParams(params) self.host.memory.updateParams(params)
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
self._getParams(0).addCallback(self.assertParamExists_async) self._getParams(0).addCallback(self.assertParamExists_async)
self._getParams(1).addCallback(self.assertParamExists_async) self._getParams(1).addCallback(self.assertParamExists_async)
# tests with security level 1 on the parameter (more secure) # tests with security level 1 on the parameter (more secure)
params = self._getParamXML(security_level=1) params = self._getParamXML(security_level=1)
self.host.memory.init() self.host.memory.reinit()
self.host.memory.updateParams(params) self.host.memory.updateParams(params)
self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async)
self._getParams(0).addCallback(self.assertParamNotExists_async) self._getParams(0).addCallback(self.assertParamNotExists_async)
@ -213,66 +213,66 @@ class MemoryTest(unittest.TestCase):
# tests with no security level on the parameter (most secure) # tests with no security level on the parameter (most secure)
params = self._getParamXML() params = self._getParamXML()
self.host.memory.init() self.host.memory.reinit()
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 0, Const.APP_NAME) register(params, 0, Const.APP_NAME)
self.assertParamNotExists() self.assertParamNotExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 1, Const.APP_NAME) register(params, 1, Const.APP_NAME)
self.assertParamNotExists() self.assertParamNotExists()
# tests with security level 0 on the parameter (not secure) # tests with security level 0 on the parameter (not secure)
params = self._getParamXML(security_level=0) params = self._getParamXML(security_level=0)
self.host.memory.init() self.host.memory.reinit()
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 0, Const.APP_NAME) register(params, 0, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 1, Const.APP_NAME) register(params, 1, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
# tests with security level 1 on the parameter (more secure) # tests with security level 1 on the parameter (more secure)
params = self._getParamXML(security_level=1) params = self._getParamXML(security_level=1)
self.host.memory.init() self.host.memory.reinit()
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 0, Const.APP_NAME) register(params, 0, Const.APP_NAME)
self.assertParamNotExists() self.assertParamNotExists()
self.host.memory.init() self.host.memory.reinit()
register(params, 1, Const.APP_NAME) register(params, 1, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
# tests with security level 1 and several parameters being registered # tests with security level 1 and several parameters being registered
params = self._getParamXML("12", security_level=1) params = self._getParamXML("12", security_level=1)
self.host.memory.init() self.host.memory.reinit()
register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.assertParamExists("2") self.assertParamExists("2")
self.host.memory.init() self.host.memory.reinit()
register(params, 0, Const.APP_NAME) register(params, 0, Const.APP_NAME)
self.assertParamNotExists() self.assertParamNotExists()
self.assertParamNotExists("2") self.assertParamNotExists("2")
self.host.memory.init() self.host.memory.reinit()
register(params, 1, Const.APP_NAME) register(params, 1, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.assertParamExists("2") self.assertParamExists("2")
# tests with several parameters being registered in an existing category # tests with several parameters being registered in an existing category
self.host.memory.init() self.host.memory.reinit()
self.host.memory.updateParams(self._getParamXML("3")) self.host.memory.updateParams(self._getParamXML("3"))
register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME) register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME)
self.assertParamExists() self.assertParamExists()
self.assertParamExists("2") self.assertParamExists("2")
self.host.memory.init() self.host.memory.reinit()
def test_paramsRegisterApp_getParams(self): def test_paramsRegisterApp_getParams(self):
# test retrieving the parameter for a specific frontend # test retrieving the parameter for a specific frontend
self.host.memory.init() self.host.memory.reinit()
params = self._getParamXML(security_level=1) params = self._getParamXML(security_level=1)
self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME)
self._getParams(1, '').addCallback(self.assertParamExists_async) self._getParams(1, '').addCallback(self.assertParamExists_async)
@ -280,7 +280,7 @@ class MemoryTest(unittest.TestCase):
self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async) self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async)
# the same with several parameters registered at the same time # the same with several parameters registered at the same time
self.host.memory.init() self.host.memory.reinit()
params = self._getParamXML('12', security_level=0) params = self._getParamXML('12', security_level=0)
self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME) self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME)
self._getParams(5, '').addCallback(self.assertParamExists_async) self._getParams(5, '').addCallback(self.assertParamExists_async)

View file

@ -55,8 +55,8 @@ class RadiocolTest(helpers.SatTestCase):
def setUp(self): def setUp(self):
self.host = helpers.FakeSAT() self.host = helpers.FakeSAT()
def init(self): def reinit(self):
self.host.init() self.host.reinit()
self.host.plugins['ROOM-GAME'] = plugin_room_game.RoomGame(self.host) self.host.plugins['ROOM-GAME'] = plugin_room_game.RoomGame(self.host)
self.plugin = plugin.Radiocol(self.host) # must be init after ROOM-GAME self.plugin = plugin.Radiocol(self.host) # must be init after ROOM-GAME
self.plugin.testing = True self.plugin.testing = True
@ -109,7 +109,7 @@ class RadiocolTest(helpers.SatTestCase):
"""Check if the message "song_rejected" has been sent by the referee """Check if the message "song_rejected" has been sent by the referee
and process the command with the profile of the uploader and process the command with the profile of the uploader
@param profile_index: uploader's profile""" @param profile_index: uploader's profile"""
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
content = "<song_rejected xmlns='' reason='Too many songs in queue'/>" 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.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._roomGameCmd(sent, ['radiocolSongRejected', ROOM_JID_S, 'Too many songs in queue'])
@ -117,7 +117,7 @@ class RadiocolTest(helpers.SatTestCase):
def _noUploadCb(self): def _noUploadCb(self):
"""Check if the message "no_upload" has been sent by the referee """Check if the message "no_upload" has been sent by the referee
and process the command with the profiles of each room users""" and process the command with the profiles of each room users"""
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
content = "<no_upload xmlns=''/>" content = "<no_upload xmlns=''/>"
self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S]) self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S])
@ -125,7 +125,7 @@ class RadiocolTest(helpers.SatTestCase):
def _uploadOkCb(self): def _uploadOkCb(self):
"""Check if the message "upload_ok" has been sent by the referee """Check if the message "upload_ok" has been sent by the referee
and process the command with the profiles of each room users""" and process the command with the profiles of each room users"""
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
content = "<upload_ok xmlns=''/>" content = "<upload_ok xmlns=''/>"
self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S]) self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S])
@ -136,7 +136,7 @@ class RadiocolTest(helpers.SatTestCase):
@param attrs: information dict about the song @param attrs: information dict about the song
@param profile_index: profile index of the uploader @param profile_index: profile index of the uploader
""" """
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
attrs['sender'] = self.plugin_0045.getNick(0, profile_index) attrs['sender'] = self.plugin_0045.getNick(0, profile_index)
radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next() radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next()
preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next() preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next()
@ -150,7 +150,7 @@ class RadiocolTest(helpers.SatTestCase):
def _playNextSongCb(self): def _playNextSongCb(self):
"""Check if the message "play" has been sent by the referee """Check if the message "play" has been sent by the referee
and process the command with the profiles of each room users""" and process the command with the profiles of each room users"""
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
filename = self.playlist.pop(0) filename = self.playlist.pop(0)
content = "<play xmlns='' filename='%s' />" % filename content = "<play xmlns='' filename='%s' />" % filename
self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content))
@ -181,7 +181,7 @@ class RadiocolTest(helpers.SatTestCase):
self.assertEqual(game_data['to_delete'][attrs['filename']], filepath) self.assertEqual(game_data['to_delete'][attrs['filename']], filepath)
content = "<song_added xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs]) content = "<song_added xmlns='' %s/>" % " ".join(["%s='%s'" % (attr, attrs[attr]) for attr in attrs])
sent = self.host.getSentMessageRaw(profile_index) sent = self.host.getSentMessage(profile_index)
self.assertEqualXML(sent.toXml(), self._expectedMessage(REFEREE_FULL, 'normal', content)) self.assertEqualXML(sent.toXml(), self._expectedMessage(REFEREE_FULL, 'normal', content))
reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT
@ -240,7 +240,7 @@ class RadiocolTest(helpers.SatTestCase):
""" """
for nick in sync_data: for nick in sync_data:
expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick]) expected = self._expectedMessage(ROOM_JID_S + '/' + nick, 'normal', sync_data[nick])
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
self.assertEqualXML(sent.toXml(), expected) self.assertEqualXML(sent.toXml(), expected)
for elt in sync_data[nick]: for elt in sync_data[nick]:
if elt.name == 'preload': if elt.name == 'preload':
@ -273,7 +273,7 @@ class RadiocolTest(helpers.SatTestCase):
# Check that the message "players" has been sent by the referee # Check that the message "players" has been sent by the referee
expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks))
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
self.assertEqualXML(sent.toXml(), expected) self.assertEqualXML(sent.toXml(), expected)
# Process the command with the profiles of each room users # Process the command with the profiles of each room users
@ -332,14 +332,14 @@ class RadiocolTest(helpers.SatTestCase):
d.addCallbacks(eb, eb) d.addCallbacks(eb, eb)
def test_init(self): def test_init(self):
self.init() self.reinit()
self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS) self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS)
self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE) self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE)
self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) self.assertEqual(self.plugin.join_mode, self.plugin.INVITED)
self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE)
def test_game(self): def test_game(self):
self.init() self.reinit()
# create game # create game
self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE)
@ -347,7 +347,7 @@ class RadiocolTest(helpers.SatTestCase):
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
nicks = [self.plugin_0045.getNick(0, 0)] nicks = [self.plugin_0045.getNick(0, 0)]
sent = self.host.getSentMessageRaw(0) sent = self.host.getSentMessage(0)
self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', self._buildPlayers(nicks))) 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._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])

View file

@ -54,8 +54,8 @@ class RoomGameTest(helpers.SatTestCase):
def setUp(self): def setUp(self):
self.host = helpers.FakeSAT() self.host = helpers.FakeSAT()
def init(self, game_init={}, player_init={}): def reinit(self, game_init={}, player_init={}):
self.host.init() self.host.reinit()
self.plugin = plugin.RoomGame(self.host) self.plugin = plugin.RoomGame(self.host)
self.plugin._init_(self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init) 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_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host)
@ -83,20 +83,20 @@ class RoomGameTest(helpers.SatTestCase):
return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content) return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content)
def test_createOrInvite_solo(self): def test_createOrInvite_solo(self):
self.init() self.reinit()
self.plugin_0045.joinRoom(0, 0) self.plugin_0045.joinRoom(0, 0)
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[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_S, True))
def test_createOrInvite_multi_not_waiting(self): def test_createOrInvite_multi_not_waiting(self):
self.init() self.reinit()
self.plugin_0045.joinRoom(0, 0) self.plugin_0045.joinRoom(0, 0)
other_players = [Const.JID_STR[1], Const.JID_STR[2]] other_players = [Const.JID_STR[1], Const.JID_STR[2]]
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) 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_S, True))
def test_createOrInvite_multi_waiting(self): def test_createOrInvite_multi_waiting(self):
self.init(player_init={'score': 0}) self.reinit(player_init={'score': 0})
self.plugin_0045.joinRoom(0, 0) self.plugin_0045.joinRoom(0, 0)
other_players = [Const.JID_STR[1], Const.JID_STR[2]] other_players = [Const.JID_STR[1], Const.JID_STR[2]]
self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0])
@ -104,13 +104,13 @@ class RoomGameTest(helpers.SatTestCase):
self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
def test_initGame(self): def test_initGame(self):
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user)) self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user))
self.assertEqual([], self.plugin.games[ROOM_JID_S]['players']) self.assertEqual([], self.plugin.games[ROOM_JID_S]['players'])
def test_checkJoinAuth(self): def test_checkJoinAuth(self):
self.init() 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_S, Const.JID_STR[0], Const.JID[0].user))
check(False) check(False)
# to test the "invited" mode, the referee must be different than the user to test # to test the "invited" mode, the referee must be different than the user to test
@ -127,7 +127,7 @@ class RoomGameTest(helpers.SatTestCase):
check(True) check(True)
def test_updatePlayers(self): def test_updatePlayers(self):
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], []) self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0]) self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0])
@ -140,27 +140,27 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"])
def test_synchronizeRoom(self): def test_synchronizeRoom(self):
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", [])) self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", []))
self.plugin.games[ROOM_JID_S]['players'].append("test1") self.plugin.games[ROOM_JID_S]['players'].append("test1")
self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"])) 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]['started'] = True
self.plugin.games[ROOM_JID_S]['players'].append("test2") self.plugin.games[ROOM_JID_S]['players'].append("test2")
self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"])) 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("test3")
self.plugin.games[ROOM_JID_S]['players'].append("test4") self.plugin.games[ROOM_JID_S]['players'].append("test4")
user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user) user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user)
user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user) user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user)
self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0]) self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0])
self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) self.assertEqualXML(self.host.getSentMessageXml(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
def test_invitePlayers(self): def test_invitePlayers(self):
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
self.plugin_0045.joinRoom(0, 1) self.plugin_0045.joinRoom(0, 1)
self.assertEqual(self.plugin.invitations[ROOM_JID_S], []) self.assertEqual(self.plugin.invitations[ROOM_JID_S], [])
@ -181,7 +181,7 @@ class RoomGameTest(helpers.SatTestCase):
nick = self.plugin_0045.getNick(0, 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_S, nick))
self.init() self.reinit()
for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]: for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]:
self.plugin.invite_mode = mode self.plugin.invite_mode = mode
@ -205,13 +205,13 @@ class RoomGameTest(helpers.SatTestCase):
check(False, 2) check(False, 2)
def test_isReferee(self): def test_isReferee(self):
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(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.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1)))
def test_isPlayer(self): def test_isPlayer(self):
self.init() self.reinit()
self.initGame(0, 0) 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_S, self.plugin_0045.getNick(0, 0)))
user_nick = self.plugin_0045.joinRoom(0, 1) user_nick = self.plugin_0045.joinRoom(0, 1)
@ -225,7 +225,7 @@ class RoomGameTest(helpers.SatTestCase):
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players)) self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players))
self.init() self.reinit()
self.initGame(0, 0) self.initGame(0, 0)
other_players = [Const.JID[1], Const.JID[3]] other_players = [Const.JID[1], Const.JID[3]]
self.plugin.wait_mode = self.plugin.FOR_NONE self.plugin.wait_mode = self.plugin.FOR_NONE
@ -251,7 +251,7 @@ class RoomGameTest(helpers.SatTestCase):
self.plugin_0045.getNickOfUser(0, 2, 0)], []) self.plugin_0045.getNickOfUser(0, 2, 0)], [])
def test_prepareRoom_trivial(self): def test_prepareRoom_trivial(self):
self.init() self.reinit()
other_players = [] other_players = []
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
@ -263,7 +263,7 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
def test_prepareRoom_invite(self): def test_prepareRoom_invite(self):
self.init() self.reinit()
other_players = [Const.JID_STR[1], Const.JID_STR[2]] other_players = [Const.JID_STR[1], Const.JID_STR[2]]
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
@ -285,7 +285,7 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1])) self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1]))
def test_prepareRoom_score1(self): def test_prepareRoom_score1(self):
self.init(player_init={'score': 0}) self.reinit(player_init={'score': 0})
other_players = [Const.JID_STR[1], Const.JID_STR[2]] other_players = [Const.JID_STR[1], Const.JID_STR[2]]
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
@ -311,7 +311,7 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0])) self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0]))
def test_prepareRoom_score2(self): def test_prepareRoom_score2(self):
self.init(player_init={'score': 0}) self.reinit(player_init={'score': 0})
other_players = [Const.JID_STR[1], Const.JID_STR[4]] other_players = [Const.JID_STR[1], Const.JID_STR[4]]
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
@ -324,56 +324,56 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
def test_userJoinedTrigger(self): def test_userJoinedTrigger(self):
self.init(player_init={"xxx": "xyz"}) self.reinit(player_init={"xxx": "xyz"})
other_players = [Const.JID_STR[1], Const.JID_STR[3]] other_players = [Const.JID_STR[1], Const.JID_STR[3]]
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
nicks = [self.plugin_0045.getNick(0, 0)] nicks = [self.plugin_0045.getNick(0, 0)]
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) 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.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1)
# wrong profile # wrong profile
user_nick = self.plugin_0045.joinRoom(0, 1) user_nick = self.plugin_0045.joinRoom(0, 1)
room = self.plugin_0045.getRoom(0, 1) room = self.plugin_0045.getRoom(0, 1)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
self.assertEqual(self.host.getSentMessageRaw(0), None) # no new message has been sent 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_S, True)) # game not started
# referee profile, user is allowed, wait for one more # referee profile, user is allowed, wait for one more
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
nicks.append(user_nick) nicks.append(user_nick)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) 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.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
# referee profile, user is not allowed # referee profile, user is not allowed
user_nick = self.plugin_0045.joinRoom(0, 4) user_nick = self.plugin_0045.joinRoom(0, 4)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks)) 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.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
# referee profile, user is allowed, everybody here # referee profile, user is allowed, everybody here
user_nick = self.plugin_0045.joinRoom(0, 3) user_nick = self.plugin_0045.joinRoom(0, 3)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
nicks.append(user_nick) nicks.append(user_nick)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) 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(self.plugin._gameExists(ROOM_JID_S, True)) # game started
self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
# wait for none # wait for none
self.init() self.reinit()
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
self.assertNotEqual(self.host.getSentMessageRaw(0), None) # init messages self.assertNotEqual(self.host.getSentMessage(0), None) # init messages
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
nicks = [self.plugin_0045.getNick(0, 0)] nicks = [self.plugin_0045.getNick(0, 0)]
user_nick = self.plugin_0045.joinRoom(0, 3) user_nick = self.plugin_0045.joinRoom(0, 3)
self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
nicks.append(user_nick) nicks.append(user_nick)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
def test_userLeftTrigger(self): def test_userLeftTrigger(self):
self.init(player_init={"xxx": "xyz"}) self.reinit(player_init={"xxx": "xyz"})
other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]] other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]]
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
room = self.plugin_0045.getRoom(0, 0) room = self.plugin_0045.getRoom(0, 0)
@ -433,7 +433,7 @@ class RoomGameTest(helpers.SatTestCase):
self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
def test__checkCreateGameAndInit(self): def test__checkCreateGameAndInit(self):
self.init() 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_S, PROFILE)) # print internal error
nick = self.plugin_0045.joinRoom(0, 0) nick = self.plugin_0045.joinRoom(0, 0)
@ -453,7 +453,7 @@ class RoomGameTest(helpers.SatTestCase):
def test_createGame(self): def test_createGame(self):
self.init(player_init={"xxx": "xyz"}) self.reinit(player_init={"xxx": "xyz"})
nicks = [] nicks = []
for i in [0, 1, 3, 4]: for i in [0, 1, 3, 4]:
nicks.append(self.plugin_0045.joinRoom(0, i)) nicks.append(self.plugin_0045.joinRoom(0, i))
@ -462,7 +462,7 @@ class RoomGameTest(helpers.SatTestCase):
self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
for nick in nicks: for nick in nicks:
self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick]) 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.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick])
@ -472,16 +472,16 @@ class RoomGameTest(helpers.SatTestCase):
self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx']) self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx'])
# game exists, current profile is referee # game exists, current profile is referee
self.init(player_init={"xxx": "xyz"}) self.reinit(player_init={"xxx": "xyz"})
self.initGame(0, 0) self.initGame(0, 0)
self.plugin.games[ROOM_JID_S]['started'] = True self.plugin.games[ROOM_JID_S]['started'] = True
self.plugin.createGame(ROOM_JID_S, nicks, PROFILE) self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) self.assertEqual(self.host.getSentMessageXml(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
# game exists, current profile is not referee # game exists, current profile is not referee
self.init(player_init={"xxx": "xyz"}) self.reinit(player_init={"xxx": "xyz"})
self.initGame(0, 0) self.initGame(0, 0)
self.plugin.games[ROOM_JID_S]['started'] = True self.plugin.games[ROOM_JID_S]['started'] = True
self.plugin_0045.joinRoom(0, 1) self.plugin_0045.joinRoom(0, 1)
self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE) self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE)
self.assertEqual(self.host.getSentMessageRaw(0), None) # no sync message has been sent by other_profile self.assertEqual(self.host.getSentMessage(0), None) # no sync message has been sent by other_profile

View file

@ -46,7 +46,7 @@ class XEP_0033Test(helpers.SatTestCase):
self.plugin = plugin.XEP_0033(self.host) self.plugin = plugin.XEP_0033(self.host)
def test_messageReceived(self): def test_messageReceived(self):
self.host.memory.init() self.host.memory.reinit()
xml = u""" xml = u"""
<message type="chat" from="%s" to="%s" id="test_1"> <message type="chat" from="%s" to="%s" id="test_1">
<body>test</body> <body>test</body>
@ -148,21 +148,19 @@ class XEP_0033Test(helpers.SatTestCase):
post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception)) post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception))
# feature is not supported, abort the message # feature is not supported, abort the message
self.host.memory.init()
data = deepcopy(mess_data) data = deepcopy(mess_data)
trigger(data, CancelError) trigger(data, CancelError)
self.host.memory.reinit()
# feature is supported by the main target server # feature is supported by the main target server
self.host.init() self.host.reinit()
self.host.memory.init()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
data = deepcopy(mess_data) data = deepcopy(mess_data)
trigger(data, CancelError) trigger(data, CancelError)
checkSentAndStored() checkSentAndStored()
# feature is supported by all target servers # feature is supported by all target servers
self.host.init() self.host.reinit()
self.host.memory.init()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
@ -171,8 +169,7 @@ class XEP_0033Test(helpers.SatTestCase):
checkSentAndStored() checkSentAndStored()
# check that a wrong recipient entity is fixed by the backend # check that a wrong recipient entity is fixed by the backend
self.host.init() self.host.reinit()
self.host.memory.init()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)

View file

@ -37,7 +37,7 @@ class XEP_0085Test(helpers.SatTestCase):
self.plugin = plugin.XEP_0085(self.host) self.plugin = plugin.XEP_0085(self.host)
def test_messageReceived(self): def test_messageReceived(self):
self.host.memory.init() self.host.memory.reinit()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0]) self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0])
for state in plugin.CHAT_STATES: for state in plugin.CHAT_STATES:
xml = u""" xml = u"""
@ -54,7 +54,7 @@ class XEP_0085Test(helpers.SatTestCase):
self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0]) self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0])
def test_sendMessageTrigger(self): def test_sendMessageTrigger(self):
self.host.memory.init() self.host.memory.reinit()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0]) self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0])
for state in plugin.CHAT_STATES: for state in plugin.CHAT_STATES:
mess_data = {"to": Const.JID[0], mess_data = {"to": Const.JID[0],