class Admin_functional_test(B3TestCase):
    """ tests from a class inherithing from Admin_functional_test must call self.init() """

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.p = AdminPlugin(self.console, self.conf)

    def init(self, config_content=None):
        """ optionally specify a config for the plugin. If called with no parameter, then the default config is loaded """
        if config_content is None:
            if not os.path.isfile(ADMIN_CONFIG_FILE):
                B3TestCase.tearDown(self)  # we are skipping the test at a late stage after setUp was called
                raise unittest.SkipTest("%s is not a file" % ADMIN_CONFIG_FILE)
            else:
                self.conf.load(ADMIN_CONFIG_FILE)
        else:
            self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=TEAM_RED)
        self.mike = FakeClient(
            self.console, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=TEAM_BLUE
        )
class Admin_functional_test(B3TestCase):
    """ tests from a class inherithing from Admin_functional_test must call self.init() """
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.p = AdminPlugin(self.console, self.conf)

    def init(self, config_content=None):
        """ optionally specify a config for the plugin. If called with no parameter, then the default config is loaded """
        if config_content is None:
            if not os.path.isfile(ADMIN_CONFIG_FILE):
                B3TestCase.tearDown(
                    self
                )  # we are skipping the test at a late stage after setUp was called
                raise unittest.SkipTest("%s is not a file" % ADMIN_CONFIG_FILE)
            else:
                self.conf.load(ADMIN_CONFIG_FILE)
        else:
            self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console,
                              name="Joe",
                              exactName="Joe",
                              guid="joeguid",
                              groupBits=128,
                              team=TEAM_RED)
        self.mike = FakeClient(self.console,
                               name="Mike",
                               exactName="Mike",
                               guid="mikeguid",
                               groupBits=1,
                               team=TEAM_BLUE)
Example #3
0
    def setUp(self):
        BF3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.loadFromString("""
                <configuration>
                </configuration>
            """)
        self.console = Bf3Parser(self.conf)

        from b3 import __file__ as b3_module__file__
        admin_config_file = os.path.normpath(os.path.join(os.path.dirname(b3_module__file__), "conf/plugin_admin.xml"))
        admin_config = XmlConfigParser()
        admin_config.load(admin_config_file)
        self.adminPlugin = AdminPlugin(self.console, admin_config)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # monkeypatch the admin plugin
        self.console.patch_b3_admin_plugin()

        self.changeMap_patcher = patch.object(self.console, "changeMap")
        self.changeMap_mock = self.changeMap_patcher.start()

        self.player = FakeClient(self.console, name="Player1", guid="Player1GUID", groupBits=128)
        self.player.connects("p1")

        # GIVEN
        self.console.game.gameType = 'ConquestLarge0'
        when(self.console).write(('mapList.list', 0)).thenReturn(['4', '3', 'MP_001', 'RushLarge0', '1', 'MP_003',
                                                                  'ConquestSmall0', '2', 'XP5_001', 'ConquestSmall0',
                                                                  '2', 'MP_007', 'SquadDeathMatch0', '3'])
        when(self.console).write(('mapList.getMapIndices',)).thenReturn(['0', '0'])
Example #4
0
class Admin_TestCase(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.load(ADMIN_CONFIG_FILE)
        self.p = AdminPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()
class Admin_functional_test(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.conf.load(ADMIN_CONFIG_FILE)
        self.p = AdminPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=TEAM_RED)
        self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=TEAM_BLUE)
Example #6
0
def setUpModule():
    global default_plugin_content, default_plugin_file, ADMIN_CONFIG, ADMIN_CONFIG_FILE, timer_patcher, feedparser_patcher
    if os.path.exists(default_plugin_file):
        with open(default_plugin_file, 'r') as f:
            default_plugin_content = f.read()

    ADMIN_CONFIG = XmlConfigParser()
    ADMIN_CONFIG.load(ADMIN_CONFIG_FILE)

    timer_patcher = patch('threading.Timer')
    timer_patcher.start()

    feedparser_patcher = patch.object(feedparser, 'parse')
    feedparser_patcher.start()
Example #7
0
    def setUp(self):
        self.status_response = None # defaults to STATUS_RESPONSE module attribute
        self.conf = XmlConfigParser()
        self.conf.loadFromString("""<configuration></configuration>""")
        self.parser = RavagedParser(self.conf)
        self.parser.output = Mock()
        self.parser.output.write = Mock()

        ADMIN_CONFIG = XmlConfigParser()
        ADMIN_CONFIG.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.parser, ADMIN_CONFIG)
        when(self.parser).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.parser.startup()
    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True
Example #9
0
    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True
