annotate src/test/test_plugin_misc_room_game.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents 3c270d691e56
children b3f383ab39da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
3
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 795
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 795
diff changeset
6 # Copyright (C) 2013, 2014 Adrien Cossa (souliane@mailoo.org)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
7
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
12
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
17
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
20
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Tests for the plugin room game (base class for MUC games) """
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
22
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from sat.core.i18n import _
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from constants import Const
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from sat.test import helpers, helpers_plugins
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from sat.plugins import plugin_misc_room_game as plugin
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.jid import JID
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from wokkel.muc import User
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
29 import logging
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
30
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
31 # Data used for test initialization
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
32 NAMESERVICE = 'http://www.goffi.org/protocol/dummy'
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
33 TAG = 'dummy'
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
34 PLUGIN_INFO = {
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
35 "name": "Dummy plugin",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
36 "import_name": "DUMMY",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
37 "type": "MISC",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
38 "protocols": [],
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
39 "dependencies": [],
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
40 "main": "Dummy",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
41 "handler": "no", # handler MUST be "no" (dynamic inheritance)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
42 "description": _("""Dummy plugin to test room game""")
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
43 }
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
44
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
45 ROOM_JID_S = Const.MUC_STR[0]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
46 PROFILE = Const.PROFILE[0]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
47 OTHER_PROFILE = Const.PROFILE[1]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
48
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
49
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
50 class RoomGameTest(helpers.SatTestCase):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
51
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
52 def setUp(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
53 self.host = helpers.FakeSAT()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
54
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
55 def init(self, game_init={}, player_init={}):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
56 self.host.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
57 self.plugin = plugin.RoomGame(self.host)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
58 self.plugin._init_(self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
59 self.plugin_0045 = self.host.plugins['XEP-0045'] = helpers_plugins.FakeXEP_0045(self.host)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
60 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
61 logger = logging.getLogger()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
62 level = logger.getEffectiveLevel()
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 857
diff changeset
63 logger.setLevel(logging.WARNING) # remove log.info pollution
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
64 for profile in Const.PROFILE:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
65 self.host.getClient(profile) # init self.host.profiles[profile]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
66 logger.setLevel(level)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
67
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
68 def initGame(self, muc_index, user_index):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
69 self.plugin_0045.joinRoom(user_index, muc_index)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
70 self.plugin._initGame(Const.MUC_STR[muc_index], Const.JID[user_index].user)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
71
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
72 def _expectedMessage(self, to, type_, tag, players=[]):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
73 content = "<%s" % tag
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
74 if not players:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
75 content += "/>"
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
76 else:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
77 content += ">"
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
78 for i in xrange(0, len(players)):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
79 content += "<player index='%s'>%s</player>" % (i, players[i])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
80 content += "</%s>" % tag
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
81 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (to, type_, TAG, NAMESERVICE, content)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
82
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
83 def test_createOrInvite_solo(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
84 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
85 self.plugin_0045.joinRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
86 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
87 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
88
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
89 def test_createOrInvite_multi_not_waiting(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
90 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
91 self.plugin_0045.joinRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
92 other_players = [Const.JID_STR[1], Const.JID_STR[2]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
93 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
94 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
95
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
96 def test_createOrInvite_multi_waiting(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
97 self.init(player_init={'score': 0})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
98 self.plugin_0045.joinRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
99 other_players = [Const.JID_STR[1], Const.JID_STR[2]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
100 self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
101 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
102 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
103
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
104 def test_initGame(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
105 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
106 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
107 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
108 self.assertEqual([], self.plugin.games[ROOM_JID_S]['players'])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
109
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
110 def test_checkJoinAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
111 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
112 check = lambda value: getattr(self, "assert%s" % value)(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
113 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
114 # to test the "invited" mode, the referee must be different than the user to test
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
115 self.initGame(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
116 self.plugin.join_mode = self.plugin.ALL
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
117 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
118 self.plugin.join_mode = self.plugin.INVITED
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
119 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
120 self.plugin.invitations[ROOM_JID_S] = [(None, [Const.JID[0].userhost()])]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
121 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
122 self.plugin.join_mode = self.plugin.NONE
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
123 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
124 self.plugin.games[ROOM_JID_S]['players'].append(Const.JID[0].user)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
125 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
126
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
127 def test_updatePlayers(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
128 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
129 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
130 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
131 self.plugin._updatePlayers(ROOM_JID_S, [], True, Const.PROFILE[0])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
132 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], [])
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
133 self.plugin._updatePlayers(ROOM_JID_S, ["user1"], True, Const.PROFILE[0])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
134 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1"])
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
135 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
136 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"])
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
137 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], True, Const.PROFILE[0]) # should not be stored twice
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
138 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], ["user1", "user2", "user3"])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
139
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
140 def test_synchronizeRoom(self):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
141 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
142 self.initGame(0, 0)
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
143 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
144 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", []))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
145 self.plugin.games[ROOM_JID_S]['players'].append("test1")
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
146 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
147 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"]))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
148 self.plugin.games[ROOM_JID_S]['started'] = True
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
149 self.plugin.games[ROOM_JID_S]['players'].append("test2")
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
150 self.plugin._synchronizeRoom(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0])
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
151 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"]))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
152 self.plugin.games[ROOM_JID_S]['players'].append("test3")
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
153 self.plugin.games[ROOM_JID_S]['players'].append("test4")
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
154 user1 = JID(ROOM_JID_S + "/" + Const.JID[0].user)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
155 user2 = JID(ROOM_JID_S + "/" + Const.JID[1].user)
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
156 self.plugin._synchronizeRoom(ROOM_JID_S, [user1, user2], Const.PROFILE[0])
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
157 self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
158 self.assertEqualXML(self.host.getSentMessage(0), self._expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"]))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
159
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
160 def test_invitePlayers(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
161 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
162 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
163 self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
164 self.assertEqual(self.plugin.invitations[ROOM_JID_S], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
165 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
166 nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[2]], Const.JID[0].user, Const.PROFILE[0])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
167 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[2].userhost()])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
168 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
169 self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
170
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
171 nicks = self.plugin._invitePlayers(room, [Const.JID_STR[1], Const.JID_STR[3]], Const.JID[0].user, Const.PROFILE[0])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
172 self.assertEqual(self.plugin.invitations[ROOM_JID_S][1][1], [Const.JID[1].userhost(), Const.JID[3].userhost()])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
173 # this time Const.JID[1] and Const.JID[3] have the same user but the host differs
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
174 self.assertEqual(nicks, [Const.JID[1].user])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
175
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
176 def test_checkInviteAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
177
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
178 def check(value, index):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
179 nick = self.plugin_0045.getNick(0, index)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
180 getattr(self, "assert%s" % value)(self.plugin._checkInviteAuth(ROOM_JID_S, nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
181
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
182 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
183
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
184 for mode in [self.plugin.FROM_ALL, self.plugin.FROM_NONE, self.plugin.FROM_REFEREE, self.plugin.FROM_PLAYERS]:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
185 self.plugin.invite_mode = mode
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
186 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
187
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
188 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
189 self.plugin.invite_mode = self.plugin.FROM_ALL
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
190 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
191 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
192 self.plugin.invite_mode = self.plugin.FROM_NONE
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
193 check(True, 0) # game initialized but not started yet, referee can invite
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
194 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
195 self.plugin.invite_mode = self.plugin.FROM_REFEREE
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
196 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
197 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
198 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
199 self.plugin.games[ROOM_JID_S]['players'].append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
200 self.plugin.invite_mode = self.plugin.FROM_PLAYERS
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
201 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
202 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
203 check(False, 2)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
204
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
205 def test_isReferee(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
206 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
207 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
208 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 0)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
209 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, self.plugin_0045.getNick(0, 1)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
210
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
211 def test_isPlayer(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
212 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
213 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
214 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 0)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
215 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
216 self.plugin.games[ROOM_JID_S]['players'].append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
217 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
218 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNick(0, 2)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
219
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
220 def test_checkWaitAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
221
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
222 def check(value, other_players, confirmed, rest):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
223 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
224 self.assertEqual((value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
225
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
226 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
227 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
228 other_players = [Const.JID[1], Const.JID[3]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
229 self.plugin.wait_mode = self.plugin.FOR_NONE
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
230 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
231 check(True, [Const.JID[0]], [], [Const.JID[0]]) # getRoomNickOfUser checks for the other users only
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
232 check(True, other_players, [], other_players)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
233 self.plugin.wait_mode = self.plugin.FOR_ALL
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
234 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
235 check(False, [Const.JID[0]], [], [Const.JID[0]])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
236 check(False, other_players, [], other_players)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
237 self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
238 check(False, other_players, [], other_players)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
239 self.plugin_0045.joinRoom(0, 4)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
240 check(False, other_players, [self.plugin_0045.getNickOfUser(0, 1, 0)], [Const.JID[3]])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
241 self.plugin_0045.joinRoom(0, 3)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
242 check(True, other_players, [self.plugin_0045.getNickOfUser(0, 1, 0),
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
243 self.plugin_0045.getNickOfUser(0, 3, 0)], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
244
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
245 other_players = [Const.JID[1], Const.JID[3], Const.JID[2]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
246 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
247 check(True, other_players, [self.plugin_0045.getNickOfUser(0, 1, 0),
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
248 self.plugin_0045.getNickOfUser(0, 3, 0),
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
249 self.plugin_0045.getNickOfUser(0, 2, 0)], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
250
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
251 def test_prepareRoom_trivial(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
252 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
253 other_players = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
254 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
255 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
256 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[0], Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
257 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
258 self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID_S, []))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
259 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
260 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[0].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
261 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
262
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
263 def test_prepareRoom_invite(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
264 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
265 other_players = [Const.JID_STR[1], Const.JID_STR[2]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
266 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
267 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
268
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
269 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
270 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
271 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
272 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
273 self.assertEqual((True, [], other_players), self.plugin._checkWaitAuth(room, other_players))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
274
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
275 player2_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
276 self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
277 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
278 self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID_S, player2_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
279 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, player2_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
280 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, player2_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
281 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
282 self.assertFalse(self.plugin.isPlayer(ROOM_JID_S, Const.JID_STR[3]))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
283 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[1]))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
284
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
285 def test_prepareRoom_score1(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
286 self.init(player_init={'score': 0})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
287 other_players = [Const.JID_STR[1], Const.JID_STR[2]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
288 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
289 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
290
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
291 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
292 self.assertTrue(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[1], Const.JID[1].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
293 self.assertFalse(self.plugin._checkJoinAuth(ROOM_JID_S, Const.JID_STR[3], Const.JID[3].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
294 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, Const.JID[1].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
295 self.assertEqual((False, [], other_players), self.plugin._checkWaitAuth(room, other_players))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
296
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
297 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
298 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
299 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
300 self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID_S, user_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
301 self.assertFalse(self.plugin.isReferee(ROOM_JID_S, user_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
302 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, user_nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
303 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
304 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, self.plugin_0045.getNickOfUser(0, 2, 0)))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
305 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
306 self.assertTrue(self.plugin.isPlayer(ROOM_JID_S, Const.JID[3].user))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
307 # but Const.JID[3] is actually not in the room
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
308 self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
309 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, Const.PROFILE[0]))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
310
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
311 def test_prepareRoom_score2(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
312 self.init(player_init={'score': 0})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
313 other_players = [Const.JID_STR[1], Const.JID_STR[4]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
314 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
315 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
316
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
317 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
318 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
319 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
320 user_nick = self.plugin_0045.joinRoom(0, 4)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
321 self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
322 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
323
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
324 def test_userJoinedTrigger(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
325 self.init(player_init={"xxx": "xyz"})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
326 other_players = [Const.JID_STR[1], Const.JID_STR[3]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
327 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
328 nicks = [self.plugin_0045.getNick(0, 0)]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
329
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
330 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
331 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
332
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
333 # wrong profile
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
334 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
335 room = self.plugin_0045.getRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
336 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
337 self.assertEqual(self.host.getSentMessageRaw(0), None) # no new message has been sent
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
338 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
339
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
340 # referee profile, user is allowed, wait for one more
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
341 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
342 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
343 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
344 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "players", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
345 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
346
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
347 # referee profile, user is not allowed
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
348 user_nick = self.plugin_0045.joinRoom(0, 4)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
349 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
350 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
351 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
352
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
353 # referee profile, user is allowed, everybody here
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
354 user_nick = self.plugin_0045.joinRoom(0, 3)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
355 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
356 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
357 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
358 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True)) # game started
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
359 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
360
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
361 # wait for none
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
362 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
363 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
364 self.assertNotEqual(self.host.getSentMessageRaw(0), None) # init messages
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
365 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
366 nicks = [self.plugin_0045.getNick(0, 0)]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
367 user_nick = self.plugin_0045.joinRoom(0, 3)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
368 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
369 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
370 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
371 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
372
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
373 def test_userLeftTrigger(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
374 self.init(player_init={"xxx": "xyz"})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
375 other_players = [Const.JID_STR[1], Const.JID_STR[3], Const.JID_STR[4]]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
376 self.plugin.prepareRoom(other_players, ROOM_JID_S, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
377 room = self.plugin_0045.getRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
378 nicks = [self.plugin_0045.getNick(0, 0)]
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
379 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[1].userhost(), Const.JID[3].userhost(), Const.JID[4].userhost()])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
380
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
381 # one user joins
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
382 user_nick = self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
383 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
384 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
385
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
386 # the user leaves
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
387 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
388 room = self.plugin_0045.getRoom(0, 1)
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
389 # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
390 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), Const.PROFILE[1]) # not the referee
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
391 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
392 room = self.plugin_0045.getRoom(0, 0)
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
393 user_nick = self.plugin_0045.leaveRoom(0, 1)
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
394 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[1]), PROFILE) # referee
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
395 nicks.pop()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
396 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
397
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
398 # all the users join
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
399 user_nick = self.plugin_0045.joinRoom(0, 1)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
400 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
401 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
402 user_nick = self.plugin_0045.joinRoom(0, 3)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
403 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
404 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
405 user_nick = self.plugin_0045.joinRoom(0, 4)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
406 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
407 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
408 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
409 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
410
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
411 # one user leaves
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
412 user_nick = self.plugin_0045.leaveRoom(0, 4)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
413 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
414 nicks.pop()
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
415 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost()])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
416
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
417 # another leaves
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
418 user_nick = self.plugin_0045.leaveRoom(0, 3)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
419 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
420 nicks.pop()
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
421 self.assertEqual(self.plugin.invitations[ROOM_JID_S][0][1], [Const.JID[4].userhost(), Const.JID[3].userhost()])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
422
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
423 # they can join again
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
424 user_nick = self.plugin_0045.joinRoom(0, 3)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
425 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
426 nicks.append(user_nick)
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
427 user_nick = self.plugin_0045.joinRoom(0, 4)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
428 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
429 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
430 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
431 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
432
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
433 def test__checkCreateGameAndInit(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
434 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
435 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE)) # print internal error
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
436
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
437 nick = self.plugin_0045.joinRoom(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
438 self.assertEqual((True, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
439 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, False))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
440 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
441 self.assertTrue(self.plugin.isReferee(ROOM_JID_S, nick))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
442
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
443 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) # print internal error
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
444
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
445 self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
446 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
447
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
448 self.plugin.createGame(ROOM_JID_S, [Const.JID_STR[1]], PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
449 self.assertEqual((False, True), self.plugin._checkCreateGameAndInit(ROOM_JID_S, PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
450 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
451
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
452 def test_createGame(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
453
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
454 self.init(player_init={"xxx": "xyz"})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
455 nicks = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
456 for i in [0, 1, 3, 4]:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
457 nicks.append(self.plugin_0045.joinRoom(0, i))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
458
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
459 # game not exists
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
460 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
461 self.assertTrue(self.plugin._gameExists(ROOM_JID_S, True))
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
462 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
463 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
464 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
465 self.assertEqual('init', self.plugin.games[ROOM_JID_S]['status'][nick])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
466 self.assertEqual(self.plugin.player_init, self.plugin.games[ROOM_JID_S]['players_data'][nick])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
467 self.plugin.games[ROOM_JID_S]['players_data'][nick]["xxx"] = nick
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
468 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
469 # checks that a copy of self.player_init has been done and not a reference
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
470 self.assertEqual(nick, self.plugin.games[ROOM_JID_S]['players_data'][nick]['xxx'])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
471
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
472 # game exists, current profile is referee
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
473 self.init(player_init={"xxx": "xyz"})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
474 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
475 self.plugin.games[ROOM_JID_S]['started'] = True
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
476 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
477 self.assertEqual(self.host.getSentMessage(0), self._expectedMessage(ROOM_JID_S, "groupchat", "started", nicks))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
478
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
479 # game exists, current profile is not referee
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
480 self.init(player_init={"xxx": "xyz"})
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
481 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
482 self.plugin.games[ROOM_JID_S]['started'] = True
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
483 self.plugin_0045.joinRoom(0, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
484 self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
485 self.assertEqual(self.host.getSentMessageRaw(0), None) # no sync message has been sent by other_profile