def setUp(self):
        super(Test_autoassign, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[preferences]
no_autoassign_level: 20
autoassign: On
team_swap_threshold: 2
        """)
        with logging_disabled():
            self.p = Poweradminbf4Plugin(self.console, self.conf)
            self.p.onLoadConfig()
            self.p.onStartup()
        self.assertTrue(self.p._autoassign)
        self.assertEqual(20, self.p._no_autoassign_level)

        def my_write(data):
            if data[0] == 'admin.movePlayer':
                self.console.routeFrostbitePacket(
                    ['player.onTeamChange', data[1], data[2], data[3]])
                return ['OK']
            else:
                return Mock()

        self.write_patcher = patch.object(self.console,
                                          "write",
                                          side_effect=my_write)
        self.write_mock = self.write_patcher.start()
Ejemplo n.º 2
0
 def setUp(self):
     self.available_names = [
         "hardcore", "normal", "infantry", "tdm", "conquest", "rush",
         "quickmatch", "hardcore-tdm", "hardcore-conquest"
     ]
     self.console = Mock()
     self.p = Poweradminbf4Plugin(self.console)
     self.p._list_available_server_config_files = lambda: self.available_names
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vehicles: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
    def assert_config_value(self, expected, conf_value):
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[preferences]
team_swap_threshold: %s
                    """ % conf_value)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.assertEqual(expected, self.p._team_swap_threshold)
