Mercurial > libervia-backend
annotate src/test/test_plugin_misc_room_game.py @ 801:02ee9ef95277
plugin XEP-0045, primitivus: added MUC configuration
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 04 Feb 2014 18:06:12 +0100 |
parents | 6625558371db |
children | 1fe00f0c9a91 |
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 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 # Copyright (C) 2013 Adrien Cossa (souliane@mailoo.org) |
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 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 def expectedMessage(self, to, type_, tag, players=[]): |
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'], []) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 self.plugin._updatePlayers(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
|
133 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
|
134 self.plugin._updatePlayers(ROOM_JID_S, ["user1"], Const.PROFILE[0]) |
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"]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
136 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], Const.PROFILE[0]) |
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"]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
138 self.plugin._updatePlayers(ROOM_JID_S, ["user2", "user3"], Const.PROFILE[0]) # should not be stored twice |
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 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
141 def test_signalPlayers(self): |
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) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
144 self.plugin._signalPlayers(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
145 self.assertEqual(self.host.getSentMessage(0, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", [])) |
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") |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
147 self.plugin._signalPlayers(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 self.assertEqual(self.host.getSentMessage(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", ["test1"])) |
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") |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
151 self.plugin._signalPlayers(ROOM_JID_S, [Const.MUC[0]], Const.PROFILE[0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
152 self.assertEqual(self.host.getSentMessage(2, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", ["test1", "test2"])) |
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) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 self.plugin._signalPlayers(ROOM_JID_S, [user1, user2], Const.PROFILE[0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 self.assertEqualXML(self.host.getSentMessage(3, 0), self.expectedMessage(user1.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
159 self.assertEqualXML(self.host.getSentMessage(4, 0), self.expectedMessage(user2.full(), "normal", "started", ["test1", "test2", "test3", "test4"])) |
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 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
331 self.assertEqual(self.host.countSentMessages(), [1, 0, 0, 0, 0]) # init messages |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
332 self.assertEqual(self.host.getSentMessage(0, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
333 self.assertTrue(len(self.plugin.invitations[ROOM_JID_S]) == 1) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
334 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
335 # wrong profile |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
336 user_nick = self.plugin_0045.joinRoom(0, 1) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
337 room = self.plugin_0045.getRoom(0, 1) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
338 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
339 self.assertEqual(self.host.countSentMessages(), [1, 0, 0, 0, 0]) # no new message has been sent |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
340 self.assertFalse(self.plugin._gameExists(ROOM_JID_S, True)) # game not started |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
341 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
342 # referee profile, user is allowed, wait for one more |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
343 room = self.plugin_0045.getRoom(0, 0) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
344 self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
345 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
346 self.assertEqual(self.host.countSentMessages(), [2, 0, 0, 0, 0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
347 self.assertEqual(self.host.getSentMessage(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "players", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
348 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
|
349 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
350 # 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
|
351 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
|
352 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
|
353 self.assertEqual(self.host.countSentMessages(), [3, 0, 0, 0, 0]) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
354 self.assertEqual(self.host.getSentMessage(2, 0), self.expectedMessage(ROOM_JID_S + '/' + user_nick, "normal", "players", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
355 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
|
356 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
357 # 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
|
358 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
|
359 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
|
360 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
361 self.assertEqual(self.host.getSentMessage(3, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
362 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
|
363 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
|
364 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
365 # wait for none |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
366 self.init() |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
367 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
|
368 self.assertEqual(self.host.countSentMessages(), [1, 0, 0, 0, 0]) # init messages |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
369 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
|
370 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
|
371 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
|
372 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
|
373 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
374 self.assertEqual(self.host.getSentMessage(1, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
375 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
|
376 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
377 def test_userLeftTrigger(self): |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
385 # one user joins |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
386 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
|
387 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
|
388 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
389 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
390 # the user leaves |
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, 1) |
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]), 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
|
394 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
|
395 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
|
396 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
|
397 nicks.pop() |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
398 self.assertEqual(self.plugin.games[ROOM_JID_S]['players'], nicks) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
399 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
400 # all the users join |
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[1]), 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, 3) |
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[3]), 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 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
|
407 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
|
408 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
409 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
|
410 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
|
411 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
412 # one user leaves |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
413 self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
414 nicks.pop() |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
415 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
|
416 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
417 # another leaves |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
418 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
|
419 nicks.pop() |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
420 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
|
421 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
422 # they can join again |
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, 3, 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[3]), 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 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
|
427 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
|
428 nicks.append(user_nick) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
429 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
|
430 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
|
431 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
432 def test__checkCreateGameAndInit(self): |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
433 self.init() |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
434 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
|
435 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 |
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)) # print internal error |
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_0045.joinRoom(0, 1) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
445 self.assertEqual((False, False), self.plugin._checkCreateGameAndInit(ROOM_JID_S, OTHER_PROFILE)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
446 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
447 self.plugin.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
|
448 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
|
449 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
|
450 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
451 def test_createGame(self): |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
452 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
453 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
|
454 nicks = [] |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
455 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
|
456 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
|
457 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
458 # game not exists |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
459 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
|
460 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
|
461 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
|
462 self.assertEqual(self.host.getSentMessage(0, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
463 for nick in nicks: |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
464 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
|
465 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
|
466 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
|
467 for nick in nicks: |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
468 # 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
|
469 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
|
470 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
471 # 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
|
472 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
|
473 self.initGame(0, 0) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
474 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
|
475 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
|
476 self.assertEqual(self.host.getSentMessage(0, 0), self.expectedMessage(ROOM_JID_S, "groupchat", "started", nicks)) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
477 |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
478 # 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
|
479 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
|
480 self.initGame(0, 0) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
481 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
|
482 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
|
483 self.plugin.createGame(ROOM_JID_S, nicks, OTHER_PROFILE) |
6625558371db
test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
484 self.assertEqual(self.host.countSentMessages(), [0, 0, 0, 0, 0]) # no sync message has been sent by other_profile |