Beispiel #1
0
    def test_forgive(self, timer_patch):
        from b3.fake import superadmin
        superadmin.connects(99)

        Tk_functional_test.p._round_grace = 0
        joe = FakeClient(fakeConsole,
                         name="Joe",
                         exactName="Joe",
                         guid="joeguid",
                         groupBits=1,
                         team=b3.TEAM_RED)
        mike = FakeClient(fakeConsole,
                          name="Mike",
                          exactName="Mike",
                          guid="mikeguid",
                          groupBits=1,
                          team=b3.TEAM_RED)

        joe.warn = Mock()
        joe.connects(0)
        mike.connects(1)

        joe.kills(mike)

        superadmin.message_history = []
        superadmin.says("!forgiveinfo joe")
        self.assertIn("Joe has 200 TK points", superadmin.message_history[0])

        mike.says("!forgive")

        superadmin.message_history = []
        superadmin.says("!forgiveinfo joe")
        self.assertIn("Joe has 0 TK points", superadmin.message_history[0])
Beispiel #2
0
 def test_cmdrevoke_with_client_reconnection(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       id="10",
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdgrant mike cmdlevel")
     superadmin.says("!cmdrevoke mike cmdlevel")
     mike.disconnects()
     del mike  # totally destroy the object
     mike = FakeClient(self.console,
                       id="10",
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # THEN
     grantlist = getattr(mike, GRANT_SET_ATTR, None)
     self.assertIsNotNone(grantlist)
     self.assertIsInstance(grantlist, set)
     self.assertEqual(0, len(grantlist))
Beispiel #3
0
    def test_map(self):
        # GIVEN
        when(self.parser.output).write("getmaplist false").thenReturn(
            u"""0 CTR_Bridge
1 CTR_Canyon
2 CTR_Derelict
3 CTR_IceBreaker
4 CTR_Liberty
5 CTR_Rooftop
6 Thrust_Bridge
7 Thrust_Canyon
8 Thrust_Chasm
9 Thrust_IceBreaker
10 Thrust_Liberty
11 Thrust_Oilrig
12 Thrust_Rooftop
""".encode('UTF-8'))
        admin = FakeClient(console=self.parser,
                           name="admin",
                           guid="guid_admin",
                           groupBits=128)
        admin.connects("guid_admin")
        # WHEN
        with patch.object(self.parser.output,
                          'write',
                          wraps=self.parser.output.write) as write_mock:
            admin.says("!map chasm")
        # THEN
        write_mock.assert_has_calls(
            [call("addmap Thrust_Chasm 1"),
             call("nextmap")])
Beispiel #4
0
 def testPlugin1():
     jack = FakeClient(fakeConsole,
                       name="Jack",
                       guid="qsd654sqf",
                       _maxLevel=0)
     jack.connects(0)
     jack.says('!makeroom')
    def test_cmd_plugin_unload_successful(self):
        # GIVEN

        ###### MOCK PLUGIN
        mock_plugin = Mock(spec=Plugin)
        mock_plugin.console = self.console
        mock_plugin.isEnabled = Mock(return_value=False)
        when(self.console).getPlugin("mock").thenReturn(mock_plugin)
        self.console._plugins['mock'] = mock_plugin
        ###### MOCK COMMAND
        mock_func = Mock()
        mock_func.__name__ = 'cmd_mockfunc'
        self.adminPlugin._commands['mockcommand'] = Command(plugin=mock_plugin, cmd='mockcommand', level=100, func=mock_func)
        ###### MOCK EVENT
        mock_plugin.onSay = Mock()
        mock_plugin.registerEvent('EVT_CLIENT_SAY', mock_plugin.onSay)
        ###### MOCK CRON
        mock_plugin.mockCronjob = Mock()
        mock_plugin.mockCrontab = b3.cron.PluginCronTab(mock_plugin, mock_plugin.mockCronjob, minute='*', second= '*/60')
        self.console.cron.add(mock_plugin.mockCrontab)
        self.assertIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)

        superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
        superadmin.connects("1")
        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!plugin unload mock")
        # THEN
        self.assertNotIn('mockcommand', self.adminPlugin._commands)
        self.assertIn(self.console.getEventID('EVT_CLIENT_SAY'), self.console._handlers)
        self.assertNotIn(mock_plugin, self.console._handlers[self.console.getEventID('EVT_CLIENT_SAY')])
        self.assertNotIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)
        self.assertListEqual(['Plugin mock has been unloaded'], superadmin.message_history)
 def test_map_with_correct_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.parser, name="superadmin", guid="guid_superadmin", groupBits=128, team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map market push")
     # THEN
     self.parser.output.write.assert_has_calls([call('changelevel market push')])