Ejemplo n.º 5
0
    def setUp(self):
        super(Test_cmd_vipadd, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vipadd: 0
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
    def test_yell_duration_empty(self):
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[preferences]
yell_duration:
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.assertEqual(10, self.p._yell_duration)
Ejemplo n.º 7
0
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
roundrestart: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
        self.superadmin.connects('superadmin')
Ejemplo n.º 8
0
 def setUp(self):
     Bf4TestCase.setUp(self)
     self.conf = CfgConfigParser()
     with logging_disabled():
         self.p = Poweradminbf4Plugin(self.console, self.conf)
     when(self.console).write(
         ('vars.roundStartPlayerCount', )).thenReturn(['0'])
     self.scrambleTeams_mock = self.p._scrambler.scrambleTeams = Mock(
         name="scrambleTeams", wraps=self.p._scrambler.scrambleTeams)
     self.scrambleTeams_mock.reset_mock()
Ejemplo n.º 9
0
    def test_1(self):
        """nothing in config, no plugin config file, no b3 config file"""
        self.conf.loadFromString("""
[preferences]

        """)
        # the plugin config does not exist on the filesystem
        p = Poweradminbf4Plugin(self.console, self.conf)
        p.onLoadConfig()
        self.assertIsNone(p._configPath)
Ejemplo n.º 10
0
    def test_3(self):
        """junk in config, no plugin config file, no b3 config file"""
        self.conf.loadFromString("""
[preferences]
config_path: I don't exists
        """)

        p = Poweradminbf4Plugin(self.console, self.conf)
        p.onLoadConfig()
        self.assertIsNone(p._configPath)
    def setUp(self):
        super(Test_cmd_unlockmode, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
unlockmode: 40
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
        when(self.console).write()
Ejemplo n.º 12
0
    def setUp(self):
        super(Test_cmd_autobalance, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[commands]
autobalance: mod
""")
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
        self.p.console._cron = Mock()
Ejemplo n.º 13
0
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
vipsave: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.moderator.connects("moderator")
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
scramblemode: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
        self.p._scrambler = Mock()
        self.superadmin.connects('superadmin')
        self.superadmin.clearMessageHistory()
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
yell: 20

[preferences]
yell_duration: 2
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
    def setUp(self):
        super(Test_issue_14, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[commands]
changeteam: guest
[preferences]
no_level_check_level: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
    def setUp(self):
        super(Test_cmd_idle, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
idle: 40
        """)
        with logging_disabled():
            self.p = Poweradminbf4Plugin(self.console, self.conf)
            self.p.onLoadConfig()
            self.p.onStartup()

        self.p.error = Mock(wraps=self.p.error)
        logging.getLogger('output').setLevel(logging.DEBUG)
    def setUp(self):
        super(Test_cmd_setnextmap, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
setnextmap-snmap: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        logging.getLogger('output').setLevel(logging.DEBUG)
        self.console.game.gameType = 'ConquestSmall0'
        self.console.game.serverinfo = {'roundsTotal': 2}
Ejemplo n.º 19
0
    def test_4(self):
        """absolute existing path in config file"""
        self.conf.loadFromString("""
[preferences]
config_path: /somewhere/on/the/filesystem/
        """)
        p = Poweradminbf4Plugin(self.console, self.conf)

        self.setExistingPaths(['/somewhere/on/the/filesystem/'])
        with patch.object(os.path, 'isdir',
                          Mock(side_effect=Test_server_config_path.isdir)):
            p.onLoadConfig()

        self.assertEqual(os.path.normpath('/somewhere/on/the/filesystem/'),
                         p._configPath)
Ejemplo n.º 20
0
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
viplist: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.console.say = Mock()
        self.console.saybig = Mock()

        self.moderator.connects("moderator")

        self.joe.connects('joe')
        self.joe.teamId = 2
Ejemplo n.º 21
0
    def test_2bis(self):
        """nothing in config, plugin config file, no b3 config file"""
        self.conf.loadFromString("""
[preferences]

        """)
        self.conf.fileName = "somewhere/on/the/filesystem/plugin_poweradminbf4.ini"

        p = Poweradminbf4Plugin(self.console, self.conf)

        self.setExistingPaths(["somewhere/on/the/filesystem//serverconfigs"])
        with patch.object(os.path, 'isdir',
                          Mock(side_effect=Test_server_config_path.isdir)):
            p.onLoadConfig()

        self.assertEqual(
            os.path.normpath("somewhere/on/the/filesystem//serverconfigs"),
            p._configPath)
Ejemplo n.º 22
0
    def test_6(self):
        """existing path in config file relative to plugin config directory"""
        self.conf.loadFromString("""
[preferences]
config_path: subdirectory
        """)
        self.conf.fileName = "somewhere/on/the/filesystem/plugin_poweradminbf4.ini"

        p = Poweradminbf4Plugin(self.console, self.conf)

        self.setExistingPaths(["somewhere/on/the/filesystem/subdirectory"])
        with patch.object(os.path, 'isdir',
                          Mock(side_effect=Test_server_config_path.isdir)):
            p.onLoadConfig()

        self.assertEqual(
            os.path.normpath('somewhere/on/the/filesystem/subdirectory'),
            p._configPath)
Ejemplo n.º 23
0
    def setUp(self):
        super(Test_cmd_listconfig, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString(
            """[commands]
listconfig: 40

[preferences]
config_path: %(script_dir)s
            """ % {
                'script_dir':
                os.path.abspath(
                    os.path.join(os.path.dirname(__file__),
                                 '../extplugins/conf/serverconfigs'))
            })
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
        self.admin.connects("admin")
        self.admin.clearMessageHistory()
Ejemplo n.º 24
0
    def test_5(self):
        """existing path in config file relative to b3 config directory"""
        self.conf.loadFromString("""
[preferences]
config_path: subdirectory
        """)
        p = Poweradminbf4Plugin(self.console, self.conf)
        # make B3 think it has a config file on the filesystem
        p.console.config.fileName = "somewhere/on/the/filesystem/b3conf/b3.xml"

        self.setExistingPaths(
            ['somewhere/on/the/filesystem/b3conf/subdirectory'])
        with patch.object(os.path, 'isdir',
                          Mock(side_effect=Test_server_config_path.isdir)):
            p.onLoadConfig()

        self.assertEqual(
            os.path.normpath(
                'somewhere/on/the/filesystem/b3conf/subdirectory'),
            p._configPath)
    def setUp(self):
        super(Test_cmd_changeteam, self).setUp()
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""
[commands]
changeteam: mod
        """)
        with logging_disabled():
            self.p = Poweradminbf4Plugin(self.console, self.conf)
            self.p.onLoadConfig()
            self.p.onStartup()

        def my_write(data):
            if data[0] == 'admin.movePlayer':
                self.console.routeFrostbitePacket(['player.onTeamChange', data[1], data[2], data[3]])
                return ['OK']
            else:
                return Mock()

        self.write_patcher = patch.object(self.console, "write", side_effect=my_write)
        self.write_mock = self.write_patcher.start()
Ejemplo n.º 26
0
    def test_2(self):
        """nothing in config, no plugin config file, b3 config file"""
        self.conf.loadFromString("""
[preferences]

        """)
        # the plugin config does not exist on the filesystem

        p = Poweradminbf4Plugin(self.console, self.conf)
        # make B3 think it has a config file on the filesystem
        p.console.config.fileName = "somewhere/on/the/filesystem/b3conf/b3.xml"

        self.setExistingPaths(
            ["somewhere/on/the/filesystem/b3conf/serverconfigs"])
        with patch.object(os.path, 'isdir',
                          Mock(side_effect=Test_server_config_path.isdir)):
            p.onLoadConfig()

        self.assertEqual(
            os.path.normpath(
                "somewhere/on/the/filesystem/b3conf/serverconfigs"),
            p._configPath)
    def setUp(self):
        Bf4TestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.conf.loadFromString("""[commands]
nuke: 20
        """)
        self.p = Poweradminbf4Plugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.sleep_patcher = patch.object(time, 'sleep')
        self.sleep_patcher.start()

        self.console.write = Mock()
        self.console.say = Mock()
        self.console.saybig = Mock()

        self.moderator.connects("moderator")
        self.moderator.teamId = 1

        self.joe.connects('joe')
        self.joe.teamId = 2
Ejemplo n.º 28
0
 def setUp(self):
     self.console = Mock()
     self.p = Poweradminbf4Plugin(self.console)
 def test_default_value(self):
     self.conf = CfgConfigParser()
     self.conf.loadFromString("""[foo]""")
     self.p = Poweradminbf4Plugin(self.console, self.conf)
     self.p.onLoadConfig()
     self.assertEqual(self.default_value, self.p._team_swap_threshold)
Ejemplo n.º 30
0
 def setUp(self):
     Bf4TestCase.setUp(self)
     self.conf = CfgConfigParser()
     self.p = Poweradminbf4Plugin(self.console, self.conf)
     logger = logging.getLogger('output')
     logger.setLevel(logging.INFO)