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