annotate libervia/backend/test/test_plugin_misc_room_game.py @ 4284:3a550e9a2b55

black reformatting
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 16:47:45 +0200
parents 0d7bb4df2343
children
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)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
94 self.plugin._create_or_invite(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
95 self.plugin_0045.get_room(0, 0), [], Const.PROFILE[0]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
96 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 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
98
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 def test_create_or_invite_multi_not_waiting(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
100 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
101 self.plugin_0045.join_room(0, 0)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
102 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
103 self.plugin._create_or_invite(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
104 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
105 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 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
107
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
108 def test_create_or_invite_multi_waiting(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 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
110 self.plugin_0045.join_room(0, 0)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
111 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
112 self.plugin._create_or_invite(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
113 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
114 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
115 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
116 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
117
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
118 def test_init_game(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
119 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
120 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
121 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
122 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
123
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
124 def test_check_join_auth(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
125 self.reinit()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 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
127 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
128 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
129 check(False)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
130 # 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
131 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
132 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
133 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
134 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
135 check(False)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
136 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
137 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
138 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
139 check(False)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 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
141 check(True)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
142
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 def test_update_players(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
144 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
145 self.init_game(0, 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, [], 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"], [])
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, ["user1"], True, Const.PROFILE[0])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 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
151 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
152 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
155 self.plugin._update_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 ) # should not be stored twice
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
161
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
162 def test_synchronize_room(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
163 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
164 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
165 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
166 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
167 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
168 self._expected_message(ROOM_JID, "groupchat", "players", []),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 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
171 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
172 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
173 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
174 self._expected_message(ROOM_JID, "groupchat", "players", ["test1"]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self.plugin.games[ROOM_JID]["started"] = True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 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
178 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
179 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
180 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
181 self._expected_message(ROOM_JID, "groupchat", "started", ["test1", "test2"]),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 self.plugin.games[ROOM_JID]["players"].append("test3")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 self.plugin.games[ROOM_JID]["players"].append("test4")
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
185 user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user)
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
186 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
187 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
188 self.assert_equal_xml(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
189 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
190 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 user1, "normal", "started", ["test1", "test2", "test3", "test4"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
194 self.assert_equal_xml(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 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
196 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
197 user2, "normal", "started", ["test1", "test2", "test3", "test4"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
198 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
200
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
201 def test_invite_players(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
202 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
203 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
204 self.plugin_0045.join_room(0, 1)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
205 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
206 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
207 nicks = self.plugin._invite_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 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
209 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
212 [Const.JID[1].userhostJID(), Const.JID[2].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
213 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
214 # 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
215 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
216
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
217 nicks = self.plugin._invite_players(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 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
219 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 self.plugin.invitations[ROOM_JID][1][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 [Const.JID[1].userhostJID(), Const.JID[3].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
224 # 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
225 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
226
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
227 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
228 def check(value, index):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
229 nick = self.plugin_0045.get_nick(0, index)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 getattr(self, "assert%s" % value)(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
231 self.plugin._check_invite_auth(ROOM_JID, nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
233
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
234 self.reinit()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
235
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 for mode in [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 self.plugin.FROM_ALL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
238 self.plugin.FROM_NONE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 self.plugin.FROM_REFEREE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 self.plugin.FROM_PLAYERS,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 ]:
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
242 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
243 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
244
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
245 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
246 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
247 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
248 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
249 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
250 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
251 check(False, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
252 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
253 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
254 check(False, 1)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
255 user_nick = self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 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
257 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
258 check(True, 0)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
259 check(True, 1)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
260 check(False, 2)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
261
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
262 def test_is_referee(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
263 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
264 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
265 self.assertTrue(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 0)))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
266 self.assertFalse(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
267 self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 1))
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
268 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
269
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
270 def test_is_player(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
271 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
272 self.init_game(0, 0)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
273 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
274 user_nick = self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 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
276 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
277 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
278
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
279 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
280 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
281 room = self.plugin_0045.get_room(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
282 self.assertEqual(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
283 (value, confirmed, rest),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
284 self.plugin._check_wait_auth(room, other_players),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
285 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
286
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
287 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
288 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
289 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
290 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
291 check(True, [], [], [])
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 True, [Const.JID[0]], [], [Const.JID[0]]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 ) # 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
295 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
296 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
297 check(True, [], [], [])
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
298 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
299 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
300 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
301 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
302 self.plugin_0045.join_room(0, 4)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
303 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 other_players,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
306 [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
307 [Const.JID[3]],
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.join_room(0, 3)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 other_players,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 [
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
314 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
315 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
316 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
317 [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
319
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
320 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
321 # 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
322 check(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 other_players,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 [
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
326 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
327 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
328 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
329 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
330 [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
331 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
332
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
333 def test_prepare_room_trivial(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
334 self.reinit()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
335 other_players = []
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
336 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
337 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
338 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
339 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
340 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
341 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
342 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
343 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
344 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
345 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
346 (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
347 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
348
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
349 def test_prepare_room_invite(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
350 self.reinit()
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
351 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
352 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
353 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
354
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
355 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
357 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
358 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
359 self.assertFalse(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
360 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
361 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
362 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
363 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
364 (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
365 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
366
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
367 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
368 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
369 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
370 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
371 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
372 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
373 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
374 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
375 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
376 self.assertFalse(self.plugin.is_player(ROOM_JID, "xxx"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
377 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
378 (False, False),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
379 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
380 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
381
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
382 def test_prepare_room_score_1(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
383 self.reinit(player_init={"score": 0})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
384 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
385 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
386 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
387
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
388 self.assertFalse(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
389 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
390 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
391 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
392 self.assertFalse(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
393 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
394 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
395 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
396 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
397 (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
398 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
399
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
400 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
401 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
402 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
403 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
404 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
405 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
406 # 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
407 self.assertTrue(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
408 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
409 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
410 # 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
411 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
412 # 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
413 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
414 self.assertEqual(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
415 (True, False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
416 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
417 )
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 def test_prepare_room_score_2(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
420 self.reinit(player_init={"score": 0})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
421 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
422 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
423 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
424
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
425 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
426 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
427 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
428 (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
429 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
430 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
431 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
432 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
433 (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
434 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
435
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
436 def test_user_joined_trigger(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
437 self.reinit(player_init={"xxx": "xyz"})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
438 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
439 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
440 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
441
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
442 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
443 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
444 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
445 )
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
446 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
447
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
448 # wrong profile
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
449 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
450 room = self.plugin_0045.get_room(0, 1)
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
451 self.plugin.user_joined_trigger(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
452 room, User(user_nick, Const.JID[1]), OTHER_PROFILE
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
453 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
454 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
455 self.host.get_sent_message(0), None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
456 ) # 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
457 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
458
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
459 # 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
460 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
461 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
462 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
463 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
464 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
465 self._expected_message(ROOM_JID, "groupchat", "players", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
466 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
467 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
468
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
469 # 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
470 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
471 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
472 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
473 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
474 self._expected_message(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
475 JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
476 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
477 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
478 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
479
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
480 # 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
481 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
482 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
483 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
484 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
485 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
486 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
487 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
488 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
489 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
490
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
491 # wait for none
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
492 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
493 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
494 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
495 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
496 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
497 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
498 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
499 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
500 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
501 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
502 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
503 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
504 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
505
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
506 def test_user_left_trigger(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
507 self.reinit(player_init={"xxx": "xyz"})
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
508 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
509 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
510 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
511 nicks = [self.plugin_0045.get_nick(0, 0)]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
512 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
513 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
514 [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
515 Const.JID[1].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
516 Const.JID[3].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
517 Const.JID[4].userhostJID(),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
518 ],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
519 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
520
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
521 # one user joins
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
522 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
523 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
524 nicks.append(user_nick)
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
525
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
526 # the user leaves
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
527 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
528 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
529 # 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
530 self.plugin.user_left_trigger(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
531 room, User(user_nick, Const.JID[1]), Const.PROFILE[1]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
532 ) # not the referee
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
533 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
534 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
535 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
536 self.plugin.user_left_trigger(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
537 room, User(user_nick, Const.JID[1]), PROFILE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
538 ) # referee
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
539 nicks.pop()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
540 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
541
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
542 # all the users join
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
543 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
544 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
545 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
546 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
547 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
548 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
549 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
550 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
551 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
552 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
553 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
554
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
555 # one user 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, 4)
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[4]), 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], [Const.JID[4].userhostJID()]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
561 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
562
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
563 # another leaves
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
564 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
565 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
566 nicks.pop()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
567 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
568 self.plugin.invitations[ROOM_JID][0][1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
569 [Const.JID[4].userhostJID(), Const.JID[3].userhostJID()],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
570 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
571
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
572 # they can join again
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
573 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
574 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
575 nicks.append(user_nick)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
576 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
577 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
578 nicks.append(user_nick)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
579 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
1412
979210da778a test: fix the tests
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
580 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
581
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
582 def test_check_create_game_and_init(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
583 self.reinit()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
584 helpers.mute_logging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
585 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
586 (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
587 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
588 helpers.unmute_logging()
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 nick = self.plugin_0045.join_room(0, 0)
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 (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
593 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
594 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
595 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
596 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
597
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
598 helpers.mute_logging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
599 self.assertEqual(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
600 (False, False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
601 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
602 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
603 helpers.unmute_logging()
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
604
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
605 self.plugin_0045.join_room(0, 1)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
606 self.assertEqual(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
607 (False, False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
608 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
609 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
610
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
611 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
612 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
613 (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
614 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
615 self.assertEqual(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
616 (False, False),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
617 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
618 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
619
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
620 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
621
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
622 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
623 nicks = []
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
624 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
625 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
626
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
627 # game not exists
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
628 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
629 self.assertTrue(self.plugin._game_exists(ROOM_JID, True))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
630 self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
631 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
632 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
633 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
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 for nick in nicks:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
636 self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
637 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
638 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
639 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
640 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
641 for nick in nicks:
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
642 # 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
643 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 nick, self.plugin.games[ROOM_JID]["players_data"][nick]["xxx"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
645 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
646
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
647 # game exists, current profile is referee
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
648 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
649 self.init_game(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
650 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
651 self.plugin.create_game(ROOM_JID, nicks, 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_xml(0),
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
654 self._expected_message(ROOM_JID, "groupchat", "started", nicks),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
655 )
795
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
656
6625558371db test: added tests for the plugin "room game" + rename other test files
souliane <souliane@mailoo.org>
parents:
diff changeset
657 # game exists, current profile is not referee
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 997
diff changeset
658 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
659 self.init_game(0, 0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
660 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
661 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
662 self.plugin.create_game(ROOM_JID, nicks, OTHER_PROFILE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
663 self.assertEqual(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
664 self.host.get_sent_message(0), None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
665 ) # no sync message has been sent by other_profile