Mercurial > libervia-backend
diff sat/test/test_plugin_misc_room_game.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children |
line wrap: on
line diff
--- a/sat/test/test_plugin_misc_room_game.py Fri Apr 07 15:18:39 2023 +0200 +++ b/sat/test/test_plugin_misc_room_game.py Sat Apr 08 13:54:42 2023 +0200 @@ -65,13 +65,13 @@ self.host ) for profile in Const.PROFILE: - self.host.getClient(profile) # init self.host.profiles[profile] + self.host.get_client(profile) # init self.host.profiles[profile] - def initGame(self, muc_index, user_index): - self.plugin_0045.joinRoom(user_index, muc_index) - self.plugin._initGame(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user) + def init_game(self, muc_index, user_index): + self.plugin_0045.join_room(user_index, muc_index) + self.plugin._init_game(JID(Const.MUC_STR[muc_index]), Const.JID[user_index].user) - def _expectedMessage(self, to, type_, tag, players=[]): + def _expected_message(self, to, type_, tag, players=[]): content = "<%s" % tag if not players: content += "/>" @@ -88,45 +88,45 @@ content, ) - def test_createOrInvite_solo(self): + def test_create_or_invite_solo(self): self.reinit() - self.plugin_0045.joinRoom(0, 0) - self.plugin._createOrInvite(self.plugin_0045.getRoom(0, 0), [], Const.PROFILE[0]) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.plugin_0045.join_room(0, 0) + self.plugin._create_or_invite(self.plugin_0045.get_room(0, 0), [], Const.PROFILE[0]) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) - def test_createOrInvite_multi_not_waiting(self): + def test_create_or_invite_multi_not_waiting(self): self.reinit() - self.plugin_0045.joinRoom(0, 0) + self.plugin_0045.join_room(0, 0) other_players = [Const.JID[1], Const.JID[2]] - self.plugin._createOrInvite( - self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0] + self.plugin._create_or_invite( + self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0] ) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) - def test_createOrInvite_multi_waiting(self): + def test_create_or_invite_multi_waiting(self): self.reinit(player_init={"score": 0}) - self.plugin_0045.joinRoom(0, 0) + self.plugin_0045.join_room(0, 0) other_players = [Const.JID[1], Const.JID[2]] - self.plugin._createOrInvite( - self.plugin_0045.getRoom(0, 0), other_players, Const.PROFILE[0] + self.plugin._create_or_invite( + self.plugin_0045.get_room(0, 0), other_players, Const.PROFILE[0] ) - self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) + self.assertTrue(self.plugin._game_exists(ROOM_JID, False)) + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) - def test_initGame(self): + def test_init_game(self): self.reinit() - self.initGame(0, 0) - self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) + self.init_game(0, 0) + self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user)) self.assertEqual([], self.plugin.games[ROOM_JID]["players"]) - def test_checkJoinAuth(self): + def test_check_join_auth(self): self.reinit() check = lambda value: getattr(self, "assert%s" % value)( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user) ) check(False) # to test the "invited" mode, the referee must be different than the user to test - self.initGame(0, 1) + self.init_game(0, 1) self.plugin.join_mode = self.plugin.ALL check(True) self.plugin.join_mode = self.plugin.INVITED @@ -138,71 +138,71 @@ self.plugin.games[ROOM_JID]["players"].append(Const.JID[0].user) check(True) - def test_updatePlayers(self): + def test_update_players(self): self.reinit() - self.initGame(0, 0) + self.init_game(0, 0) self.assertEqual(self.plugin.games[ROOM_JID]["players"], []) - self.plugin._updatePlayers(ROOM_JID, [], True, Const.PROFILE[0]) + self.plugin._update_players(ROOM_JID, [], True, Const.PROFILE[0]) self.assertEqual(self.plugin.games[ROOM_JID]["players"], []) - self.plugin._updatePlayers(ROOM_JID, ["user1"], True, Const.PROFILE[0]) + self.plugin._update_players(ROOM_JID, ["user1"], True, Const.PROFILE[0]) self.assertEqual(self.plugin.games[ROOM_JID]["players"], ["user1"]) - self.plugin._updatePlayers(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) + self.plugin._update_players(ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0]) self.assertEqual( self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"] ) - self.plugin._updatePlayers( + self.plugin._update_players( ROOM_JID, ["user2", "user3"], True, Const.PROFILE[0] ) # should not be stored twice self.assertEqual( self.plugin.games[ROOM_JID]["players"], ["user1", "user2", "user3"] ) - def test_synchronizeRoom(self): + def test_synchronize_room(self): self.reinit() - self.initGame(0, 0) - self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) + self.init_game(0, 0) + self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "players", []), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "players", []), ) self.plugin.games[ROOM_JID]["players"].append("test1") - self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) + self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "players", ["test1"]), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "players", ["test1"]), ) self.plugin.games[ROOM_JID]["started"] = True self.plugin.games[ROOM_JID]["players"].append("test2") - self.plugin._synchronizeRoom(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) + self.plugin._synchronize_room(ROOM_JID, [Const.MUC[0]], Const.PROFILE[0]) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "started", ["test1", "test2"]), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "started", ["test1", "test2"]), ) self.plugin.games[ROOM_JID]["players"].append("test3") self.plugin.games[ROOM_JID]["players"].append("test4") user1 = JID(ROOM_JID.userhost() + "/" + Const.JID[0].user) user2 = JID(ROOM_JID.userhost() + "/" + Const.JID[1].user) - self.plugin._synchronizeRoom(ROOM_JID, [user1, user2], Const.PROFILE[0]) - self.assertEqualXML( - self.host.getSentMessageXml(0), - self._expectedMessage( + self.plugin._synchronize_room(ROOM_JID, [user1, user2], Const.PROFILE[0]) + self.assert_equal_xml( + self.host.get_sent_message_xml(0), + self._expected_message( user1, "normal", "started", ["test1", "test2", "test3", "test4"] ), ) - self.assertEqualXML( - self.host.getSentMessageXml(0), - self._expectedMessage( + self.assert_equal_xml( + self.host.get_sent_message_xml(0), + self._expected_message( user2, "normal", "started", ["test1", "test2", "test3", "test4"] ), ) - def test_invitePlayers(self): + def test_invite_players(self): self.reinit() - self.initGame(0, 0) - self.plugin_0045.joinRoom(0, 1) + self.init_game(0, 0) + self.plugin_0045.join_room(0, 1) self.assertEqual(self.plugin.invitations[ROOM_JID], []) - room = self.plugin_0045.getRoom(0, 0) - nicks = self.plugin._invitePlayers( + room = self.plugin_0045.get_room(0, 0) + nicks = self.plugin._invite_players( room, [Const.JID[1], Const.JID[2]], Const.JID[0].user, Const.PROFILE[0] ) self.assertEqual( @@ -212,7 +212,7 @@ # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost self.assertEqual(nicks, [Const.JID[1].user, Const.JID[2].user]) - nicks = self.plugin._invitePlayers( + nicks = self.plugin._invite_players( room, [Const.JID[1], Const.JID[3]], Const.JID[0].user, Const.PROFILE[0] ) self.assertEqual( @@ -222,11 +222,11 @@ # this time Const.JID[1] and Const.JID[3] have the same user but the host differs self.assertEqual(nicks, [Const.JID[1].user]) - def test_checkInviteAuth(self): + def test_check_invite_auth(self): def check(value, index): - nick = self.plugin_0045.getNick(0, index) + nick = self.plugin_0045.get_nick(0, index) getattr(self, "assert%s" % value)( - self.plugin._checkInviteAuth(ROOM_JID, nick) + self.plugin._check_invite_auth(ROOM_JID, nick) ) self.reinit() @@ -240,7 +240,7 @@ self.plugin.invite_mode = mode check(True, 0) - self.initGame(0, 0) + self.init_game(0, 0) self.plugin.invite_mode = self.plugin.FROM_ALL check(True, 0) check(True, 1) @@ -250,37 +250,37 @@ self.plugin.invite_mode = self.plugin.FROM_REFEREE check(True, 0) check(False, 1) - user_nick = self.plugin_0045.joinRoom(0, 1) + user_nick = self.plugin_0045.join_room(0, 1) self.plugin.games[ROOM_JID]["players"].append(user_nick) self.plugin.invite_mode = self.plugin.FROM_PLAYERS check(True, 0) check(True, 1) check(False, 2) - def test_isReferee(self): + def test_is_referee(self): self.reinit() - self.initGame(0, 0) - self.assertTrue(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 0))) - self.assertFalse(self.plugin.isReferee(ROOM_JID, self.plugin_0045.getNick(0, 1))) + self.init_game(0, 0) + self.assertTrue(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 0))) + self.assertFalse(self.plugin.is_referee(ROOM_JID, self.plugin_0045.get_nick(0, 1))) - def test_isPlayer(self): + def test_is_player(self): self.reinit() - self.initGame(0, 0) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 0))) - user_nick = self.plugin_0045.joinRoom(0, 1) + self.init_game(0, 0) + self.assertTrue(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 0))) + user_nick = self.plugin_0045.join_room(0, 1) self.plugin.games[ROOM_JID]["players"].append(user_nick) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) - self.assertFalse(self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNick(0, 2))) + self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick)) + self.assertFalse(self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick(0, 2))) - def test_checkWaitAuth(self): + def test_check_wait_auth(self): def check(value, other_players, confirmed, rest): - room = self.plugin_0045.getRoom(0, 0) + room = self.plugin_0045.get_room(0, 0) self.assertEqual( - (value, confirmed, rest), self.plugin._checkWaitAuth(room, other_players) + (value, confirmed, rest), self.plugin._check_wait_auth(room, other_players) ) self.reinit() - self.initGame(0, 0) + self.init_game(0, 0) other_players = [Const.JID[1], Const.JID[3]] self.plugin.wait_mode = self.plugin.FOR_NONE check(True, [], [], []) @@ -292,22 +292,22 @@ check(True, [], [], []) check(False, [Const.JID[0]], [], [Const.JID[0]]) check(False, other_players, [], other_players) - self.plugin_0045.joinRoom(0, 1) + self.plugin_0045.join_room(0, 1) check(False, other_players, [], other_players) - self.plugin_0045.joinRoom(0, 4) + self.plugin_0045.join_room(0, 4) check( False, other_players, - [self.plugin_0045.getNickOfUser(0, 1, 0)], + [self.plugin_0045.get_nick_of_user(0, 1, 0)], [Const.JID[3]], ) - self.plugin_0045.joinRoom(0, 3) + self.plugin_0045.join_room(0, 3) check( True, other_players, [ - self.plugin_0045.getNickOfUser(0, 1, 0), - self.plugin_0045.getNickOfUser(0, 3, 0), + self.plugin_0045.get_nick_of_user(0, 1, 0), + self.plugin_0045.get_nick_of_user(0, 3, 0), ], [], ) @@ -318,189 +318,189 @@ True, other_players, [ - self.plugin_0045.getNickOfUser(0, 1, 0), - self.plugin_0045.getNickOfUser(0, 3, 0), - self.plugin_0045.getNickOfUser(0, 2, 0), + self.plugin_0045.get_nick_of_user(0, 1, 0), + self.plugin_0045.get_nick_of_user(0, 3, 0), + self.plugin_0045.get_nick_of_user(0, 2, 0), ], [], ) - def test_prepareRoom_trivial(self): + def test_prepare_room_trivial(self): self.reinit() other_players = [] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) self.assertTrue( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[0], Const.JID[0].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[0], Const.JID[0].user) ) - self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[0].user)) - self.assertEqual((True, [], []), self.plugin._checkWaitAuth(ROOM_JID, [])) - self.assertTrue(self.plugin.isReferee(ROOM_JID, Const.JID[0].user)) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[0].user)) + self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, Const.JID[0].user)) + self.assertEqual((True, [], []), self.plugin._check_wait_auth(ROOM_JID, [])) + self.assertTrue(self.plugin.is_referee(ROOM_JID, Const.JID[0].user)) + self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[0].user)) self.assertEqual( - (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) - def test_prepareRoom_invite(self): + def test_prepare_room_invite(self): self.reinit() other_players = [Const.JID[1], Const.JID[2]] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - room = self.plugin_0045.getRoom(0, 0) + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + room = self.plugin_0045.get_room(0, 0) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) self.assertTrue( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user) ) self.assertFalse( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user) ) - self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) + self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user)) self.assertEqual( - (True, [], other_players), self.plugin._checkWaitAuth(room, other_players) + (True, [], other_players), self.plugin._check_wait_auth(room, other_players) ) - player2_nick = self.plugin_0045.joinRoom(0, 1) - self.plugin.userJoinedTrigger(room, room.roster[player2_nick], PROFILE) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) - self.assertTrue(self.plugin._checkInviteAuth(ROOM_JID, player2_nick)) - self.assertFalse(self.plugin.isReferee(ROOM_JID, player2_nick)) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, player2_nick)) + player2_nick = self.plugin_0045.join_room(0, 1) + self.plugin.user_joined_trigger(room, room.roster[player2_nick], PROFILE) + self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick)) + self.assertTrue(self.plugin._check_invite_auth(ROOM_JID, player2_nick)) + self.assertFalse(self.plugin.is_referee(ROOM_JID, player2_nick)) + self.assertTrue(self.plugin.is_player(ROOM_JID, player2_nick)) self.assertTrue( - self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)) + self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0)) ) - self.assertFalse(self.plugin.isPlayer(ROOM_JID, "xxx")) + self.assertFalse(self.plugin.is_player(ROOM_JID, "xxx")) self.assertEqual( (False, False), - self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[1]), + self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[1]), ) - def test_prepareRoom_score1(self): + def test_prepare_room_score_1(self): self.reinit(player_init={"score": 0}) other_players = [Const.JID[1], Const.JID[2]] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - room = self.plugin_0045.getRoom(0, 0) + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + room = self.plugin_0045.get_room(0, 0) - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) self.assertTrue( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[1], Const.JID[1].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[1], Const.JID[1].user) ) self.assertFalse( - self.plugin._checkJoinAuth(ROOM_JID, Const.JID[3], Const.JID[3].user) + self.plugin._check_join_auth(ROOM_JID, Const.JID[3], Const.JID[3].user) ) - self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, Const.JID[1].user)) + self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, Const.JID[1].user)) self.assertEqual( - (False, [], other_players), self.plugin._checkWaitAuth(room, other_players) + (False, [], other_players), self.plugin._check_wait_auth(room, other_players) ) - user_nick = self.plugin_0045.joinRoom(0, 1) - self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) - self.assertFalse(self.plugin._checkInviteAuth(ROOM_JID, user_nick)) - self.assertFalse(self.plugin.isReferee(ROOM_JID, user_nick)) - self.assertTrue(self.plugin.isPlayer(ROOM_JID, user_nick)) + user_nick = self.plugin_0045.join_room(0, 1) + self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE) + self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick)) + self.assertFalse(self.plugin._check_invite_auth(ROOM_JID, user_nick)) + self.assertFalse(self.plugin.is_referee(ROOM_JID, user_nick)) + self.assertTrue(self.plugin.is_player(ROOM_JID, user_nick)) # the following assertion is True because Const.JID[1] and Const.JID[2] have the same userhost self.assertTrue( - self.plugin.isPlayer(ROOM_JID, self.plugin_0045.getNickOfUser(0, 2, 0)) + self.plugin.is_player(ROOM_JID, self.plugin_0045.get_nick_of_user(0, 2, 0)) ) # the following assertion is True because Const.JID[1] nick in the room is equal to Const.JID[3].user - self.assertTrue(self.plugin.isPlayer(ROOM_JID, Const.JID[3].user)) + self.assertTrue(self.plugin.is_player(ROOM_JID, Const.JID[3].user)) # but Const.JID[3] is actually not in the room - self.assertEqual(self.plugin_0045.getNickOfUser(0, 3, 0), None) + self.assertEqual(self.plugin_0045.get_nick_of_user(0, 3, 0), None) self.assertEqual( - (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, Const.PROFILE[0]) + (True, False), self.plugin._check_create_game_and_init(ROOM_JID, Const.PROFILE[0]) ) - def test_prepareRoom_score2(self): + def test_prepare_room_score_2(self): self.reinit(player_init={"score": 0}) other_players = [Const.JID[1], Const.JID[4]] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - room = self.plugin_0045.getRoom(0, 0) + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + room = self.plugin_0045.get_room(0, 0) - user_nick = self.plugin_0045.joinRoom(0, 1) - self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) + user_nick = self.plugin_0045.join_room(0, 1) + self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE) self.assertEqual( - (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) - user_nick = self.plugin_0045.joinRoom(0, 4) - self.plugin.userJoinedTrigger(room, room.roster[user_nick], PROFILE) + user_nick = self.plugin_0045.join_room(0, 4) + self.plugin.user_joined_trigger(room, room.roster[user_nick], PROFILE) self.assertEqual( - (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) - def test_userJoinedTrigger(self): + def test_user_joined_trigger(self): self.reinit(player_init={"xxx": "xyz"}) other_players = [Const.JID[1], Const.JID[3]] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - nicks = [self.plugin_0045.getNick(0, 0)] + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + nicks = [self.plugin_0045.get_nick(0, 0)] self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "players", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "players", nicks), ) self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 1) # wrong profile - user_nick = self.plugin_0045.joinRoom(0, 1) - room = self.plugin_0045.getRoom(0, 1) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) + user_nick = self.plugin_0045.join_room(0, 1) + room = self.plugin_0045.get_room(0, 1) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), OTHER_PROFILE) self.assertEqual( - self.host.getSentMessage(0), None + self.host.get_sent_message(0), None ) # no new message has been sent - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started # referee profile, user is allowed, wait for one more - room = self.plugin_0045.getRoom(0, 0) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) + room = self.plugin_0045.get_room(0, 0) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE) nicks.append(user_nick) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "players", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "players", nicks), ) - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started # referee profile, user is not allowed - user_nick = self.plugin_0045.joinRoom(0, 4) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 4) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage( + self.host.get_sent_message_xml(0), + self._expected_message( JID(ROOM_JID.userhost() + "/" + user_nick), "normal", "players", nicks ), ) - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) # game not started + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) # game not started # referee profile, user is allowed, everybody here - user_nick = self.plugin_0045.joinRoom(0, 3) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 3) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE) nicks.append(user_nick) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "started", nicks), ) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) # game started + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) # game started self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) # wait for none self.reinit() - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - self.assertNotEqual(self.host.getSentMessage(0), None) # init messages - room = self.plugin_0045.getRoom(0, 0) - nicks = [self.plugin_0045.getNick(0, 0)] - user_nick = self.plugin_0045.joinRoom(0, 3) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + self.assertNotEqual(self.host.get_sent_message(0), None) # init messages + room = self.plugin_0045.get_room(0, 0) + nicks = [self.plugin_0045.get_nick(0, 0)] + user_nick = self.plugin_0045.join_room(0, 3) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE) nicks.append(user_nick) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "started", nicks), ) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) - def test_userLeftTrigger(self): + def test_user_left_trigger(self): self.reinit(player_init={"xxx": "xyz"}) other_players = [Const.JID[1], Const.JID[3], Const.JID[4]] - self.plugin.prepareRoom(other_players, ROOM_JID, PROFILE) - room = self.plugin_0045.getRoom(0, 0) - nicks = [self.plugin_0045.getNick(0, 0)] + self.plugin.prepare_room(other_players, ROOM_JID, PROFILE) + room = self.plugin_0045.get_room(0, 0) + nicks = [self.plugin_0045.get_nick(0, 0)] self.assertEqual( self.plugin.invitations[ROOM_JID][0][1], [ @@ -511,50 +511,50 @@ ) # one user joins - user_nick = self.plugin_0045.joinRoom(0, 1) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 1) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE) nicks.append(user_nick) # the user leaves self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) - room = self.plugin_0045.getRoom(0, 1) - # to not call self.plugin_0045.leaveRoom(0, 1) here, we are testing the trigger with a wrong profile - self.plugin.userLeftTrigger( + room = self.plugin_0045.get_room(0, 1) + # to not call self.plugin_0045.leave_room(0, 1) here, we are testing the trigger with a wrong profile + self.plugin.user_left_trigger( room, User(user_nick, Const.JID[1]), Const.PROFILE[1] ) # not the referee self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) - room = self.plugin_0045.getRoom(0, 0) - user_nick = self.plugin_0045.leaveRoom(0, 1) - self.plugin.userLeftTrigger( + room = self.plugin_0045.get_room(0, 0) + user_nick = self.plugin_0045.leave_room(0, 1) + self.plugin.user_left_trigger( room, User(user_nick, Const.JID[1]), PROFILE ) # referee nicks.pop() self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) # all the users join - user_nick = self.plugin_0045.joinRoom(0, 1) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[1]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 1) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[1]), PROFILE) nicks.append(user_nick) - user_nick = self.plugin_0045.joinRoom(0, 3) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 3) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE) nicks.append(user_nick) - user_nick = self.plugin_0045.joinRoom(0, 4) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 4) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE) nicks.append(user_nick) self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) # one user leaves - user_nick = self.plugin_0045.leaveRoom(0, 4) - self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[4]), PROFILE) + user_nick = self.plugin_0045.leave_room(0, 4) + self.plugin.user_left_trigger(room, User(user_nick, Const.JID[4]), PROFILE) nicks.pop() self.assertEqual( self.plugin.invitations[ROOM_JID][0][1], [Const.JID[4].userhostJID()] ) # another leaves - user_nick = self.plugin_0045.leaveRoom(0, 3) - self.plugin.userLeftTrigger(room, User(user_nick, Const.JID[3]), PROFILE) + user_nick = self.plugin_0045.leave_room(0, 3) + self.plugin.user_left_trigger(room, User(user_nick, Const.JID[3]), PROFILE) nicks.pop() self.assertEqual( self.plugin.invitations[ROOM_JID][0][1], @@ -562,64 +562,64 @@ ) # they can join again - user_nick = self.plugin_0045.joinRoom(0, 3) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[3]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 3) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[3]), PROFILE) nicks.append(user_nick) - user_nick = self.plugin_0045.joinRoom(0, 4) - self.plugin.userJoinedTrigger(room, User(user_nick, Const.JID[4]), PROFILE) + user_nick = self.plugin_0045.join_room(0, 4) + self.plugin.user_joined_trigger(room, User(user_nick, Const.JID[4]), PROFILE) nicks.append(user_nick) self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) self.assertTrue(len(self.plugin.invitations[ROOM_JID]) == 0) - def test__checkCreateGameAndInit(self): + def test_check_create_game_and_init(self): self.reinit() - helpers.muteLogging() + helpers.mute_logging() self.assertEqual( - (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (False, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) - helpers.unmuteLogging() + helpers.unmute_logging() - nick = self.plugin_0045.joinRoom(0, 0) + nick = self.plugin_0045.join_room(0, 0) self.assertEqual( - (True, False), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (True, False), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) - self.assertTrue(self.plugin._gameExists(ROOM_JID, False)) - self.assertFalse(self.plugin._gameExists(ROOM_JID, True)) - self.assertTrue(self.plugin.isReferee(ROOM_JID, nick)) + self.assertTrue(self.plugin._game_exists(ROOM_JID, False)) + self.assertFalse(self.plugin._game_exists(ROOM_JID, True)) + self.assertTrue(self.plugin.is_referee(ROOM_JID, nick)) - helpers.muteLogging() + helpers.mute_logging() self.assertEqual( - (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) + (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE) ) - helpers.unmuteLogging() + helpers.unmute_logging() - self.plugin_0045.joinRoom(0, 1) + self.plugin_0045.join_room(0, 1) self.assertEqual( - (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) + (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE) ) - self.plugin.createGame(ROOM_JID, [Const.JID[1]], PROFILE) + self.plugin.create_game(ROOM_JID, [Const.JID[1]], PROFILE) self.assertEqual( - (False, True), self.plugin._checkCreateGameAndInit(ROOM_JID, PROFILE) + (False, True), self.plugin._check_create_game_and_init(ROOM_JID, PROFILE) ) self.assertEqual( - (False, False), self.plugin._checkCreateGameAndInit(ROOM_JID, OTHER_PROFILE) + (False, False), self.plugin._check_create_game_and_init(ROOM_JID, OTHER_PROFILE) ) - def test_createGame(self): + def test_create_game(self): self.reinit(player_init={"xxx": "xyz"}) nicks = [] for i in [0, 1, 3, 4]: - nicks.append(self.plugin_0045.joinRoom(0, i)) + nicks.append(self.plugin_0045.join_room(0, i)) # game not exists - self.plugin.createGame(ROOM_JID, nicks, PROFILE) - self.assertTrue(self.plugin._gameExists(ROOM_JID, True)) + self.plugin.create_game(ROOM_JID, nicks, PROFILE) + self.assertTrue(self.plugin._game_exists(ROOM_JID, True)) self.assertEqual(self.plugin.games[ROOM_JID]["players"], nicks) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "started", nicks), ) for nick in nicks: self.assertEqual("init", self.plugin.games[ROOM_JID]["status"][nick]) @@ -635,20 +635,20 @@ # game exists, current profile is referee self.reinit(player_init={"xxx": "xyz"}) - self.initGame(0, 0) + self.init_game(0, 0) self.plugin.games[ROOM_JID]["started"] = True - self.plugin.createGame(ROOM_JID, nicks, PROFILE) + self.plugin.create_game(ROOM_JID, nicks, PROFILE) self.assertEqual( - self.host.getSentMessageXml(0), - self._expectedMessage(ROOM_JID, "groupchat", "started", nicks), + self.host.get_sent_message_xml(0), + self._expected_message(ROOM_JID, "groupchat", "started", nicks), ) # game exists, current profile is not referee self.reinit(player_init={"xxx": "xyz"}) - self.initGame(0, 0) + self.init_game(0, 0) self.plugin.games[ROOM_JID]["started"] = True - self.plugin_0045.joinRoom(0, 1) - self.plugin.createGame(ROOM_JID, nicks, OTHER_PROFILE) + self.plugin_0045.join_room(0, 1) + self.plugin.create_game(ROOM_JID, nicks, OTHER_PROFILE) self.assertEqual( - self.host.getSentMessage(0), None + self.host.get_sent_message(0), None ) # no sync message has been sent by other_profile