Example #10
0
class Test_Tk_default_config(B3TestCase):
    def setUp(self):
        super(Test_Tk_default_config, self).setUp()
        b3.console.gameName = "f00"
        self.conf = XmlConfigParser()
        self.conf.load(default_plugin_file)
        self.p = TkPlugin(b3.console, self.conf)
        self.p.onLoadConfig()

    def test(self):
        self.assertEqual("sfire", self.p._issue_warning)
        self.assertEqual(7, self.p._round_grace)
        self.assertEqual(40, self.p._maxLevel)
        self.assertEqual(400, self.p._maxPoints)
        self.assertEqual(
            {0: (2.0, 1.0, 2), 1: (2.0, 1.0, 2), 2: (1.0, 0.5, 1), 20: (1.0, 0.5, 0), 40: (0.75, 0.5, 0)},
            self.p._levels,
        )
        self.assertTrue(self.p._private_messages)
Example #11
0
class Admin_TestCase(B3TestCase):
    """ tests from a class inherithing from Admin_TestCase must call self.init() """
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.p = AdminPlugin(self.console, self.conf)

    def init(self, config_content=None):
        """ optionally specify a config for the plugin. If called with no parameter, then the default config is loaded """
        if config_content is None:
            if not os.path.isfile(ADMIN_CONFIG_FILE):
                B3TestCase.tearDown(self) # we are skipping the test at a late stage after setUp was called
                raise unittest.SkipTest("%s is not a file" % ADMIN_CONFIG_FILE)
            else:
                self.conf.load(ADMIN_CONFIG_FILE)
        else:
            self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
Example #12
0
class Admin_TestCase(B3TestCase):
    """ tests from a class inherithing from Admin_TestCase must call self.init() """
    def setUp(self):
        B3TestCase.setUp(self)
        self.conf = XmlConfigParser()
        self.p = AdminPlugin(self.console, self.conf)

    def init(self, config_content=None):
        """ optionally specify a config for the plugin. If called with no parameter, then the default config is loaded """
        if config_content is None:
            if not os.path.isfile(ADMIN_CONFIG_FILE):
                B3TestCase.tearDown(
                    self
                )  # we are skipping the test at a late stage after setUp was called
                raise unittest.SkipTest("%s is not a file" % ADMIN_CONFIG_FILE)
            else:
                self.conf.load(ADMIN_CONFIG_FILE)
        else:
            self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
Example #13
0
class LoginTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the censor plugin config """
    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True

    def tearDown(self):
        B3TestCase.tearDown(self)

    def init_plugin(self, config_content=None):
        self.conf = XmlConfigParser()
        if config_content:
            self.conf.setXml(config_content)
        else:
            self.conf.load(default_plugin_file)
        self.p = LoginPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info(
            "============================= Login plugin: loading config ============================"
        )
        self.p.onLoadConfig()
        self.log.info(
            "============================= Login plugin: starting  ================================="
        )
        self.p.onStartup()
Example #14
0
class Test_Tk_default_config(B3TestCase):
    def setUp(self):
        super(Test_Tk_default_config, self).setUp()
        b3.console.gameName = 'f00'
        self.conf = XmlConfigParser()
        self.conf.load(default_plugin_file)
        self.p = TkPlugin(b3.console, self.conf)
        self.p.onLoadConfig()

    def test(self):
        self.assertEqual("sfire", self.p._issue_warning)
        self.assertEqual(7, self.p._round_grace)
        self.assertEqual(40, self.p._maxLevel)
        self.assertEqual(400, self.p._maxPoints)
        self.assertEqual(
            {
                0: (2.0, 1.0, 2),
                1: (2.0, 1.0, 2),
                2: (1.0, 0.5, 1),
                20: (1.0, 0.5, 0),
                40: (0.75, 0.5, 0)
            }, self.p._levels)
        self.assertTrue(self.p._private_messages)
Example #15
0
class LoginTestCase(B3TestCase):
    """ Ease testcases that need an working B3 console and need to control the censor plugin config """

    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)

        admin_conf = XmlConfigParser()
        admin_conf.load(ADMIN_CONFIG_FILE)
        self.adminPlugin = AdminPlugin(self.console, admin_conf)
        when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
        self.adminPlugin.onLoadConfig()
        self.adminPlugin.onStartup()

        self.console.gameName = "theGame"
        self.console.startup()
        self.log.propagate = True


    def tearDown(self):
        B3TestCase.tearDown(self)

    def init_plugin(self, config_content=None):
        self.conf = XmlConfigParser()
        if config_content:
            self.conf.setXml(config_content)
        else:
            self.conf.load(default_plugin_file)
        self.p = LoginPlugin(self.console, self.conf)

        self.log.setLevel(logging.DEBUG)
        self.log.info("============================= Login plugin: loading config ============================")
        self.p.onLoadConfig()
        self.log.info("============================= Login plugin: starting  =================================")
        self.p.onStartup()
            self._maps_parsed = True
            self.info('There was at least one error opening your map files many/few %s/%s' % (self._maps_load_error['many'], self._maps_load_error['few']))
################################################################################################################
#
# Debuging, Testing
#
################################################################################################################


if __name__ == '__main__':
    from b3.config import XmlConfigParser
    from b3.fake import fakeConsole
    from b3.fake import joe, simon, moderator, superadmin, reg, admin
    import time
    config = XmlConfigParser() 
    config.load('conf/plugin_autofillbf3.xml.test')
    event_start = type('lamdbaobject', (object,), {'type' :  b3.events.EVT_GAME_ROUND_START})()
    event_end = type('lamdbaobject', (object,), {'type' :  b3.events.EVT_GAME_ROUND_END})()
    event_join = type('lamdbaobject', (object,), {'type' :  b3.events.EVT_CLIENT_JOIN})()
    event_leave = type('lamdbaobject', (object,), {'type' :  b3.events.EVT_CLIENT_DISCONNECT})()
    p = Autofillbf3Plugin(fakeConsole, config)
    p.console.setCvar('maxPlayers', 18)
    p.onStartup()
    p.onLoadConfig()
    """  Adjust slot size
    
    p.onEvent(event_start)
    joe.connects(cid = 1)
    p.onEvent(event_join)
    simon.connects(cid = 2)
    p.onEvent(event_join)
