plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance

This commit is contained in:
souliane 2014-01-17 15:02:46 +01:00
commit 30dfdf1025

View file

@ -129,32 +129,32 @@ class RoomGameTest(helpers.SatTestCase):
self.init()
self.initGame(0, 0)
self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
self.plugin._updatePlayers(ROOM_JID_S, [], Const.PROFILE[0])
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"], Const.PROFILE[0])
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"], Const.PROFILE[0])
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"], Const.PROFILE[0]) # should not be stored twice
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"])
def test_signalPlayers(self):
def test_synchronizeRoom(self):
self.init()
self.initGame(0, 0)
self.plugin._signalPlayers(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, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", []))
self.plugin.games[ROOM_JID_S]['players'].append("test1")
self.plugin._signalPlayers(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(1, 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._signalPlayers(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(2, 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._signalPlayers(ROOM_JID_S, [user1, user2], Const.PROFILE[0])
self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0])
self.assertEqualXML(self.host.getSentMessage(3, 0), self.expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
self.assertEqualXML(self.host.getSentMessage(4, 0), self.expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))