test: improvements for the helpers classes:
- simplification for retrieving the sent messages - an expected bridge call which is already set can no more be overwritten with new arguments for the same method name. The new arguments are stored in a FIFO list instead, and each call of the method also registers the arguments for the next call.
This commit is contained in:
parent
30dfdf1025
commit
cf8f9330b4
1 changed files with 105 additions and 40 deletions
|
|
@ -70,7 +70,7 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.plugin_0045.joinRoom(user_index, muc_index)
|
||||
self.plugin._initGame(Const.MUC_STR[muc_index], Const.JID[user_index].user)
|
||||
|
||||
def expectedMessage(self, to, type_, tag, players=[]):
|
||||
def _expectedMessage(self, to, type_, tag, players=[]):
|
||||
content = "<%s" % tag
|
||||
if not players:
|
||||
content += "/>"
|
||||
|
|
@ -142,21 +142,21 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.init()
|
||||
self.initGame(0, 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.assertEqual(self.host.getSentMessage(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(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"]))
|
||||
self.assertEqual(self.host.getSentMessage(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(2, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"]))
|
||||
self.assertEqual(self.host.getSentMessage(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(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"]))
|
||||
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"]))
|
||||
|
||||
def test_invitePlayers(self):
|
||||
self.init()
|
||||
|
|
@ -328,50 +328,47 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
|
||||
nicks = [self.plugin_0045.getNick(0, 0)]
|
||||
|
||||
self.assertEqual(self.host.countSentMessages(), [1, 0, 0, 0, 0]) # init messages
|
||||
self.assertEqual(self.host.getSentMessage(0, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(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.countSentMessages(), [1, 0, 0, 0, 0]) # no new message has been sent
|
||||
self.assertEqual(self.host.getSentMessageRaw(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.countSentMessages(), [2, 0, 0, 0, 0])
|
||||
self.assertEqual(self.host.getSentMessage(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(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.countSentMessages(), [3, 0, 0, 0, 0])
|
||||
self.assertEqual(self.host.getSentMessage(2, 0), self.expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(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(3, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(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.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
|
||||
self.assertEqual(self.host.countSentMessages(), [1, 0, 0, 0, 0]) # init messages
|
||||
self.assertNotEqual(self.host.getSentMessageRaw(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(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
|
||||
|
||||
def test_userLeftTrigger(self):
|
||||
|
|
@ -459,7 +456,7 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
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, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(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])
|
||||
|
|
@ -473,7 +470,7 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
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, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
|
||||
|
||||
# game exists, current profile is not referee
|
||||
self.init(player_init={"xxx": "xyz"})
|
||||
|
|
@ -481,4 +478,4 @@ class RoomGameTest(helpers.SatTestCase):
|
|||
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.countSentMessages(), [0, 0, 0, 0, 0]) # no sync message has been sent by other_profile
|
||||
self.assertEqual(self.host.getSentMessageRaw(0), None) # no sync message has been sent by other_profile
|
||||
|
|
|
|||
Loading…
Reference in a new issue