class Test_commands(CustomcommandsTestCase):

    def setUp(self):
        CustomcommandsTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.p = CustomcommandsPlugin(self.console, self.conf)
        with logging_disabled():
            from b3.fake import FakeClient
        self.guest = FakeClient(console=self.console, name="Guest", guid="GuestGUID", pbid="GuestPBID", group_bits=0)
        self.user = FakeClient(console=self.console, name="User", guid="UserGUID", pbid="UserPBID", group_bits=1)
        self.regular = FakeClient(console=self.console, name="Regular", guid="RegularGUID", pbid="RegularPBID", group_bits=2)
        self.mod = FakeClient(console=self.console, name="Moderator", guid="ModeratorGUID", pbid="ModeratorPBID", group_bits=8)
        self.admin = FakeClient(console=self.console, name="Admin", guid="AdminGUID", pbid="AdminPBID", group_bits=16)
        self.fulladmin = FakeClient(console=self.console, name="FullAdmin", guid="FullAdminGUID", pbid="FullAdminPBID", group_bits=32)
        self.senioradmin = FakeClient(console=self.console, name="SeniorAdmin", guid="SeniorAdminGUID", pbid="SeniorAdminPBID", group_bits=64)
        self.superadmin = FakeClient(console=self.console, name="SuperAdmin", guid="SuperAdminGUID", pbid="SuperAdminPBID", group_bits=128)

    def test_guest(self):
        # GIVEN
        self.conf.loadFromString("""
[guest commands]
# define in this section commands that will be available to all players
f00 = f00 rcon command
        """)
        # WHEN
        self.p.onLoadConfig()
        self.p.onStartup()
        # THEN
        self.assertIn("f00", self.p._adminPlugin._commands)
        # WHEN
        self.guest.connects(cid="guestCID")
        with patch.object(self.console, "write") as write_mock:
            self.guest.says("!f00")
        # THEN
        self.assertListEqual([call("f00 rcon command")], write_mock.mock_calls)
        self.assertListEqual([], self.guest.message_history)

    def test_user(self):
        # GIVEN
        self.console.getPlugin('admin')._warn_command_abusers = True
        self.conf.loadFromString("""
[user commands]
# define in this section commands that will be available to all players
f00 = f00 rcon command
        """)
        self.p.onLoadConfig()
        self.p.onStartup()
        # WHEN
        self.guest.connects(cid="guestCID")
        with patch.object(self.console, "write") as write_mock:
            self.guest.says("!f00")
        # THEN
        self.assertEqual(1, len(self.guest.message_history))
        self.assertIn(self.guest.message_history[0], [
            'You do not have sufficient access to use !f00',
            'You need to be in group User to use !f00'
        ])
        self.assertListEqual([], write_mock.mock_calls)
 def test_cmdalias_no_parameter_no_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias register")
     # THEN
     self.assertListEqual(['command register has not alias set'], superadmin.message_history)
 def test_cmdalias_no_parameter_no_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias register")
     # THEN
     self.assertListEqual(['command register has not alias set'], superadmin.message_history)
 def test_cmd_plugin_enable_with_invalid_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable fake")
     # THEN
     self.assertListEqual(['Plugin fake is not loaded'], superadmin.message_history)
 def test_cmd_plugin_load_with_invalid_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin load fake")
     # THEN
     self.assertListEqual(['Missing fake plugin python module', 'Please put the plugin module in @b3/extplugins/'], superadmin.message_history)
 def test_cmd_plugin_enable_protected(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable admin")
     # THEN
     self.assertListEqual(['Plugin admin is protected'], superadmin.message_history)
 def test_cmdlevel_no_parameter_no_access(self):
     # GIVEN
     mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=32)
     mike.connects("1")
     # WHEN
     mike.clearMessageHistory()
     mike.says("!cmdlevel die")
     # THEN
     self.assertListEqual(['no sufficient access to die command'], mike.message_history)
 def test_cmdlevel_invalid_command(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel fakecommand")
     # THEN
     self.assertListEqual(['could not find command fakecommand'], superadmin.message_history)
 def test_cmdlevel_no_parameter(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help")
     # THEN
     self.assertListEqual(['command help level: guest'], superadmin.message_history)
 def test_cmdlevel_no_parameter_no_access(self):
     # GIVEN
     mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=32)
     mike.connects("1")
     # WHEN
     mike.clearMessageHistory()
     mike.says("!cmdlevel die")
     # THEN
     self.assertListEqual(['no sufficient access to die command'], mike.message_history)
 def test_cmd_plugin_enable_with_no_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable")
     # THEN
     self.assertListEqual(['usage: !plugin enable <name/s>'], superadmin.message_history)
 def test_cmd_plugin_with_invalid_command_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin fake")
     # THEN
     self.assertListEqual(['usage: !plugin <disable|enable|info|list|load|unload> [<data>]'], superadmin.message_history)
 def test_cmd_plugin_list(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin list")
     # THEN
     self.assertListEqual(['Loaded plugins: admin, pluginmanager'], superadmin.message_history)
 def test_cmdlevel_invalid_command(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel fakecommand")
     # THEN
     self.assertListEqual(['could not find command fakecommand'], superadmin.message_history)
 def test_cmdlevel_no_parameter(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help")
     # THEN
     self.assertListEqual(['command help level: guest'], superadmin.message_history)
 def test_map_with_invalid_map_name(self):
     # GIVEN
     superadmin = FakeClient(self.parser, name="superadmin", guid="guid_superadmin", groupBits=128, team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map blargh blub")
     # THEN
     self.assertListEqual(["do you mean : buhriz, district, sinjar, siege, uprising, ministry, revolt, heights, "
                           "contact, peak, panj, market ?"], superadmin.message_history)
 def test_cmd_plugin_no_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin")
     # THEN
     self.assertListEqual(['invalid data, try !help plugin'], superadmin.message_history)
 def test_already_logged_in(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=128)
     joe.setvar(self.p, 'loggedin', 1)
     joe.connects("0")
     # WHEN
     joe.clearMessageHistory()
     joe.says("!login")
     # THEN
     self.assertEqual(['You are already logged in'], joe.message_history)
    def test_tempban_non_existing_player(self):
        joe = FakeClient(Admin_functional_test.fakeConsole, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=b3.TEAM_RED)
        mike = FakeClient(Admin_functional_test.fakeConsole, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=b3.TEAM_BLUE)

        joe.message = Mock()
        joe.connects(0)
        mike.connects(1)

        joe.says('!tempban foo 5h')
        joe.message.assert_called_with('^7No players found matching foo')
 def test_low_level(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=8)
     joe.connects("0")
     # WHEN
     joe.clearMessageHistory()
     joe.says("!login")
     # THEN
     self.assertEqual(['You do not need to log in'], joe.message_history)
     self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
Beispiel #27
0
 def test_low_level(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=8)
     joe.connects("0")
     # WHEN
     joe.clearMessageHistory()
     joe.says("!login")
     # THEN
     self.assertEqual(['You do not need to log in'], joe.message_history)
     self.assertFalse(self.jack.isvar(self.p, 'loggedin'))
    def test_tempban_no_duration(self):
        joe = FakeClient(Admin_functional_test.fakeConsole, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=b3.TEAM_RED)
        mike = FakeClient(Admin_functional_test.fakeConsole, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=b3.TEAM_BLUE)

        joe.message = Mock()
        joe.connects(0)
        mike.connects(1)

        joe.says('!tempban mike')
        joe.message.assert_called_with('^7Invalid parameters')
 def test_cmd_plugin_load_with_already_loaded_plugin(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin load mock")
     # THEN
     self.assertListEqual(['Plugin mock is already loaded'], superadmin.message_history)
 def test_cmdalias_update_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help newhelp")
     # THEN
     self.assertListEqual(['updated alias for command help: newhelp'], superadmin.message_history)
     self.assert_cmd_alias("help", "newhelp")
 def test_cmdlevel_double_minlevel_greater_than_maxlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fulladmin-admin")
     # THEN
     self.assertListEqual(['invalid level: fulladmin is greater than admin'], superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
 def test_cmdalias_already_in_use(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("ban", "b")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias ban tempban")
     # THEN
     self.assertListEqual(['command tempban is already in use'], superadmin.message_history)
     self.assert_cmd_alias("ban", "b")
 def test_cmdalias_update_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help newhelp")
     # THEN
     self.assertListEqual(['updated alias for command help: newhelp'], superadmin.message_history)
     self.assert_cmd_alias("help", "newhelp")
 def test_cmdlevel_double_valid_minlevel_maxlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help admin-senioradmin")
     # THEN
     self.assertListEqual(['command help level changed: admin-senioradmin'], superadmin.message_history)
     self.assert_cmd_groups("help", "^2admin^7-^2senioradmin")
 def test_cmdlevel_single_invalid_minlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fakegroup")
     # THEN
     self.assertListEqual(['invalid level specified: fakegroup'], superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
 def test_cmdalias_already_in_use(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("ban", "b")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias ban tempban")
     # THEN
     self.assertListEqual(['command tempban is already in use'], superadmin.message_history)
     self.assert_cmd_alias("ban", "b")
 def test_cmdalias_add_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("register", None)
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias register newregister")
     # THEN
     self.assertListEqual(['added alias for command register: newregister'], superadmin.message_history)
     self.assert_cmd_alias("register", "newregister")
    def test_cmdlevel_single_valid_minlevel(self):
        # GIVEN
        superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
        superadmin.connects("1")

        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!cmdlevel help admin")
        # THEN
        self.assertListEqual(['command help level changed: admin'], superadmin.message_history)
        self.assert_cmd_groups("help", "^2admin")
    def test_tempban_no_reason(self):
        joe = FakeClient(Admin_functional_test.fakeConsole, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=b3.TEAM_RED)
        mike = FakeClient(Admin_functional_test.fakeConsole, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=b3.TEAM_BLUE)

        joe.message = Mock()
        joe.connects(0)
        mike.connects(1)
        mike.tempban = Mock()

        joe.says('!tempban mike 5h')
        mike.tempban.assert_called_with('', None, 5*60, joe)
 def test_cmduse_access(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmduse mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has access to cmdlevel command'], superadmin.message_history)
 def test_cmdalias_invalid_alias_specified(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help !")
     # THEN
     self.assertListEqual(['invalid data, try !help cmdalias'], superadmin.message_history)
     self.assert_cmd_alias("help", "h")
 def test_cmdrevoke_with_no_grant_given(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has no grant for cmdlevel command'], superadmin.message_history)
 def test_cmdlevel_double_minlevel_greater_than_maxlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fulladmin-admin")
     # THEN
     self.assertListEqual(['invalid level: fulladmin is greater than admin'], superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
 def test_cmdalias_add_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("register", None)
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias register newregister")
     # THEN
     self.assertListEqual(['added alias for command register: newregister'], superadmin.message_history)
     self.assert_cmd_alias("register", "newregister")
 def test_cmdlevel_single_invalid_minlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fakegroup")
     # THEN
     self.assertListEqual(['invalid level specified: fakegroup'], superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
 def test_cmdalias_invalid_alias_specified(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help !")
     # THEN
     self.assertListEqual(['invalid data, try !help cmdalias'], superadmin.message_history)
     self.assert_cmd_alias("help", "h")
 def test_cmduse_access(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmduse mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has access to cmdlevel command'], superadmin.message_history)
 def test_cmdrevoke_with_no_grant_given(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has no grant for cmdlevel command'], superadmin.message_history)
 def test_cmd_plugin_enable_succeed(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     mock_plugin.isEnabled = Mock(return_value=False)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable mock")
     # THEN
     self.assertListEqual(['Plugin mock is now enabled'], superadmin.message_history)
 def test_cmd_plugin_disable_mixed_multiple(self):
     # GIVEN
     mock_pluginA = Mock(spec=Plugin)
     mock_pluginA.isEnabled = Mock(return_value=True)
     when(self.console).getPlugin("mock").thenReturn(mock_pluginA)
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin disable mock fake")
     # THEN
     self.assertListEqual(['Plugin mock is now disabled', 'Plugin fake is not loaded'], superadmin.message_history)
 def test_cmd_plugin_unload_with_enabled_plugin(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     mock_plugin.isEnabled = Mock(return_value=True)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin unload mock")
     # THEN
     self.assertListEqual(['Plugin mock is currently enabled: disable it first'], superadmin.message_history)