class Test_Config(B3TestCase):

    def setUp(self):
        self.log = logging.getLogger('output')
        self.log.propagate = False

        B3TestCase.setUp(self)
        self.console.startup()
        self.log.propagate = True
        self.log.setLevel(logging.DEBUG)

        self.conf = XmlConfigParser()
        self.p = ChatloggerPlugin(self.console, self.conf)

        when(self.console.config).get('b3', 'time_zone').thenReturn('GMT')
        when(b3).getB3Path().thenReturn("c:\\b3_folder")
        when(b3).getConfPath().thenReturn("c:\\b3_conf_folder")
        self.p.setup_fileLogger = Mock()


    def init(self, config_content=None):
        """ load plugin config and initialise the plugin """
        if config_content:
            self.conf.loadFromString(config_content)
        else:
            if os.path.isfile(CHATLOGGER_CONFIG_FILE):
                self.conf.load(CHATLOGGER_CONFIG_FILE)
            else:
                unittest.skip("default config file '%s' does not exists" % CHATLOGGER_CONFIG_FILE)
                return
        self.p.onLoadConfig()
        self.p.onStartup()


    def test_default_config(self):
        self.init()
        self.assertTrue(self.p._save2db)
        self.assertTrue(self.p._save2file)
        expected_log_file = 'c:\\b3_conf_folder\\chat.log' if sys.platform == 'win32' else 'c:\\b3_conf_folder/chat.log'
        self.assertEqual(expected_log_file, self.p._file_name)
        self.assertEqual("D", self.p._file_rotation_rate)
        self.assertEqual(0, self.p._max_age_in_days)
        self.assertEqual(0, self.p._max_age_cmd_in_days)
        self.assertEqual(0, self.p._hours)
        self.assertEqual(0, self.p._minutes)


    def test_empty_config(self):
        self.init("""<configuration plugin="chatlogger" />""")
        self.assertTrue(self.p._save2db)
        self.assertFalse(self.p._save2file)
        self.assertIsNone(self.p._file_name)
        self.assertIsNone(self.p._file_rotation_rate)
        self.assertEqual(0, self.p._max_age_in_days)
        self.assertEqual(0, self.p._max_age_cmd_in_days)
        self.assertEqual(0, self.p._hours)
        self.assertEqual(0, self.p._minutes)


    def test_conf1(self):
        self.init("""
            <configuration plugin="chatlogger">
                <settings name="purge">
                    <set name="max_age">7d</set>
                    <set name="hour">4</set>
                    <set name="min">0</set>
                </settings>
            </configuration>
        """)
        self.assertTrue(self.p._save2db)
        self.assertFalse(self.p._save2file)
        self.assertIsNone(self.p._file_name)
        self.assertIsNone(self.p._file_rotation_rate)
        self.assertEqual(7, self.p._max_age_in_days)
        self.assertEqual(0, self.p._max_age_cmd_in_days)
        self.assertEqual(4, self.p._hours)
        self.assertEqual(0, self.p._minutes)