annotate src/test/test_plugin_misc_room_game.py @ 1311:4895e1e092fb frontends_multi_profiles

frontends (tools): Pyjamas's JID implementation can be compared to an object of a different type: - always return False if the other object is not a JID - to not fake list membership's test, hash(jid) now differs from hash(unicode(jid))
author souliane <souliane@mailoo.org>
date Sat, 07 Feb 2015 14:47:23 +0100
parents b3f383ab39da
children 2308f8405ffb
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 _
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
24 from sat.core.log import getLogger
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from constants import Const
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
26 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
27 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
28 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
29 from wokkel.muc import User
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
30
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
31 from logging import WARNING
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
32
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
33 # 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
34 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
35 TAG = 'dummy'
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
36 PLUGIN_INFO = {
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
37 "name": "Dummy plugin",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
38 "import_name": "DUMMY",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
39 "type": "MISC",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
40 "protocols": [],
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
41 "dependencies": [],
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
42 "main": "Dummy",
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
43 "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
44 "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
45 }
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
46
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
47 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
48 PROFILE = Const.PROFILE[0]
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
49 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
50
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 class RoomGameTest(helpers.SatTestCase):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
53
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
54 def setUp(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
55 self.host = helpers.FakeSAT()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
56
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
57 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
58 self.host.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
59 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
60 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
61 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
62 self.plugin_0249 = self.host.plugins['XEP-0249'] = helpers_plugins.FakeXEP_0249(self.host)
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
63 logger = getLogger()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
64 level = logger.getEffectiveLevel()
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
65 logger.setLevel(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
66 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
67 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
68 logger.setLevel(level)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
69
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
70 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
71 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
72 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
73
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
74 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
75 content = "<%s" % tag
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
76 if not players:
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 else:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
79 content += ">"
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
80 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
81 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
82 content += "</%s>" % tag
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
83 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
84
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
85 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
86 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
87 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
88 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
89 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
90
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
91 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
92 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
93 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
94 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
95 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
96 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
97
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
106 def test_initGame(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
107 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
108 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
109 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
110 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
111
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
112 def test_checkJoinAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
113 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
114 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
115 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
116 # 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
117 self.initGame(0, 1)
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.ALL
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
119 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
120 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
121 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
122 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
123 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
124 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
125 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
126 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
127 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
128
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
129 def test_updatePlayers(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
130 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
131 self.initGame(0, 0)
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, [], 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'], [])
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, ["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
136 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
137 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
138 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
139 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
140 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
141
828
8f335c03eebb plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents: 811
diff changeset
142 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
143 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
162 def test_invitePlayers(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
163 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
164 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
165 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
166 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
167 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
168 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
169 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
170 # 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
171 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
172
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
173 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
174 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
175 # 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
176 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
177
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
178 def test_checkInviteAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
179
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
180 def check(value, index):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
181 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
182 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
183
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
184 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
185
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
186 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
187 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
188 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
189
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
190 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
191 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
192 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
193 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
194 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
195 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
196 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
197 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
198 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
199 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
200 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
201 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
202 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
203 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
204 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
205 check(False, 2)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
206
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
207 def test_isReferee(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
208 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
209 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
210 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
211 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
212
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
213 def test_isPlayer(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
214 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
215 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
216 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
217 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
218 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
219 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
220 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
221
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
222 def test_checkWaitAuth(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
223
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
224 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
225 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
226 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
227
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
228 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
229 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
230 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
231 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
232 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
233 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
234 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
235 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
236 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
237 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
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, 1)
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, [], other_players)
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, 4)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
242 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
243 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
244 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
245 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
246
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
247 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
248 # 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
249 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
250 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
251 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
252
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
253 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
254 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
255 other_players = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
265 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
266 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
267 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
268 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
269 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
270
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
271 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
272 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
273 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
274 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
275 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
276
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
277 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
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
287 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
288 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
289 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
290 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
291 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
292
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._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
294 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
295 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
296 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
297 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
298
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
299 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
300 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
301 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
302 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
303 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
304 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
305 # 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
306 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
307 # 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
308 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
309 # 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
310 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
311 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
312
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
313 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
314 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
315 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
316 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
317 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
318
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
319 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
320 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
321 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
322 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
323 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
324 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
325
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
326 def test_userJoinedTrigger(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
327 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
328 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
329 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
330 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
331
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
332 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
333 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
334
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
335 # wrong profile
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
336 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
337 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
338 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
339 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
340 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
341
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
342 # 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
343 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
344 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
345 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
346 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
347 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
348
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
349 # 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
350 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
351 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
352 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
353 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
354
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
355 # 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
356 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
357 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
358 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
359 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
360 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
361 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
362
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
363 # wait for none
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
364 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
365 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
366 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
367 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
368 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
369 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
370 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
371 nicks.append(user_nick)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
372 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
373 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
374
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
375 def test_userLeftTrigger(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
376 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
377 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
378 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
379 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
380 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
381 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
382
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
383 # one user joins
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
384 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
385 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
386 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
387
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
388 # the user leaves
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
389 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
390 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
391 # 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
392 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
393 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
394 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
395 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
396 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
397 nicks.pop()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
398 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
399
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
400 # all the users join
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
401 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
402 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
403 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
404 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
405 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
406 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
407 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
408 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
409 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
410 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
411 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
412
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
413 # one user leaves
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
414 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
415 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
416 nicks.pop()
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
417 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
418
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
419 # another leaves
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
420 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
421 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
422 nicks.pop()
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
423 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
424
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
425 # they can join again
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
426 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
427 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
428 nicks.append(user_nick)
857
3c270d691e56 test: fix the tests for plugin room game
souliane <souliane@mailoo.org>
parents: 829
diff changeset
429 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
430 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
431 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
432 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
433 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
434
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
435 def test__checkCreateGameAndInit(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
436 self.init()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
437 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
438
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
439 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
440 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
441 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
442 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
443 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
444
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
445 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
446
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
447 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
448 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
449
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
450 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
451 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
452 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
453
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
454 def test_createGame(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
455
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
456 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
457 nicks = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
458 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
459 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
460
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
461 # game not exists
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
462 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
463 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
464 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
465 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
466 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
467 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
468 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
469 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
470 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
471 # 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
472 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
473
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
474 # 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
475 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
476 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
477 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
478 self.plugin.createGame(ROOM_JID_S, nicks, PROFILE)
829
187d2443c82d test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents: 828
diff changeset
479 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
480
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
481 # 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
482 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
483 self.initGame(0, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
484 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
485 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
486 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
487 self.assertEqual(self.host.getSentMessageRaw(0), None) # no sync message has been sent by other_profile