annotate libervia/backend/test/test_plugin_misc_room_game.py @ 4163:3b3cd9453d9b

plugin XEP-0308: implement Last Message Correction
author Goffi <goffi@goffi.org>
date Tue, 28 Nov 2023 17:38:31 +0100
parents 4b842c1fb686
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
795
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
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1412
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
7
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
12
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
17
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
20
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Tests for the plugin room game (base class for MUC games) """
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
22
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
23 from libervia.backend.core.i18n import _
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
24 from .constants import Const
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.test import helpers, helpers_plugins
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.plugins import plugin_misc_room_game as plugin
795
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
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
29
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
30 from logging import WARNING
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
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
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 NAMESERVICE = "http://www.goffi.org/protocol/dummy"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 TAG = "dummy"
795
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)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 "description": _("""Dummy plugin to test room game"""),
795
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
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
46 ROOM_JID = JID(Const.MUC_STR[0])
795
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 def setUp(self):
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
53 self.host = helpers.FakeSAT()
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
54
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
55 def reinit(self, game_init={}, player_init={}):
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
56 self.host.reinit()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
57 self.plugin = plugin.RoomGame(self.host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 self.plugin._init_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self.host, PLUGIN_INFO, (NAMESERVICE, TAG), game_init, player_init
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 self.plugin_0045 = self.host.plugins["XEP-0045"] = helpers_plugins.FakeXEP_0045(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 self.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 self.plugin_0249 = self.host.plugins["XEP-0249"] = helpers_plugins.FakeXEP_0249(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 self.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
67 for profile in Const.PROFILE:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
68 self.host.get_client(profile) # init self.host.profiles[profile]
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
69
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
70 def init_game(self, muc_index, user_index):
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
71 self.plugin_0045.join_room(user_index, muc_index)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
72 self.plugin._init_game(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
73
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
74 def _expected_message(self, to, type_, tag, players=[]):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
75 content = "<%s" % tag
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
76 if not players:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
77 content += "/>"
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
78 else:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
79 content += ">"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
80 for i in range(0, len(players)):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
81 content += "<player index='%s'>%s</player>" % (i, players[i])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
82 content += "</%s>" % tag
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 return "<message to='%s' type='%s'><%s xmlns='%s'>%s</dummy></message>" % (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 to.full(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 type_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 TAG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 NAMESERVICE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 content,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
90
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
91 def test_create_or_invite_solo(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
92 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 self.plugin_0045.join_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 self.plugin._create_or_invite(self.plugin_0045.get_room(0, 0), [], Const.PROFILE[0])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
95 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
96
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 def test_create_or_invite_multi_not_waiting(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
98 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 self.plugin_0045.join_room(0, 0)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
100 other_players = [Const.JID[1], Const.JID[2]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
101 self.plugin._create_or_invite(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
102 self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
105
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 def test_create_or_invite_multi_waiting(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 self.reinit(player_init={"score": 0})
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 self.plugin_0045.join_room(0, 0)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
109 other_players = [Const.JID[1], Const.JID[2]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
110 self.plugin._create_or_invite(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
111 self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
113 self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
114 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
115
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
116 def test_init_game(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
117 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
119 self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 self.assertEqual([], self.plugin.games[ROOM_JID]["players"])
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
121
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 def test_check_join_auth(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
123 self.reinit()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 check = lambda value: getattr(self, "assert%s" % value)(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125 self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
127 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
128 # to test the "invited" mode, the referee must be different than the user to test
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
129 self.init_game(0, 1)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
130 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
131 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
132 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
133 check(False)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
134 self.plugin.invitations[ROOM_JID] = [(None, [Const.JID[0].userhostJID()])]
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
135 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
136 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
137 check(False)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 self.plugin.games[ROOM_JID]["players"].append(Const.JID[0].user)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
139 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
140
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
141 def test_update_players(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
142 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 self.init_game(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145 self.plugin._update_players(ROOM_JID, [], True, Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 self.assertEqual(self.plugin.games[ROOM_JID]["players"], [])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
147 self.plugin._update_players(ROOM_JID, ["user1"], True, Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 self.assertEqual(self.plugin.games[ROOM_JID]["players"], ["user1"])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
149 self.plugin._update_players(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
153 self.plugin._update_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 ) # should not be stored twice
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
159
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
160 def test_synchronize_room(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
161 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
162 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
163 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
164 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
165 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
166 self._expected_message(ROOM_JID, "groupchat", "players", []),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 self.plugin.games[ROOM_JID]["players"].append("test1")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
169 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
172 self._expected_message(ROOM_JID, "groupchat", "players", ["test1"]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 self.plugin.games[ROOM_JID]["started"] = True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 self.plugin.games[ROOM_JID]["players"].append("test2")
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
176 self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
178 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
179 self._expected_message(ROOM_JID, "groupchat", "started", ["test1", "test2"]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 self.plugin.games[ROOM_JID]["players"].append("test3")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 self.plugin.games[ROOM_JID]["players"].append("test4")
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
183 user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
184 user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
185 self.plugin._synchronize_room(ROOM_JID, [user1, user2], Const.PROFILE[0])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
186 self.assert_equal_xml(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
187 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
188 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 user1, "normal", "started", ["test1", "test2", "test3", "test4"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
192 self.assert_equal_xml(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
193 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
194 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 user2, "normal", "started", ["test1", "test2", "test3", "test4"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
196 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
198
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
199 def test_invite_players(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
200 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
201 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
202 self.plugin_0045.join_room(0, 1)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
203 self.assertEqual(self.plugin.invitations[ROOM_JID], [])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 room = self.plugin_0045.get_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
205 nicks = self.plugin._invite_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
212 # 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
213 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
214
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
215 nicks = self.plugin._invite_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 self.plugin.invitations[ROOM_JID][1][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
222 # 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
223 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
224
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
225 def test_check_invite_auth(self):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
226 def check(value, index):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
227 nick = self.plugin_0045.get_nick(0, index)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 getattr(self, "assert%s" % value)(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
229 self.plugin._check_invite_auth(ROOM_JID, nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
231
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
232 self.reinit()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
233
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 for mode in [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 self.plugin.FROM_ALL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 self.plugin.FROM_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 self.plugin.FROM_REFEREE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
238 self.plugin.FROM_PLAYERS,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 ]:
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
240 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
241 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
242
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
243 self.init_game(0, 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
244 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
245 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
246 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
247 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
248 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
249 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
250 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
251 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
252 check(False, 1)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
253 user_nick = self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 self.plugin.games[ROOM_JID]["players"].append(user_nick)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
255 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
256 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
257 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
258 check(False, 2)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
259
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
260 def test_is_referee(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
261 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
262 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
263 self.assertTrue(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
264 self.assertFalse(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 1)))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
265
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
266 def test_is_player(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
267 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
268 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
269 self.assertTrue(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
270 user_nick = self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 self.plugin.games[ROOM_JID]["players"].append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
272 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
273 self.assertFalse(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 2)))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
274
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
275 def test_check_wait_auth(self):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
276 def check(value, other_players, confirmed, rest):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
277 room = self.plugin_0045.get_room(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
278 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
279 (value, confirmed, rest), self.plugin._check_wait_auth(room, other_players)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
280 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
281
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
282 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
283 self.init_game(0, 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
284 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
285 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
286 check(True, [], [], [])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 True, [Const.JID[0]], [], [Const.JID[0]]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
289 ) # getRoomNickOfUser checks for the other users only
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
290 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
291 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
292 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
293 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
294 check(False, other_players, [], other_players)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
295 self.plugin_0045.join_room(0, 1)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
296 check(False, other_players, [], other_players)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
297 self.plugin_0045.join_room(0, 4)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
300 other_players,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
301 [self.plugin_0045.get_nick_of_user(0, 1, 0)],
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
302 [Const.JID[3]],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
304 self.plugin_0045.join_room(0, 3)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 other_players,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 [
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
309 self.plugin_0045.get_nick_of_user(0, 1, 0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
310 self.plugin_0045.get_nick_of_user(0, 3, 0),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
314
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
315 other_players = [Const.JID[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
316 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
317 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
319 other_players,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
320 [
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
321 self.plugin_0045.get_nick_of_user(0, 1, 0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
322 self.plugin_0045.get_nick_of_user(0, 3, 0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
323 self.plugin_0045.get_nick_of_user(0, 2, 0),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
327
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
328 def test_prepare_room_trivial(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
329 self.reinit()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
330 other_players = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
331 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
332 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
333 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
334 self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
336 self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, Const.JID[0].user))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
337 self.assertEqual((True, [], []), self.plugin._check_wait_auth(ROOM_JID, []))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
338 self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
339 self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[0].user))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
340 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
341 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
342 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
343
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
344 def test_prepare_room_invite(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
345 self.reinit()
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
346 other_players = [Const.JID[1], Const.JID[2]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
347 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
348 room = self.plugin_0045.get_room(0, 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
349
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
350 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
351 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
352 self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
353 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
354 self.assertFalse(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
355 self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
357 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
358 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
359 (True, [], other_players), self.plugin._check_wait_auth(room, other_players)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
360 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
361
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
362 player2_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
363 self.plugin.user_joined_trigger(room, room.roster[player2_nick], PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
364 self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
365 self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, player2_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
366 self.assertFalse(self.plugin.is_referee(ROOM_JID, player2_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
367 self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
368 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
369 self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
370 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
371 self.assertFalse(self.plugin.is_player(ROOM_JID, "xxx"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
372 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
373 (False, False),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
374 self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[1]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
376
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
377 def test_prepare_room_score_1(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
378 self.reinit(player_init={"score": 0})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
379 other_players = [Const.JID[1], Const.JID[2]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
380 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
381 room = self.plugin_0045.get_room(0, 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
382
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
383 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
384 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
385 self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
386 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
387 self.assertFalse(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
388 self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
389 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
390 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
391 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
392 (False, [], other_players), self.plugin._check_wait_auth(room, other_players)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
393 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
394
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
395 user_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
396 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
397 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
398 self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, user_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
399 self.assertFalse(self.plugin.is_referee(ROOM_JID, user_nick))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
400 self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
401 # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
402 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
403 self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
404 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
405 # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
406 self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[3].user))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
407 # but Const.JID[3] is actually not in the room
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
408 self.assertEqual(self.plugin_0045.get_nick_of_user(0, 3, 0), None)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
409 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
410 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
411 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
412
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
413 def test_prepare_room_score_2(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 self.reinit(player_init={"score": 0})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
415 other_players = [Const.JID[1], Const.JID[4]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
416 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
417 room = self.plugin_0045.get_room(0, 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
418
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
419 user_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
420 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
421 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
422 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
423 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
424 user_nick = self.plugin_0045.join_room(0, 4)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
425 self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
427 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
428 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
429
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
430 def test_user_joined_trigger(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
431 self.reinit(player_init={"xxx": "xyz"})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
432 other_players = [Const.JID[1], Const.JID[3]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
433 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
434 nicks = [self.plugin_0045.get_nick(0, 0)]
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
435
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
436 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
437 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
438 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
439 )
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
440 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1)
795
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 # wrong profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
443 user_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
444 room = self.plugin_0045.get_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
445 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
446 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
447 self.host.get_sent_message(0), None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
448 ) # no new message has been sent
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
449 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
795
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 # referee profile, user is allowed, wait for one more
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
452 room = self.plugin_0045.get_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
453 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
454 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
456 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
457 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
458 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
459 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
460
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
461 # referee profile, user is not allowed
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
462 user_nick = self.plugin_0045.join_room(0, 4)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
463 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
464 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
465 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
466 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
467 JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
468 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
469 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
470 self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
471
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
472 # referee profile, user is allowed, everybody here
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
473 user_nick = self.plugin_0045.join_room(0, 3)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
474 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
475 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
476 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
477 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
478 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
479 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
480 self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) # game started
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
481 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
482
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
483 # wait for none
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
484 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
485 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
486 self.assertNotEqual(self.host.get_sent_message(0), None) # init messages
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
487 room = self.plugin_0045.get_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
488 nicks = [self.plugin_0045.get_nick(0, 0)]
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
489 user_nick = self.plugin_0045.join_room(0, 3)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
490 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
491 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
492 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
493 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
494 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
495 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
496 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
497
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
498 def test_user_left_trigger(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
499 self.reinit(player_init={"xxx": "xyz"})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
500 other_players = [Const.JID[1], Const.JID[3], Const.JID[4]]
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
501 self.plugin.prepare_room(other_players, ROOM_JID, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
502 room = self.plugin_0045.get_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
503 nicks = [self.plugin_0045.get_nick(0, 0)]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
504 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
505 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
506 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
507 Const.JID[1].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
508 Const.JID[3].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
509 Const.JID[4].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
510 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
511 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
512
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
513 # one user joins
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
514 user_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
515 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
516 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
517
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
518 # the user leaves
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
519 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
520 room = self.plugin_0045.get_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
521 # to not call self.plugin_0045.leave_room(0, 1) here, we are testing the trigger with a wrong profile
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
522 self.plugin.user_left_trigger(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
523 room, User(user_nick, Const.JID[1]), Const.PROFILE[1]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
524 ) # not the referee
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
525 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
526 room = self.plugin_0045.get_room(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
527 user_nick = self.plugin_0045.leave_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
528 self.plugin.user_left_trigger(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
529 room, User(user_nick, Const.JID[1]), PROFILE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
530 ) # referee
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
531 nicks.pop()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
532 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
533
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
534 # all the users join
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
535 user_nick = self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
536 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
537 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
538 user_nick = self.plugin_0045.join_room(0, 3)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
539 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
540 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
541 user_nick = self.plugin_0045.join_room(0, 4)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
542 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
543 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
544 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
545 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
546
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
547 # one user leaves
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
548 user_nick = self.plugin_0045.leave_room(0, 4)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
549 self.plugin.user_left_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
550 nicks.pop()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
551 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
552 self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
553 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
554
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
555 # another leaves
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
556 user_nick = self.plugin_0045.leave_room(0, 3)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
557 self.plugin.user_left_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
558 nicks.pop()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
559 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
560 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
561 [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
562 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
563
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
564 # they can join again
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
565 user_nick = self.plugin_0045.join_room(0, 3)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
566 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
567 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
568 user_nick = self.plugin_0045.join_room(0, 4)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
569 self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
570 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
571 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
572 self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0)
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
573
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
574 def test_check_create_game_and_init(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
575 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
576 helpers.mute_logging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
577 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
578 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
579 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
580 helpers.unmute_logging()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
581
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
582 nick = self.plugin_0045.join_room(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
583 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
584 (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
585 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
586 self.assertTrue(self.plugin._game_exists(ROOM_JID, False))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
587 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
588 self.assertTrue(self.plugin.is_referee(ROOM_JID, nick))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
589
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
590 helpers.mute_logging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
591 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
592 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
593 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
594 helpers.unmute_logging()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
595
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
596 self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
597 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
598 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
599 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
600
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
601 self.plugin.create_game(ROOM_JID, [Const.JID[1]], PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
602 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
603 (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
604 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
605 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
606 (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
607 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
608
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
609 def test_create_game(self):
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
610
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
611 self.reinit(player_init={"xxx": "xyz"})
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
612 nicks = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
613 for i in [0, 1, 3, 4]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
614 nicks.append(self.plugin_0045.join_room(0, i))
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
615
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
616 # game not exists
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
617 self.plugin.create_game(ROOM_JID, nicks, PROFILE)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
618 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
619 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
620 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
621 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
622 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
623 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
624 for nick in nicks:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
625 self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
626 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
627 self.plugin.player_init, self.plugin.games[ROOM_JID]["players_data"][nick]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
628 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
629 self.plugin.games[ROOM_JID]["players_data"][nick]["xxx"] = nick
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
630 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
631 # checks that a copy of self.player_init has been done and not a reference
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
632 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
633 nick, self.plugin.games[ROOM_JID]["players_data"][nick]["xxx"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
634 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
635
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
636 # game exists, current profile is referee
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
637 self.reinit(player_init={"xxx": "xyz"})
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
638 self.init_game(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
639 self.plugin.games[ROOM_JID]["started"] = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
640 self.plugin.create_game(ROOM_JID, nicks, PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
641 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
642 self.host.get_sent_message_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
643 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
645
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
646 # game exists, current profile is not referee
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
647 self.reinit(player_init={"xxx": "xyz"})
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
648 self.init_game(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
649 self.plugin.games[ROOM_JID]["started"] = True
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
650 self.plugin_0045.join_room(0, 1)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
651 self.plugin.create_game(ROOM_JID, nicks, OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
652 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
653 self.host.get_sent_message(0), None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
654 ) # no sync message has been sent by other_profile