Mercurial > libervia-backend
changeset 1271:2308f8405ffb
test: refactoring:
- rename internal init methods to reinit
- rename getSentMessage to getSentMessageXml
- rename getSentMessageRaw to getSentMessage
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 19 Dec 2014 11:36:00 +0100 |
parents | 037ec0795a85 |
children | 7fbc858cd1cd |
files | src/test/helpers.py src/test/test_memory.py src/test/test_plugin_misc_radiocol.py src/test/test_plugin_misc_room_game.py src/test/test_plugin_xep_0033.py src/test/test_plugin_xep_0085.py |
diffstat | 6 files changed, 119 insertions(+), 99 deletions(-) [+] |
line wrap: on
line diff
--- a/src/test/helpers.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/helpers.py Fri Dec 19 11:36:00 2014 +0100 @@ -64,12 +64,15 @@ self.bridge = FakeBridge() self.memory = FakeMemory(self) 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, 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.plugins = {} self.profiles = {} @@ -90,7 +93,7 @@ @param mess_data: message data dictionnary @param client: profile's client """ - self.sent_messages.append(mess_data["to"]) + client.xmlstream.send(mess_data['xml']) return mess_data def _storeMessage(self, mess_data, client): @@ -128,13 +131,18 @@ def isConnected(self, profile): return True - def getSentMessageRaw(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: the sent message for given profile, or None""" + def getSentMessages(self, profile_index): + """Return all the sent messages (in the order they have been sent) and + empty the list. Called by tests. FakeClient instances associated to each + profile must have been previously initialized with the method + FakeSAT.getClient. + + @param profile_index: index of the profile to consider (cf. C.PROFILE) + @return: the sent messages for given profile, or None""" 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: return None @@ -142,8 +150,20 @@ """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. + + @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""" - entry = self.getSentMessageRaw(profile_index) + entry = self.getSentMessage(profile_index) return entry.toXml() if entry else None def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None): @@ -258,9 +278,9 @@ self.host = host self.params = FakeParams(host, None) self.config = self.parseMainConf() - self.init() + self.reinit() - def init(self): + def reinit(self): """Tests that manipulate params, entities, features should re-initialise the memory first to not fake the result.""" self.params.load_default_params() @@ -350,6 +370,9 @@ self.roster = FakeRosterProtocol(host, self) self.xmlstream = FakeXmlStream() + def reinit(self): + self.xmlstream = FakeXmlStream() + def send(self, obj): return self.xmlstream.send(obj)
--- a/src/test/test_memory.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/test_memory.py Fri Dec 19 11:36:00 2014 +0100 @@ -136,7 +136,7 @@ return self.host.memory.getParams(security_limit, app, profile_key) def test_updateParams(self): - self.host.memory.init() + self.host.memory.reinit() # check if the update works self.host.memory.updateParams(self._getParamXML()) self.assertParamExists() @@ -145,7 +145,7 @@ self.host.memory.updateParams(self._getParamXML()) 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) self.host.memory.updateParams(self._getParamXML('1')) self.assertParamExists("1") @@ -156,7 +156,7 @@ previous = self.host.memory.params.dom.cloneNode(True) # save for later - self.host.memory.init() + self.host.memory.reinit() # check successive updates (with intersection) self.host.memory.updateParams(self._getParamXML('1')) self.assertParamExists("1") @@ -168,7 +168,7 @@ # 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.host.memory.init() + self.host.memory.reinit() # one update with two params in a new category self.host.memory.updateParams(self._getParamXML('12')) self.assertParamExists("1") @@ -177,21 +177,21 @@ def test_getParams(self): # tests with no security level on the parameter (most secure) params = self._getParamXML() - self.host.memory.init() + self.host.memory.reinit() self.host.memory.updateParams(params) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(0).addCallback(self.assertParamNotExists_async) self._getParams(1).addCallback(self.assertParamNotExists_async) # tests with security level 0 on the parameter (not secure) params = self._getParamXML(security_level=0) - self.host.memory.init() + self.host.memory.reinit() self.host.memory.updateParams(params) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(0).addCallback(self.assertParamExists_async) self._getParams(1).addCallback(self.assertParamExists_async) # tests with security level 1 on the parameter (more secure) params = self._getParamXML(security_level=1) - self.host.memory.init() + self.host.memory.reinit() self.host.memory.updateParams(params) self._getParams(Const.NO_SECURITY_LIMIT).addCallback(self.assertParamExists_async) self._getParams(0).addCallback(self.assertParamNotExists_async) @@ -213,66 +213,66 @@ # tests with no security level on the parameter (most secure) params = self._getParamXML() - self.host.memory.init() + self.host.memory.reinit() register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 0, Const.APP_NAME) self.assertParamNotExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 1, Const.APP_NAME) self.assertParamNotExists() # tests with security level 0 on the parameter (not secure) params = self._getParamXML(security_level=0) - self.host.memory.init() + self.host.memory.reinit() register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 0, Const.APP_NAME) self.assertParamExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 1, Const.APP_NAME) self.assertParamExists() # tests with security level 1 on the parameter (more secure) params = self._getParamXML(security_level=1) - self.host.memory.init() + self.host.memory.reinit() register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 0, Const.APP_NAME) self.assertParamNotExists() - self.host.memory.init() + self.host.memory.reinit() register(params, 1, Const.APP_NAME) self.assertParamExists() # tests with security level 1 and several parameters being registered params = self._getParamXML("12", security_level=1) - self.host.memory.init() + self.host.memory.reinit() register(params, Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() self.assertParamExists("2") - self.host.memory.init() + self.host.memory.reinit() register(params, 0, Const.APP_NAME) self.assertParamNotExists() self.assertParamNotExists("2") - self.host.memory.init() + self.host.memory.reinit() register(params, 1, Const.APP_NAME) self.assertParamExists() self.assertParamExists("2") # 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")) register(self._getParamXML("12"), Const.NO_SECURITY_LIMIT, Const.APP_NAME) self.assertParamExists() self.assertParamExists("2") - self.host.memory.init() + self.host.memory.reinit() def test_paramsRegisterApp_getParams(self): # test retrieving the parameter for a specific frontend - self.host.memory.init() + self.host.memory.reinit() params = self._getParamXML(security_level=1) self.host.memory.paramsRegisterApp(params, 1, Const.APP_NAME) self._getParams(1, '').addCallback(self.assertParamExists_async) @@ -280,7 +280,7 @@ self._getParams(1, 'another_dummy_frontend').addCallback(self.assertParamNotExists_async) # 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) self.host.memory.paramsRegisterApp(params, 5, Const.APP_NAME) self._getParams(5, '').addCallback(self.assertParamExists_async)
--- a/src/test/test_plugin_misc_radiocol.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/test_plugin_misc_radiocol.py Fri Dec 19 11:36:00 2014 +0100 @@ -55,8 +55,8 @@ def setUp(self): self.host = helpers.FakeSAT() - def init(self): - self.host.init() + def reinit(self): + self.host.reinit() 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.testing = True @@ -109,7 +109,7 @@ """Check if the message "song_rejected" has been sent by the referee and process the command with the profile of the uploader @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'/>" 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']) @@ -117,7 +117,7 @@ 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.getSentMessageRaw(0) + sent = self.host.getSentMessage(0) content = "<no_upload xmlns=''/>" self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) self._roomGameCmd(sent, ['radiocolNoUpload', ROOM_JID_S]) @@ -125,7 +125,7 @@ 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.getSentMessageRaw(0) + sent = self.host.getSentMessage(0) content = "<upload_ok xmlns=''/>" self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) self._roomGameCmd(sent, ['radiocolUploadOk', ROOM_JID_S]) @@ -136,7 +136,7 @@ @param attrs: information dict about the song @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) radiocol_elt = domish.generateElementsNamed(sent.elements(), 'radiocol').next() preload_elt = domish.generateElementsNamed(radiocol_elt.elements(), 'preload').next() @@ -150,7 +150,7 @@ def _playNextSongCb(self): """Check if the message "play" has been sent by the referee 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) content = "<play xmlns='' filename='%s' />" % filename self.assertEqualXML(sent.toXml(), self._expectedMessage(ROOM_JID_S, 'groupchat', content)) @@ -181,7 +181,7 @@ self.assertEqual(game_data['to_delete'][attrs['filename']], filepath) 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)) reject_song = len(game_data['queue']) >= plugin.QUEUE_LIMIT @@ -240,7 +240,7 @@ """ for nick in sync_data: 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) for elt in sync_data[nick]: if elt.name == 'preload': @@ -273,7 +273,7 @@ # Check that the message "players" has been sent by the referee expected = self._expectedMessage(to_jid, type_, self._buildPlayers(nicks)) - sent = self.host.getSentMessageRaw(0) + sent = self.host.getSentMessage(0) self.assertEqualXML(sent.toXml(), expected) # Process the command with the profiles of each room users @@ -332,14 +332,14 @@ d.addCallbacks(eb, eb) def test_init(self): - self.init() + self.reinit() self.assertEqual(self.plugin.invite_mode, self.plugin.FROM_PLAYERS) self.assertEqual(self.plugin.wait_mode, self.plugin.FOR_NONE) self.assertEqual(self.plugin.join_mode, self.plugin.INVITED) self.assertEqual(self.plugin.ready_mode, self.plugin.FORCE) def test_game(self): - self.init() + self.reinit() # create game self.plugin.prepareRoom(OTHER_PLAYERS, ROOM_JID_S, PROFILE) @@ -347,7 +347,7 @@ room = self.plugin_0045.getRoom(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._roomGameCmd(sent, ['radiocolStarted', ROOM_JID_S, REFEREE_FULL, nicks, [plugin.QUEUE_TO_START, plugin.QUEUE_LIMIT]])
--- a/src/test/test_plugin_misc_room_game.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/test_plugin_misc_room_game.py Fri Dec 19 11:36:00 2014 +0100 @@ -54,8 +54,8 @@ def setUp(self): self.host = helpers.FakeSAT() - def init(self, game_init={}, player_init={}): - self.host.init() + def reinit(self, game_init={}, player_init={}): + self.host.reinit() self.plugin = plugin.RoomGame(self.host) 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) @@ -83,20 +83,20 @@ return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content) def test_createOrInvite_solo(self): - self.init() + 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)) def test_createOrInvite_multi_not_waiting(self): - self.init() + self.reinit() self.plugin_0045.joinRoom(0, 0) 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.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) def test_createOrInvite_multi_waiting(self): - self.init(player_init={'score': 0}) + self.reinit(player_init={'score': 0}) self.plugin_0045.joinRoom(0, 0) other_players = [Const.JID_STR[1], Const.JID_STR[2]] self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0]) @@ -104,13 +104,13 @@ self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) def test_initGame(self): - self.init() + 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']) 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(False) # to test the "invited" mode, the referee must be different than the user to test @@ -127,7 +127,7 @@ check(True) def test_updatePlayers(self): - self.init() + 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]) @@ -140,27 +140,27 @@ self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"]) def test_synchronizeRoom(self): - self.init() + self.reinit() self.initGame(0, 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._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]['players'].append("test2") 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("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.getSentMessage(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(user1.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): - self.init() + self.reinit() self.initGame(0, 0) self.plugin_0045.joinRoom(0, 1) self.assertEqual(self.plugin.invitations[ROOM_JID_S], []) @@ -181,7 +181,7 @@ nick = self.plugin_0045.getNick(0, index) 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]: self.plugin.invite_mode = mode @@ -205,13 +205,13 @@ check(False, 2) def test_isReferee(self): - self.init() + 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))) def test_isPlayer(self): - self.init() + self.reinit() self.initGame(0, 0) self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0))) user_nick = self.plugin_0045.joinRoom(0, 1) @@ -225,7 +225,7 @@ room = self.plugin_0045.getRoom(0, 0) self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players)) - self.init() + self.reinit() self.initGame(0, 0) other_players = [Const.JID[1], Const.JID[3]] self.plugin.wait_mode = self.plugin.FOR_NONE @@ -251,7 +251,7 @@ self.plugin_0045.getNickOfUser(0, 2, 0)], []) def test_prepareRoom_trivial(self): - self.init() + self.reinit() other_players = [] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) @@ -263,7 +263,7 @@ self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) def test_prepareRoom_invite(self): - self.init() + self.reinit() other_players = [Const.JID_STR[1], Const.JID_STR[2]] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) room = self.plugin_0045.getRoom(0, 0) @@ -285,7 +285,7 @@ self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1])) 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]] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) room = self.plugin_0045.getRoom(0, 0) @@ -311,7 +311,7 @@ self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0])) 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]] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) room = self.plugin_0045.getRoom(0, 0) @@ -324,56 +324,56 @@ self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) 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]] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) 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) # 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.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 # 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.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 # 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.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 # 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.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(len(self.plugin.invitations[ROOM_JID_S]) == 0) # wait for none - self.init() + self.reinit() 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) 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.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)) 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]] self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE) room = self.plugin_0045.getRoom(0, 0) @@ -433,7 +433,7 @@ self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0) def test__checkCreateGameAndInit(self): - self.init() + self.reinit() self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error nick = self.plugin_0045.joinRoom(0, 0) @@ -453,7 +453,7 @@ def test_createGame(self): - self.init(player_init={"xxx": "xyz"}) + self.reinit(player_init={"xxx": "xyz"}) nicks = [] for i in [0, 1, 3, 4]: nicks.append(self.plugin_0045.joinRoom(0, i)) @@ -462,7 +462,7 @@ 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.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: 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]) @@ -472,16 +472,16 @@ self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx']) # game exists, current profile is referee - self.init(player_init={"xxx": "xyz"}) + 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.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 - self.init(player_init={"xxx": "xyz"}) + self.reinit(player_init={"xxx": "xyz"}) self.initGame(0, 0) self.plugin.games[ROOM_JID_S]['started'] = True self.plugin_0045.joinRoom(0, 1) 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
--- a/src/test/test_plugin_xep_0033.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/test_plugin_xep_0033.py Fri Dec 19 11:36:00 2014 +0100 @@ -46,7 +46,7 @@ self.plugin = plugin.XEP_0033(self.host) def test_messageReceived(self): - self.host.memory.init() + self.host.memory.reinit() xml = u""" <message type="chat" from="%s" to="%s" id="test_1"> <body>test</body> @@ -148,21 +148,19 @@ post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception)) # feature is not supported, abort the message - self.host.memory.init() data = deepcopy(mess_data) trigger(data, CancelError) + self.host.memory.reinit() # feature is supported by the main target server - self.host.init() - self.host.memory.init() + self.host.reinit() self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) data = deepcopy(mess_data) trigger(data, CancelError) checkSentAndStored() # feature is supported by all target servers - self.host.init() - self.host.memory.init() + self.host.reinit() 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): self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) @@ -171,8 +169,7 @@ checkSentAndStored() # check that a wrong recipient entity is fixed by the backend - self.host.init() - self.host.memory.init() + self.host.reinit() 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): self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
--- a/src/test/test_plugin_xep_0085.py Mon Dec 15 15:29:08 2014 +0100 +++ b/src/test/test_plugin_xep_0085.py Fri Dec 19 11:36:00 2014 +0100 @@ -37,7 +37,7 @@ self.plugin = plugin.XEP_0085(self.host) 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]) for state in plugin.CHAT_STATES: xml = u""" @@ -54,7 +54,7 @@ self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0]) 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]) for state in plugin.CHAT_STATES: mess_data = {"to": Const.JID[0],