Ejemplo n.º 1
0
class CountryFilterTestCase(unittest2.TestCase):
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS',
                                 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()

        # create our plugin instance
        self.p = CountryfilterPlugin(self.console, CfgConfigParser())

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="MIKEGUID",
                               ip='1.2.3.4',
                               groupBits=0)
        self.bill = FakeClient(console=self.console,
                               name="Bill",
                               guid="BILLGUID",
                               ip='2.3.4.5',
                               groupBits=0)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL

    def tearDown(self):
        unstub()

    def init(self, config_content):
        """
        Initialize the plugin using the given configuration file content
        """
        self.p.config.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
Ejemplo n.º 2
0
    def setUp(self):
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(dedent(r""""""))
        self.console = FakeConsole(self.parser_conf)
        self.console.gameName = 'f00'
        self.console.startup()

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        self.evt_queue = []

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # prepare a few players
        self.mike = FakeClient(self.console,
                               name="Mike",
                               exactName="Mike",
                               guid="MIKEGUID",
                               groupBits=16,
                               ip='1.1.1.1')
        self.paul = FakeClient(self.console,
                               name="Paul",
                               exactName="Paul",
                               guid="PAULGUID",
                               groupBits=1,
                               ip='2.2.2.2')
        self.john = FakeClient(self.console,
                               name="John",
                               exactName="John",
                               guid="JOHNGUID",
                               groupBits=0,
                               ip='3.3.3.3')
        self.mary = FakeClient(self.console,
                               name="Mary",
                               exactName="Mary",
                               guid="MARYGUID",
                               groupBits=0,
                               ip='4.4.4.4')

        self.conf = CfgConfigParser()
        self.p = IpbanPlugin(self.console, self.conf)

        # return some mock data
        when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7'])
        when(self.p).getTempBanIps().thenReturn(
            ['3.3.3.3', '8.8.8.8', '9.9.9.9'])
Ejemplo n.º 3
0
class ServermonitorTestCase(TestCase):
    """
    TestCase suitable for testing the ServermonitorPlugin class
    """
    def setUp(self):
        # less logging
        self.logger = logging.getLogger('output')
        self.logger.setLevel(logging.ERROR)
        self.logger.propagate = False

        from b3.fake import FakeConsole, FakeClient

        # create a Fake parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(
            """<configuration><settings name="server"><set name="game_log"></set></settings></configuration>"""
        )
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        # load the admin plugin
        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           admin_plugin_conf_file)
            self.adminPlugin.onLoadConfig()
            self.adminPlugin._commands = {
            }  # work around known bug in the Admin plugin which makes the _command property shared between all instances
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # load our plugin
        self.conf = CfgConfigParser()
        self.p = ServermonitorPlugin(self.console, self.conf)

        self.superadmin = FakeClient(self.console,
                                     name="Superadmin",
                                     guid="Superadmin_guid",
                                     groupBits=128)

        self.logger.propagate = True

    def init_plugin(self, config_content):
        self.logger.setLevel(VERBOSE)
        self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
Ejemplo n.º 4
0
class IpbanTestCase(unittest2.TestCase):

    def setUp(self):
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(dedent(r""""""))
        self.console = FakeConsole(self.parser_conf)
        self.console.gameName = 'f00'
        self.console.startup()

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        self.evt_queue = []

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # prepare a few players
        self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="MIKEGUID", groupBits=16, ip='1.1.1.1')
        self.paul = FakeClient(self.console, name="Paul", exactName="Paul", guid="PAULGUID", groupBits=1, ip='2.2.2.2')
        self.john = FakeClient(self.console, name="John", exactName="John", guid="JOHNGUID", groupBits=0, ip='3.3.3.3')
        self.mary = FakeClient(self.console, name="Mary", exactName="Mary", guid="MARYGUID", groupBits=0, ip='4.4.4.4')

        self.conf = CfgConfigParser()
        self.p = IpbanPlugin(self.console, self.conf)

        # return some mock data
        when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7'])
        when(self.p).getTempBanIps().thenReturn(['3.3.3.3', '8.8.8.8', '9.9.9.9'])

    def tearDown(self):
        self.console.working = False
        self.mike.disconnects()
        self.paul.disconnects()
        self.john.disconnects()
        self.mary.disconnects()

    def init(self, config_content=None):
        if config_content:
            self.conf.loadFromString(config_content)
        else:
            self.conf.loadFromString(dedent(r"""
                [settings]
                maxlevel: user
            """))
        self.p.onLoadConfig()
        self.p.onStartup()
Ejemplo n.º 5
0
class Test_events(unittest.TestCase):
    def setUp(self):
        with logging_disabled():
            from b3.fake import FakeConsole, FakeClient
            self.console = FakeConsole('@b3/conf/b3.distribution.xml')
        self.conf = CfgConfigParser()
        self.p = GaPlugin(self.console, self.conf)

        self.conf.loadFromString(
            dedent("""
            [google analytics]
            tracking ID: UA-000000-0
        """))
        self.p.onLoadConfig()
        self.p.onStartup()
        self.assertIsNotNone(self.p._ga_tracking_id)

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="GUID_joe",
                              ip="12.12.12.12")
        self.jack = FakeClient(self.console,
                               name="Jack",
                               guid="GUID_jack",
                               ip="45.45.45.45")

    def test_auth(self, fire_mock):
        self.joe.connects("1")
        # THEN
        self.assertEqual(1, len(fire_mock.mock_calls))

    def test_disconnect(self, fire_mock):
        self.joe.connects("1")
        self.joe.disconnects()
        # THEN
        self.assertEqual(2, len(fire_mock.mock_calls))

    def test_new_round(self, fire_mock):
        # GIVEN
        self.joe.connects("1")
        self.jack.connects("2")
        # WHEN
        self.console.game.gameType = "The game type"
        self.console.game.mapName = "The map name"
        self.console.queueEvent(
            self.console.getEvent('EVT_GAME_ROUND_START',
                                  data=self.console.game))
        # THEN
        self.assertEqual(4, len(fire_mock.mock_calls))
Ejemplo n.º 6
0
class CountryFilterTestCase(unittest2.TestCase):

    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS', 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()

        # create our plugin instance
        self.p = CountryfilterPlugin(self.console, CfgConfigParser())

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="MIKEGUID", ip='1.2.3.4', groupBits=0)
        self.bill = FakeClient(console=self.console, name="Bill", guid="BILLGUID", ip='2.3.4.5', groupBits=0)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL

    def tearDown(self):
        unstub()

    def init(self, config_content):
        """
        Initialize the plugin using the given configuration file content
        """
        self.p.config.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
class ServermonitorTestCase(TestCase):
    """
    TestCase suitable for testing the ServermonitorPlugin class
    """

    def setUp(self):
        # less logging
        self.logger = logging.getLogger('output')
        self.logger.setLevel(logging.ERROR)
        self.logger.propagate = False

        from b3.fake import FakeConsole, FakeClient

        # create a Fake parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString("""<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""")
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        # load the admin plugin
        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
            self.adminPlugin.onLoadConfig()
            self.adminPlugin._commands = {} # work around known bug in the Admin plugin which makes the _command property shared between all instances
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # load our plugin
        self.conf = CfgConfigParser()
        self.p = ServermonitorPlugin(self.console, self.conf)

        self.superadmin = FakeClient(self.console, name="Superadmin", guid="Superadmin_guid", groupBits=128)

        self.logger.propagate = True


    def init_plugin(self, config_content):
        self.logger.setLevel(VERBOSE)
        self.conf.loadFromString(config_content)
        self.p.onLoadConfig()
        self.p.onStartup()
Ejemplo n.º 8
0
    def setUp(self):
        testcase_lock.acquire()
        self.addCleanup(cleanUp)
        flush_console_streams()
        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        with logging_disabled():
            from b3.fake import FakeConsole

            self.console = FakeConsole(self.parser_conf)

        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)
Ejemplo n.º 9
0
    def setUp(self):
        self.sleep_patcher = patch("time.sleep")
        self.sleep_mock = self.sleep_patcher.start()

        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        # load the admin plugin
        if B3version(b3_version) >= B3version("1.10dev"):
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           admin_plugin_conf_file)
            self.adminPlugin._commands = {
            }  # work around known bug in the Admin plugin which makes the _command property shared between all instances
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()
Ejemplo n.º 10
0
    def setUp(self):
        # less logging
        self.logger = logging.getLogger('output')
        self.logger.setLevel(logging.ERROR)
        self.logger.propagate = False

        from b3.fake import FakeConsole, FakeClient

        # create a Fake parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString("""<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""")
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        # load the admin plugin
        self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.xml')
        self.adminPlugin._commands = {} # work around known bug in the Admin plugin which makes the _command property shared between all instances
        self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # load our plugin
        self.conf = CfgConfigParser()
        self.p = ServermonitorPlugin(self.console, self.conf)

        self.superadmin = FakeClient(self.console, name="Superadmin", guid="Superadmin_guid", groupBits=128)

        self.logger.propagate = True
Ejemplo n.º 11
0
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # create our plugin instance
        self.p = SpreePlugin(self.console, CfgConfigParser())

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="MIKEGUID",
                               groupBits=1)
        self.bill = FakeClient(console=self.console,
                               name="Bill",
                               guid="BILLGUID",
                               groupBits=1)
Ejemplo n.º 12
0
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS', 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()


        self.conf = CfgConfigParser()
        self.conf.loadFromString(dedent(r"""
            [settings]
            announce: yes

            [messages]
            client_connect: ^7$name ^3from ^7$city ^3(^7$country^3) connected
            cmd_locate: ^7$name ^3is connected from ^7$city ^3(^7$country^3)
            cmd_locate_failed: ^7Could not locate ^1$name
            cmd_distance: ^7$name ^3is ^7$distance ^3km away from you
            cmd_distance_self: ^7Sorry, I'm not that smart...meh!
            cmd_distance_failed: ^7Could not compute distance with ^1$name
            cmd_isp: ^7$name ^3is using ^7$isp ^3as isp
            cmd_isp_failed: ^7Could not determine ^1$name ^7isp

            [commands]
            locate: user
            distance: user
            isp: mod
        """))

        self.p = LocationPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="MIKEGUID", groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="BILLGUID", groupBits=16)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL
Ejemplo n.º 13
0
    def setUp(self):
        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=b3.TEAM_UNKNOWN)
Ejemplo n.º 14
0
    def setUp(self):
        testcase_lock.acquire()
        flush_console_streams()

        # create a FakeConsole parser
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(r"""""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()

        def myError(msg, *args, **kwargs):
            print(("ERROR: %s" % msg) % args)
        self.console.error = myError
Ejemplo n.º 15
0
class Test_events(unittest.TestCase):

    def setUp(self):
        with logging_disabled():
            from b3.fake import FakeConsole, FakeClient
            self.console = FakeConsole('@b3/conf/b3.distribution.xml')
        self.conf = CfgConfigParser()
        self.p = GaPlugin(self.console, self.conf)

        self.conf.loadFromString(dedent("""
            [google analytics]
            tracking ID: UA-000000-0
        """))
        self.p.onLoadConfig()
        self.p.onStartup()
        self.assertIsNotNone(self.p._ga_tracking_id)

        self.joe = FakeClient(self.console, name="Joe", guid="GUID_joe", ip="12.12.12.12")
        self.jack = FakeClient(self.console, name="Jack", guid="GUID_jack", ip="45.45.45.45")

    def test_auth(self, fire_mock):
        self.joe.connects("1")
        # THEN
        self.assertEqual(1, len(fire_mock.mock_calls))

    def test_disconnect(self, fire_mock):
        self.joe.connects("1")
        self.joe.disconnects()
        # THEN
        self.assertEqual(2, len(fire_mock.mock_calls))

    def test_new_round(self, fire_mock):
        # GIVEN
        self.joe.connects("1")
        self.jack.connects("2")
        # WHEN
        self.console.game.gameType = "The game type"
        self.console.game.mapName = "The map name"
        self.console.queueEvent(self.console.getEvent('EVT_GAME_ROUND_START', data=self.console.game))
        # THEN
        self.assertEqual(4, len(fire_mock.mock_calls))
Ejemplo n.º 16
0
    def setUp(self):
        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        self.conf = CfgConfigParser()
        self.conf.loadFromString(
            dedent("""
            [settings]
            min_level: mod
            min_level_global_manage: admin
            max_nicks: 3
            interval: 30
        """))

        self.p = NickregPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient
            self.senioradmin = FakeClient(console=self.console,
                                          name="SeniorAdmin",
                                          guid="SENIORADMIN",
                                          groupBits=64)
            self.admin = FakeClient(console=self.console,
                                    name="Admin",
                                    guid="ADMIN",
                                    groupBits=16)
            self.guest = FakeClient(console=self.console,
                                    name="Guest",
                                    guid="GUEST",
                                    groupBits=0)

        self.admin.connects("1")
        self.guest.connects("2")
        self.senioradmin.connects("3")
Ejemplo n.º 17
0
    def setUp(self):
        with logging_disabled():
            from b3.fake import FakeConsole, FakeClient
            self.console = FakeConsole('@b3/conf/b3.distribution.xml')
        self.conf = CfgConfigParser()
        self.p = GaPlugin(self.console, self.conf)

        self.conf.loadFromString(
            dedent("""
            [google analytics]
            tracking ID: UA-000000-0
        """))
        self.p.onLoadConfig()
        self.p.onStartup()
        self.assertIsNotNone(self.p._ga_tracking_id)

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="GUID_joe",
                              ip="12.12.12.12")
        self.jack = FakeClient(self.console,
                               name="Jack",
                               guid="GUID_jack",
                               ip="45.45.45.45")
Ejemplo n.º 18
0
def console():
    with logging_disabled():
        from b3.fake import FakeConsole
        fake_console = FakeConsole('@b3/conf/b3.distribution.xml')

    # load the admin plugin
    with logging_disabled():
        admin_plugin = AdminPlugin(fake_console, '@b3/conf/plugin_admin.ini')
        admin_plugin._commands = {}  # work around known bug in the Admin plugin which makes the _command property shared between all instances
        admin_plugin.onStartup()

    # make sure the admin plugin obtained by other plugins is our admin plugin
    when(fake_console).getPlugin('admin').thenReturn(admin_plugin)

    return fake_console
Ejemplo n.º 19
0
    def setUp(self):

        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
Ejemplo n.º 20
0
    def setUp(self):
        with logging_disabled():
            from b3.fake import FakeConsole, FakeClient
            self.console = FakeConsole('@b3/conf/b3.distribution.xml')
        self.conf = CfgConfigParser()
        self.p = GaPlugin(self.console, self.conf)

        self.conf.loadFromString(dedent("""
            [google analytics]
            tracking ID: UA-000000-0
        """))
        self.p.onLoadConfig()
        self.p.onStartup()
        self.assertIsNotNone(self.p._ga_tracking_id)

        self.joe = FakeClient(self.console, name="Joe", guid="GUID_joe", ip="12.12.12.12")
        self.jack = FakeClient(self.console, name="Jack", guid="GUID_jack", ip="45.45.45.45")
Ejemplo n.º 21
0
    def setUp(self):
        testcase_lock.acquire()
        flush_console_streams()

        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        self.console = FakeConsole(self.parser_conf)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()

        def myError(msg, *args, **kwargs):
            print(("ERROR: %s" % msg) % args)

        self.console.error = myError
Ejemplo n.º 22
0
    def setUp(self):
        testcase_lock.acquire()
        flush_console_streams()

        # create a FakeConsole parser
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(r"""""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()

        def myError(msg, *args, **kwargs):
            print(("ERROR: %s" % msg) % args)
        self.console.error = myError
class LocationTestCase(unittest2.TestCase):

    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS', 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()


        self.conf = CfgConfigParser()
        self.conf.loadFromString(dedent(r"""
            [settings]
            announce: yes

            [messages]
            client_connect: ^7$name ^3from ^7$city ^3(^7$country^3) connected
            cmd_locate: ^7$name ^3is connected from ^7$city ^3(^7$country^3)
            cmd_locate_failed: ^7Could not locate ^1$name
            cmd_distance: ^7$name ^3is ^7$distance ^3km away from you
            cmd_distance_self: ^7Sorry, I'm not that smart...meh!
            cmd_distance_failed: ^7Could not compute distance with ^1$name
            cmd_isp: ^7$name ^3is using ^7$isp ^3as isp
            cmd_isp_failed: ^7Could not determine ^1$name ^7isp

            [commands]
            locate: user
            distance: user
            isp: mod
        """))

        self.p = LocationPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console, name="Mike", guid="MIKEGUID", groupBits=1)
        self.bill = FakeClient(console=self.console, name="Bill", guid="BILLGUID", groupBits=16)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL

    def tearDown(self):
        unstub()

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST EVENTS                                                                                                    #
    #                                                                                                                  #
    ####################################################################################################################

    def test_event_client_geolocation_success(self):
        # GIVEN
        self.mike.connects('1')
        self.console.say = Mock()
        # WHEN
        self.console.queueEvent(self.console.getEvent('EVT_CLIENT_GEOLOCATION_SUCCESS', client=self.mike))
        # THEN
        self.console.say.assert_called_with('^7Mike ^3from ^7Rome ^3(^7Italy^3) connected')

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST COMMANDS                                                                                                   #
    #                                                                                                                  #
    ####################################################################################################################

    def test_cmd_locate_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate")
        # THEN
        self.assertListEqual(['missing data, try !help locate'], self.mike.message_history)

    def test_cmd_locate_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.bill.location = None
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate bill")
        # THEN
        self.assertListEqual(['Could not locate Bill'], self.mike.message_history)

    def test_cmd_locate(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate bill")
        # THEN
        self.assertListEqual(['Bill is connected from Mountain View (United States)'], self.mike.message_history)

    def test_cmd_distance_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance")
        # THEN
        self.assertListEqual(['missing data, try !help distance'], self.mike.message_history)

    def test_cmd_distance_self(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance mike")
        # THEN
        self.assertListEqual(['Sorry, I\'m not that smart...meh!'], self.mike.message_history)

    def test_cmd_distance_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.bill.location = None
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance bill")
        # THEN
        self.assertListEqual(['Could not compute distance with Bill'], self.mike.message_history)

    def test_cmd_distance(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance bill")
        # THEN
        self.assertListEqual(['Bill is 10068.18 km away from you'], self.mike.message_history)

    def test_cmd_isp_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp")
        # THEN
        self.assertListEqual(['missing data, try !help isp'], self.bill.message_history)

    def test_cmd_isp_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.mike.location = None
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp mike")
        # THEN
        self.assertListEqual(['Could not determine Mike isp'], self.bill.message_history)

    def test_cmd_isp(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp mike")
        # THEN
        self.assertListEqual(['Mike is using Fastweb as isp'], self.bill.message_history)
class B3TestCase(unittest.TestCase):
    def setUp(self):
        testcase_lock.acquire()
        flush_console_streams()

        # create a FakeConsole parser
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(r"""""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()

        def myError(msg, *args, **kwargs):
            print(("ERROR: %s" % msg) % args)

        self.console.error = myError

    def tearDown(self):
        flush_console_streams()
        testcase_lock.release()

    @contextmanager
    def assertRaiseEvent(self,
                         event_type,
                         event_client=None,
                         event_data=None,
                         event_target=None):
        """
        USAGE:
            def test_team_change(self):
            # GIVEN
            self.client._team = TEAM_RED
            # THEN
            with self.assertRaiseEvent(
                event_type='EVT_CLIENT_TEAM_CHANGE',
                event_data=24,
                event_client=self.client,
                event_target=None):
                # WHEN
                self.client.team = 24
        """
        if type(event_type) is basestring:
            event_type_name = event_type
        else:
            event_type_name = self.console.getEventName(event_type)
            self.assertIsNotNone(
                event_type_name,
                "could not find event with name '%s'" % event_type)

        with patch.object(self.console, 'queueEvent') as queueEvent:
            yield
            if event_type is None:
                assert not queueEvent.called
                return
            assert queueEvent.called, "No event was fired"

        def assertEvent(queueEvent_call_args):
            eventraised = queueEvent_call_args[0][0]
            return type(eventraised) == Event \
                and self.console.getEventName(eventraised.type) == event_type_name \
                and eventraised.data == event_data \
                and eventraised.target == event_target \
                and eventraised.client == event_client

        if not any(map(assertEvent, queueEvent.call_args_list)):
            raise AssertionError("Event %s(%r) not fired" %
                                 (self.console.getEventName(event_type), {
                                     'event_client': event_client,
                                     'event_data': event_data,
                                     'event_target': event_target
                                 }))
Ejemplo n.º 25
0
class LocationTestCase(unittest2.TestCase):
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS',
                                 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()

        self.conf = CfgConfigParser()
        self.conf.loadFromString(
            dedent(r"""
            [settings]
            announce: yes

            [messages]
            client_connect: ^7$name ^3from ^7$city ^3(^7$country^3) connected
            cmd_locate: ^7$name ^3is connected from ^7$city ^3(^7$country^3)
            cmd_locate_failed: ^7Could not locate ^1$name
            cmd_distance: ^7$name ^3is ^7$distance ^3km away from you
            cmd_distance_self: ^7Sorry, I'm not that smart...meh!
            cmd_distance_failed: ^7Could not compute distance with ^1$name
            cmd_isp: ^7$name ^3is using ^7$isp ^3as isp
            cmd_isp_failed: ^7Could not determine ^1$name ^7isp

            [commands]
            locate: user
            distance: user
            isp: mod
        """))

        self.p = LocationPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="MIKEGUID",
                               groupBits=1)
        self.bill = FakeClient(console=self.console,
                               name="Bill",
                               guid="BILLGUID",
                               groupBits=16)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL

    def tearDown(self):
        unstub()

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST EVENTS                                                                                                    #
    #                                                                                                                  #
    ####################################################################################################################

    def test_event_client_geolocation_success(self):
        # GIVEN
        self.mike.connects('1')
        self.console.say = Mock()
        # WHEN
        self.console.queueEvent(
            self.console.getEvent('EVT_CLIENT_GEOLOCATION_SUCCESS',
                                  client=self.mike))
        # THEN
        self.console.say.assert_called_with(
            '^7Mike ^3from ^7Rome ^3(^7Italy^3) connected')

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST COMMANDS                                                                                                   #
    #                                                                                                                  #
    ####################################################################################################################

    def test_cmd_locate_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate")
        # THEN
        self.assertListEqual(['missing data, try !help locate'],
                             self.mike.message_history)

    def test_cmd_locate_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.bill.location = None
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate bill")
        # THEN
        self.assertListEqual(['Could not locate Bill'],
                             self.mike.message_history)

    def test_cmd_locate(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!locate bill")
        # THEN
        self.assertListEqual(
            ['Bill is connected from Mountain View (United States)'],
            self.mike.message_history)

    def test_cmd_distance_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance")
        # THEN
        self.assertListEqual(['missing data, try !help distance'],
                             self.mike.message_history)

    def test_cmd_distance_self(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance mike")
        # THEN
        self.assertListEqual(['Sorry, I\'m not that smart...meh!'],
                             self.mike.message_history)

    def test_cmd_distance_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.bill.location = None
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance bill")
        # THEN
        self.assertListEqual(['Could not compute distance with Bill'],
                             self.mike.message_history)

    def test_cmd_distance(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.mike.clearMessageHistory()
        self.mike.says("!distance bill")
        # THEN
        self.assertListEqual(['Bill is 10068.18 km away from you'],
                             self.mike.message_history)

    def test_cmd_isp_no_arguments(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp")
        # THEN
        self.assertListEqual(['missing data, try !help isp'],
                             self.bill.message_history)

    def test_cmd_isp_failed(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        self.mike.location = None
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp mike")
        # THEN
        self.assertListEqual(['Could not determine Mike isp'],
                             self.bill.message_history)

    def test_cmd_isp(self):
        # GIVEN
        self.mike.connects('1')
        self.bill.connects('2')
        # WHEN
        self.bill.clearMessageHistory()
        self.bill.says("!isp mike")
        # THEN
        self.assertListEqual(['Mike is using Fastweb as isp'],
                             self.bill.message_history)
Ejemplo n.º 26
0
    def setUp(self):
        # create a FakeConsole parser
        parser_ini_conf = CfgConfigParser()
        parser_ini_conf.loadFromString(r'''''')
        self.parser_main_conf = MainConfig(parser_ini_conf)

        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_main_conf)

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           '@b3/conf/plugin_admin.ini')
            self.adminPlugin._commands = {}
            self.adminPlugin.onStartup()

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        # simulate geolocation plugin registering events
        self.console.createEvent('EVT_CLIENT_GEOLOCATION_SUCCESS',
                                 'Event client geolocation success')

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=1000)
        self.console.cron.stop()

        self.conf = CfgConfigParser()
        self.conf.loadFromString(
            dedent(r"""
            [settings]
            announce: yes

            [messages]
            client_connect: ^7$name ^3from ^7$city ^3(^7$country^3) connected
            cmd_locate: ^7$name ^3is connected from ^7$city ^3(^7$country^3)
            cmd_locate_failed: ^7Could not locate ^1$name
            cmd_distance: ^7$name ^3is ^7$distance ^3km away from you
            cmd_distance_self: ^7Sorry, I'm not that smart...meh!
            cmd_distance_failed: ^7Could not compute distance with ^1$name
            cmd_isp: ^7$name ^3is using ^7$isp ^3as isp
            cmd_isp_failed: ^7Could not determine ^1$name ^7isp

            [commands]
            locate: user
            distance: user
            isp: mod
        """))

        self.p = LocationPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        with logging_disabled():
            from b3.fake import FakeClient

        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="MIKEGUID",
                               groupBits=1)
        self.bill = FakeClient(console=self.console,
                               name="Bill",
                               guid="BILLGUID",
                               groupBits=16)
        self.mike.location = LOCATION_MIKE
        self.bill.location = LOCATION_BILL
Ejemplo n.º 27
0
class Censor_functional_tests(unittest.TestCase):

    def setUp(self):
        # create a FakeConsole parser
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        self.console = FakeConsole(self.parser_conf)
        self.console.startup()

        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=b3.TEAM_UNKNOWN)

    def init_plugin(self, config_content):
        self.conf = XmlConfigParser()
        self.conf.setXml(config_content)
        self.p = CensorPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()


    def test_conf(self, timer_patch):
        self.init_plugin(r"""
            <configuration plugin="censor">
                <settings name="settings">
                    <set name="max_level">40</set>
                    <!-- ignore bad words that have equal or less characters: -->
                    <set name="ignore_length">3</set>
                </settings>
                <badwords>
                    <penalty type="warning" reasonkeyword="default_reason"/>
                    <badword name="foo" lang="en">
                        <regexp>\bf[o0]{2}\b</regexp>
                    </badword>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                    <badname name="c**t">
                        <word>c**t</word>
                    </badname>
                </badnames>
            </configuration>
        """)
        self.assertEqual(1, len(self.p._badWords))


    def test_joe_says_badword(self, timer_patch):
        self.init_plugin(r"""
            <configuration plugin="censor">
                <settings name="settings">
                    <set name="max_level">40</set>
                    <!-- ignore bad words that have equal or less characters: -->
                    <set name="ignore_length">3</set>
                </settings>
                <badwords>
                    <penalty type="warning" reasonkeyword="default_reason"/>
                    <badword name="foo" lang="en">
                        <regexp>\bf[o0]{2}\b</regexp>
                    </badword>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                    <badname name="c**t">
                        <word>c**t</word>
                    </badname>
                </badnames>
            </configuration>
        """)
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.joe.says("qsfdl f0o!")
        self.assertEqual(1, self.joe.warn.call_count)


    def test_cunt_connects(self, timer_patch):
        self.init_plugin(r"""
            <configuration plugin="censor">
                <settings name="settings">
                    <set name="max_level">40</set>
                    <!-- ignore bad words that have equal or less characters: -->
                    <set name="ignore_length">3</set>
                </settings>
                <badwords>
                    <penalty type="warning" reasonkeyword="default_reason"/>
                    <badword name="foo" lang="en">
                        <regexp>\bf[o0]{2}\b</regexp>
                    </badword>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                    <badname name="c**t">
                        <word>c**t</word>
                    </badname>
                </badnames>
            </configuration>
        """)
        self.joe.name = self.joe.exactName = "c**t"
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.assertEqual(1, self.joe.warn.call_count)


    def test_2_letters_badword_when_ignore_length_is_2(self, timer_patch):
        self.init_plugin(r"""
            <configuration plugin="censor">
                <settings name="settings">
                    <set name="max_level">40</set>
                    <!-- ignore bad words that have equal or less characters: -->
                    <set name="ignore_length">2</set>
                </settings>
                <badwords>
                    <penalty type="warning" reasonkeyword="default_reason"/>
                    <badword name="TG" lang="fr">
                        <regexp>\bTG\b</regexp>
                    </badword>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                </badnames>
            </configuration>
        """)

        self.joe.warn = Mock()
        self.joe.warn.reset_mock()
        self.joe.connects(0)
        self.joe.says("tg")
        self.assertEqual(0, self.joe.warn.call_count)


    def test_2_letters_badword_when_ignore_length_is_1(self, timer_patch):
        self.init_plugin(r"""
            <configuration plugin="censor">
                <settings name="settings">
                    <set name="max_level">40</set>
                    <!-- ignore bad words that have equal or less characters: -->
                    <set name="ignore_length">1</set>
                </settings>
                <badwords>
                    <penalty type="warning" reasonkeyword="default_reason"/>
                    <badword name="TG" lang="fr">
                        <regexp>\bTG\b</regexp>
                    </badword>
                </badwords>
                <badnames>
                    <penalty type="warning" reasonkeyword="badname"/>
                </badnames>
            </configuration>
        """)

        self.joe.warn = Mock()
        self.joe.warn.reset_mock()
        self.joe.connects(0)
        self.joe.says("tg")
        self.assertEqual(1, self.joe.warn.call_count)
    def setUpClass(cls):

        cls.fakeConsole = FakeConsole('@b3/conf/b3.distribution.xml')
        cls.conf = XmlConfigParser()
        cls.conf.setXml(r"""
            <configuration plugin="admin">
                <settings name="commands">
                    <set name="enable">100</set>
                    <set name="disable">100</set>
                    <set name="die">100</set>
                    <set name="reconfig">100</set>
                    <set name="restart">100</set>
                    <set name="mask">100</set>
                    <set name="unmask">100</set>
                    <set name="runas-su">100</set>

                    <set name="pause">90</set>
                    <set name="rebuild">90</set>
                    <set name="clientinfo">90</set>
                    <set name="putgroup">90</set>
                    <set name="ungroup">90</set>

                    <set name="permban-pb">80</set>
                    <set name="map">80</set>
                    <set name="maprotate">80</set>
                    <set name="warnclear-wc">80</set>
                    <set name="clear-kiss">80</set>
                    <set name="lookup-l">80</set>
                    <set name="makereg-mr">80</set>
                    <set name="spankall-sall">80</set>
                    <set name="banall-ball">80</set>
                    <set name="kickall-kall">80</set>
                    <set name="pbss">80</set>

                    <set name="ban-b">60</set>
                    <set name="unban">60</set>
                    <set name="spank-sp">60</set>

                    <set name="tempban-tb">40</set>
                    <set name="baninfo-bi">40</set>
                    <set name="kick-k">40</set>
                    <set name="admintest">40</set>
                    <set name="scream">40</set>
                    <set name="notice">40</set>

                    <set name="find">20</set>
                    <set name="aliases-alias">20</set>
                    <set name="warns">20</set>
                    <set name="warninfo-wi">20</set>
                    <set name="warnremove-wr">20</set>
                    <set name="warn-w">20</set>
                    <set name="warntest-wt">20</set>
                    <set name="spams">20</set>
                    <set name="spam-s">20</set>
                    <set name="list">20</set>
                    <set name="admins">20</set>
                    <set name="say">20</set>
                    <set name="status">20</set>
                    <set name="leveltest-lt">20</set>
                    <set name="poke">20</set>

                    <set name="b3">9</set>

                    <set name="seen">2</set>
                    <set name="maps">2</set>
                    <set name="nextmap">2</set>

                    <set name="regtest">1</set>
                    <set name="time">1</set>

                    <set name="help-h">0</set>
                    <set name="register">0</set>
                    <set name="rules-r">0</set>
                </settings>
                <settings name="settings">
                <!-- noreason_level : admin from this level are not required to specify a reason when giving penalties to players -->
                    <set name="noreason_level">100</set>
                    <!-- hidecmd_level : level required to be able to use hidden commands. On quake3 based games, a hidden command can be issued by
                    telling to command to oneself -->
                    <set name="hidecmd_level">60</set>
                    <!-- long_tempban_level : admin level required to be able to issue bans longer than long_tempban_max_duration -->
                    <set name="long_tempban_level">80</set>
                    <!-- long_tempban_max_duration : maximum ban duration that can be inflicted by admin of level below long_tempban_level -->
                    <set name="long_tempban_max_duration">3h</set>
                    <!-- command_prefix : the prefix that should be put before b3 commands -->
                    <set name="command_prefix">!</set>
                    <!-- comamnd_prefix_loud : some commands can have their result broadcasted to the whole player crowed instead of only to
                    the player issuing the command. To have such a behavior, use this command prefix instead -->
                    <set name="command_prefix_loud">@</set>
                    <!-- command_prefix_big : some commands can have their result broadcasted to the whole player crowed as a bigtext.
                    To have such a behavior, use this command prefix instead -->
                    <set name="command_prefix_big"><![CDATA[&]]></set>
                    <!-- admins_level : minimum level for groups to consider as admins -->
                    <set name="admins_level">20</set>
                    <!-- ban_duration : tempban duration to apply to the !ban and !banall commands -->
                    <set name="ban_duration">14d</set>
                </settings>
                <settings name="messages">
                    <set name="ban_denied">^7Hey %s^7, you're no Elvis, can't ban %s</set>
                    <set name="help_available">^7Available commands: %s</set>
                    <set name="temp_ban_self">^7%s ^7Can't ban yourself newb</set>
                    <set name="groups_in">^7%s^7 is in groups %s</set>
                    <set name="say">^7%s^7: %s</set>
                    <set name="player_id">^7%s [^2%s^7]</set>
                    <set name="seen">^7%s ^7was last seen on %s</set>
                    <set name="help_no_command">^7Command not found %s</set>
                    <set name="lookup_found">^7[^2@%s^7] %s^7 [^3%s^7]</set>
                    <set name="kick_self">^7%s ^7Can't kick yourself newb!</set>
                    <set name="groups_welcome">^7You are now a %s</set>
                    <set name="warn_denied">%s^7, %s^7 owns you, can't warn</set>
                    <set name="groups_already_in">^7%s^7 is already in group %s</set>
                    <set name="temp_ban_denied">^7Hey %s^7, you're no ^1Red ^7Elvis, can't temp ban %s</set>
                    <set name="players_matched">^7Players matching %s %s</set>
                    <set name="ban_self">^7%s ^7Can't ban yourself newb!</set>
                    <set name="regme_annouce">^7%s ^7put in group %s</set>
                    <set name="kick_denied">^7%s^7 gets 1 point, %s^7 gets none, %s^7 wins, can't kick</set>
                    <set name="no_players">^7No players found matching %s</set>
                    <set name="spanked_reason">%s ^7was ^1SPANKED^7 by %s ^7for %s</set>
                    <set name="groups_added">^7%s ^7added to group %s</set>
                    <set name="groups_put">^7%s ^7put in group %s</set>
                    <set name="groups_none">^7%s^7 is not in any groups</set>
                    <set name="help_command">^2%s%s ^7%s</set>
                    <set name="warn_self">^7%s ^7Can't warn yourself newb!</set>
                    <set name="regme_regged">^7You are now a %s</set>
                    <set name="help_none">^7You have no available commands</set>
                    <set name="spanked">%s ^7was ^1SPANKED^7 by %s</set>
                    <set name="admins">^7Admins online: %s</set>
                    <set name="time">At the sound of the beep it will be ^3%s^7...(beeeep)</set>
                    <set name="unknown_command">^7Unrecognized command %s</set>
                    <set name="leveltest">^7%s ^7[^3@%s^7] is a ^3%s ^7[^2%s^7] since %s</set>
                    <set name="leveltest_nogroups">^7%s ^7[^3@%s^7] is not in any groups</set>
                    <set name="aliases">^7%s^7 aliases: %s</set>
                <set name="cmd_plugin_disabled">^7cannot execute command. Plugin disabled</set>
                </settings>
                <settings name="warn">
                    <!-- pm_global determines whether the warning is sent to the the whole server, or just the player and admin, to reduce chatbox spam.
            0 is whole server, 1 is private.
            -->
                    <set name="pm_global">0</set>
                    <!-- alert_kick_num : if a player reach this number of active warnings he will be notified by with message then tempbanned -->
                    <set name="alert_kick_num">3</set>
                    <!-- alert_kick_num : if a player reach this number of active warnings he will be tempbanned right away -->
                    <set name="instant_kick_num">5</set>
                    <!-- tempban_num : when the number of warnings goes over this limit, the player is tempban for tempban_duration -->
                    <set name="tempban_num">6</set>
                    <!-- tempban_duration : for how long to tempban a players whose number of warning exceeded tempban_num -->
                    <set name="tempban_duration">1d</set>
                    <!-- max_duration : when the bot decides to tempban (warning exceeding alert_kick_num) the ban duration is
                    computed from the duration of each of the active warnings but will never exceed max_duration -->
                    <set name="max_duration">1d</set>
                    <!-- message : template for building warning messages -->
                    <set name="message">^1WARNING^7 [^3$warnings^7]: $reason</set>
                    <!-- warn_delay : an given player cannot only be given one warning every warn_delay seconds -->
                    <set name="warn_delay">15</set>
                    <!-- reason : template for building warning message when a player exceeds the tolerated number of warnings -->
                    <set name="reason">^7too many warnings: $reason</set>
                    <!-- duration_divider : tempbanned duration is computed from the sum of all active warnings durations divided by duration_divider -->
                    <set name="duration_divider">30</set>
                    <!-- alert : when a player receives his last warning tolerated warning, this message is broadcasted so an admin can decide to clear it and
                    this teaches other players too -->
                    <set name="alert">^1ALERT^7: $name^7 auto-kick from warnings if not cleared [^3$warnings^7] $reason</set>
                <!-- warn_command_abusers will make the bot warn players who try to use command they don't have suffisent rights to use or warn
                players who try invalid commands  -->
                <set name="warn_command_abusers">yes</set>
                </settings>
                <settings name="spamages">
                <!-- You can define shortcuts to messages that can be used with the !spam command. Note if the message shortcut is of
                the form 'rule#' where # is a number between 1 and 20, they will be used for the !rules command. -->
                    <set name="vent">^3Ventrilo voice chat: ^269.93.232.106:3803 ^3password ^2nffoov^3, www.ventrilo.org</set>
                    <set name="join">^3Join Austin Server by signing up on the forums at www.austinserver.com</set>
                    <set name="forum">^3Visit the Austin Server forums at www.austinserver.com</set>
                    <set name="rtfm">^3RTFM! www.austinservers.com</set>
                    <set name="stack">^7No clan stacking, members must split evenly between the teams, go spectator and wait if you have to</set>

                    <set name="rule1">^3Rule #1: No racism of any kind</set>
                    <set name="rule2">^3Rule #2: No clan stacking, members must split evenly between the teams</set>
                    <set name="rule3">^3Rule #3: No arguing with admins (listen and learn or leave)</set>
                    <set name="rule4">^3Rule #4: No abusive language or behavior towards admins or other players</set>
                    <set name="rule5">^3Rule #5: No offensive or potentially offensive names, annoying names, or in-game (double caret (^)) color in names</set>
                    <set name="rule6">^3Rule #6: No recruiting for your clan, your server, or anything else</set>
                    <set name="rule7">^3Rule #7: No advertising or spamming of websites or servers</set>
                    <set name="rule8">^3Rule #8: No profanity or offensive language (in any language)</set>
                    <set name="rule9">^3Rule #9: Do ^1NOT ^3fire at teammates or within 10 seconds of spawning</set>
                    <set name="rule10">^3Rule #10: Offense players must play for the objective and support their team</set>
                </settings>
                <settings name="warn_reasons">
                  <!-- Define here shorcuts for warning reasons. Those shortcuts can be used with the !kick, !tempban, !ban, and !permban commands.
                  The format of warning reasons can be of the form "<duration>, <message>". The duration defines how long such a warning will
                  last before expiring. The message is what will be sent to the player.
                  NOTE : in the message, you can make reference to an existing spammage shortcut by using the form '/spam#<spammage keyword>'
                  NOTE2 : you can define warning shortcuts aliases if you don't use duration and the message is of the form '/<warn shortcut>'-->
                    <set name="generic">1h, ^7</set>
                    <set name="default">1h, ^7behave yourself</set>

                    <set name="rule1">10d, /spam#rule1</set>
                    <set name="rule2">1d, /spam#rule2</set>
                    <set name="rule3">1d, /spam#rule3</set>
                    <set name="rule4">1d, /spam#rule4</set>
                    <set name="rule5">1h, /spam#rule5</set>
                    <set name="rule6">1d, /spam#rule6</set>
                    <set name="rule7">1d, /spam#rule7</set>
                    <set name="rule8">3d, /spam#rule8</set>
                    <set name="rule9">3h, /spam#rule9</set>
                    <set name="rule10">3d, /spam#rule10</set>

                    <set name="stack">1d, /spam#stack</set>

                    <set name="lang">/rule8</set>
                    <set name="language">/rule8</set>
                    <set name="cuss">/rule8</set>
                    <set name="profanity">/rule8</set>

                    <set name="name">/rule5</set>
                    <set name="color">1h, ^7No in-game (double caret (^)) color in names</set>
                    <set name="badname">1h, ^7No offensive, potentially offensive, or annoying names</set>
                    <set name="spec">/spectator</set>


                    <set name="adv">/rule7</set>
                    <set name="racism">/rule1</set>
                    <set name="stack">/rule2</set>
                    <set name="recruit">/rule6</set>
                    <set name="argue">/rule3</set>
                    <set name="sfire">/rule9</set>
                    <set name="spawnfire">/rule9</set>
                    <set name="jerk">/rule4</set>

                    <set name="afk">5m, ^7you appear to be away from your keyboard</set>
                    <set name="tk">1d, ^7stop team killing!</set>
                    <set name="obj">1h, ^7go for the objective!</set>
                    <set name="camp">1h, ^7stop camping or you will be kicked!</set>
                    <set name="fakecmd">1h, ^7do not use fake commands</set>
                    <set name="nocmd">1h, ^7do not use commands that you do not have access to, try using !help</set>
                    <set name="ci">5m, ^7connection interupted, reconnect</set>
                    <set name="spectator">5m, ^7spectator too long on full server</set>
                    <set name="spam">1h, ^7do not spam, shut-up!</set>
                </settings>
            </configuration>
        """)

        cls.p = AdminPlugin(cls.fakeConsole, cls.conf)
        cls.p.onLoadConfig()
        cls.p.onStartup()
    def setUp(self):
        # create a B3 FakeConsole
        self.parser_conf = XmlConfigParser()
        self.parser_conf.loadFromString(r"""<configuration/>""")
        self.console = FakeConsole(self.parser_conf)

        # create our plugin instance
        self.plugin_conf = CfgConfigParser()
        self.p = Weaponlimiterbf3Plugin(self.console, self.plugin_conf)

        # initialise the plugin
        self.plugin_conf.loadFromString(r'''
[commands]
weaponlimiter-wpl: 60
weaponlimits: guest
noobkill: 20

[settings]
change servermessage: yes
self_kill_counter: 1
config_strategy: mapname
display_extra_msg: message
yell_duration: 10

[punisher]
kill_player: no
warn_player: yes

[messages]
servermessage: This game uses weapons limits. Use !weaponlimits to show forbidden weapons.
weaponlimiter_enabled: WeaponLimiter for that round activated!
weaponlimiter_disabled: Weaponlimiter disabled! All Weapons allowed.
warn_message: You used a forbidden weapon! ^7!forbidden_weapons show the list of forbidden weapons
forbidden_message: Forbidden Weapons are: %s
allowed_message: Allowed Weapons: %s
extra_warning_message: You have %(victim)s killed with a %(weapon)s. This weapon is forbidden!

[XP2_Skybar]
banned weapons: SMAW, M320, RPG-7, USAS-12
gametype: Domination0
weapons: Weapons/Gadgets/C4/C4,870MCS,DAO-12,jackhammer,M1014,M26Mass,Siaga20k,SPAS-12,USAS-12
''')

        # fake BF3 game
        self.console.game.gameName = 'bf3'
        self.console.game.gameType = 'Domination0'
        self.console.game._mapName = 'XP2_Skybar'
        # startup plugin
        self.p.onLoadConfig()
        self.p.onStartup()
        # enable
        self.p._wpl_is_active = True
        # prepare a few players
        self.joe = FakeClient(self.console,
                              name="Joe",
                              exactName="Joe",
                              guid="zaerezarezar",
                              groupBits=1)
        self.simon = FakeClient(self.console,
                                name="Simon",
                                exactName="Simon",
                                guid="qsdfdsqfdsqf",
                                groupBits=0)
        self.admin = FakeClient(
            self.console,
            name="Level-40-Admin",
            exactName="Level-40-Admin",
            guid="875sasda",
            groupBits=16,
        )
        self.superadmin = FakeClient(self.console,
                                     name="God",
                                     exactName="God",
                                     guid="f4qfer654r",
                                     groupBits=128)
Ejemplo n.º 30
0
def index():

    b3log_file = StringIO()

    config_log_content = ""
    config_content = None
    chat_text = ""
    chat_consequences = ""
    playername_text = ""
    playername_consequences = ""

    if request.method == "POST":

        # create a B3 bot
        b3bot_conf = XmlConfigParser()
        b3bot_conf.loadFromString("<configuration/>")
        b3bot = FakeConsole(b3bot_conf)
        b3bot.screen = b3log_file

        # create a Censor plugin instance
        censor_conf = XmlConfigParser()
        censor_plugin = CensorPlugin(b3bot, censor_conf)

        # create a player Joe to test the chat messages
        joe = FakeClient(console=b3bot, name="Joe", guid="000joe000")

        # monkey patch the Censor plugin penalizeClient method to log its actions
        # and remove a dependy over the admin plugin
        censor_plugin.penalizeClient = penalizeClient
        censor_plugin.penalizeClientBadname = penalizeClientBadname

        # add our log handler to collect B3 log messages
        b3log.handlers = []
        b3log_handler = logging.StreamHandler(b3log_file)
        b3log.addHandler(b3log_handler)
        b3log.setLevel(logging.DEBUG)

        b3bot.log.disabled = False

        # read form data
        config_content = request.form["config_content"]
        chat_text = request.form["chat"]
        playername_text = request.form["playername"]

        if config_content is not None:
            # we got a config to test
            b3log_file.truncate(0)
            b3log.info("--------- loading Censor plugin config ----------")
            try:
                censor_conf.loadFromString(config_content)
            except ConfigFileNotValid, err:
                b3log.error("bad config file format : %r" % err)
                b3log_file.seek(0)
                config_log_content = b3log_file.read()
            except Exception, err:
                b3log.error("Unexpected error : %r" % err)
                b3log_file.seek(0)
                config_log_content = b3log_file.read()
            else:
                censor_plugin.onLoadConfig()
                b3log.info("--------- Censor plugin config loaded ----------")
                b3log_file.seek(0)
                config_log_content = b3log_file.read()

                if chat_text:
                    # we got some chat to check for badwords
                    b3log_file.truncate(0)
                    try:
                        censor_plugin.checkBadWord(text=chat_text, client=joe)
                    except VetoEvent:
                        pass
                    b3log_file.seek(0)
                    chat_consequences = b3log_file.read()

                if playername_text:
                    # we got some player name to check for badnames
                    b3log_file.truncate(0)
                    try:
                        joe.name = playername_text
                        with patch.object(threading, "Timer"):  # prevent the Censor plugin to check again every minute
                            censor_plugin.checkBadName(client=joe)
                    except VetoEvent:
                        pass
                    b3log_file.seek(0)
                    playername_consequences = b3log_file.read()
Ejemplo n.º 31
0
class IpbanTestCase(unittest2.TestCase):
    def setUp(self):

        if B3version(b3_version) >= B3version("1.10dev"):
            from b3.config import MainConfig
            self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
            self.parser_conf.loadFromString(dedent(r""""""))
            admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
        else:
            self.parser_conf = XmlConfigParser()
            self.parser_conf.loadFromString(
                dedent(r"""<configuration></configuration>"""))
            admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'

        self.console = FakeConsole(self.parser_conf)
        self.console.gameName = 'f00'
        self.console.startup()

        with logging_disabled():
            self.adminPlugin = AdminPlugin(self.console,
                                           admin_plugin_conf_file)
            self.adminPlugin.onLoadConfig()
            self.adminPlugin.onStartup()

        self.evt_queue = []

        # make sure the admin plugin obtained by other plugins is our admin plugin
        when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)

        with logging_disabled():
            from b3.fake import FakeClient

        # prepare a few players
        self.mike = FakeClient(self.console,
                               name="Mike",
                               exactName="Mike",
                               guid="MIKEGUID",
                               groupBits=16,
                               ip='1.1.1.1')
        self.paul = FakeClient(self.console,
                               name="Paul",
                               exactName="Paul",
                               guid="PAULGUID",
                               groupBits=1,
                               ip='2.2.2.2')
        self.john = FakeClient(self.console,
                               name="John",
                               exactName="John",
                               guid="JOHNGUID",
                               groupBits=0,
                               ip='3.3.3.3')
        self.mary = FakeClient(self.console,
                               name="Mary",
                               exactName="Mary",
                               guid="MARYGUID",
                               groupBits=0,
                               ip='4.4.4.4')

        self.conf = CfgConfigParser()
        self.p = IpbanPlugin(self.console, self.conf)

        # return some mock data
        when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7'])
        when(self.p).getTempBanIps().thenReturn(
            ['3.3.3.3', '8.8.8.8', '9.9.9.9'])

    def tearDown(self):
        self.console.working = False
        self.mike.disconnects()
        self.paul.disconnects()
        self.john.disconnects()
        self.mary.disconnects()

    def init(self, config_content=None):
        if config_content:
            self.conf.loadFromString(config_content)
        else:
            self.conf.loadFromString(
                dedent(r"""
                [settings]
                maxlevel: user
            """))
        self.p.onLoadConfig()
        self.p.onStartup()

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST CONFIG                                                                                                    #
    #                                                                                                                  #
    ####################################################################################################################

    def test_with_config_content(self):
        # GIVEN
        self.init(
            dedent(r"""
            [settings]
            maxlevel: admin
        """))
        # THEN
        self.assertEqual(self.p._maxLevel, 40)

    def test_with_empty_config(self):
        # GIVEN
        self.init(dedent(r"""
            [settings]
        """))
        # THEN
        self.assertEqual(self.p._maxLevel, 1)

    ####################################################################################################################
    #                                                                                                                  #
    #   TEST EVENTS                                                                                                    #
    #                                                                                                                  #
    ####################################################################################################################

    def test_higher_group_level_client_connect(self):
        # GIVEN
        self.init()
        self.mike.kick = Mock()
        # WHEN
        self.mike.connects('1')
        # THEN
        self.assertGreater(self.mike.maxLevel, self.p._maxLevel)
        self.assertEqual(self.mike.kick.call_count, 0)

    def test_ip_banned_client_connect(self):
        # GIVEN
        self.init()
        self.paul.kick = Mock()
        # WHEN
        self.paul.connects('1')
        # THEN
        self.assertLessEqual(self.paul.maxLevel, self.p._maxLevel)
        self.assertIn(self.paul.ip, self.p.getBanIps())
        self.paul.kick.assert_called_once_with(
            'Netblocker: Client refused: 2.2.2.2 (Paul) has an active Ban')

    def test_ip_temp_banned_client_connect(self):
        # GIVEN
        self.init()
        self.john.kick = Mock()
        # WHEN
        self.john.connects('1')
        # THEN
        self.assertLessEqual(self.paul.maxLevel, self.p._maxLevel)
        self.assertIn(self.john.ip, self.p.getTempBanIps())
        self.john.kick.assert_called_once_with(
            'Netblocker: Client refused: 3.3.3.3 (John) has an active TempBan')

    def test_clean_client_connect(self):
        # GIVEN
        self.init()
        self.mary.kick = Mock()
        # WHEN
        self.mary.connects('1')
        # THEN
        self.assertLessEqual(self.paul.maxLevel, self.p._maxLevel)
        self.assertNotIn(self.mary.ip, self.p.getBanIps())
        self.assertNotIn(self.mary.ip, self.p.getTempBanIps())
        self.assertEqual(self.mary.kick.call_count, 0)
Ejemplo n.º 32
0
 def setUp(self):
     with logging_disabled():
         from b3.fake import FakeConsole
         self.console = FakeConsole('@b3/conf/b3.distribution.xml')
     self.conf = CfgConfigParser()
     self.p = GaPlugin(self.console, self.conf)
Ejemplo n.º 33
0
class B3TestCase(unittest.TestCase):

    def setUp(self):
        testcase_lock.acquire()
        flush_console_streams()

        # create a FakeConsole parser
        self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
        self.parser_conf.loadFromString(r"""""")
        with logging_disabled():
            from b3.fake import FakeConsole
            self.console = FakeConsole(self.parser_conf)

        self.console.screen = Mock()
        self.console.time = time.time
        self.console.upTime = Mock(return_value=3)

        self.console.cron.stop()

        def myError(msg, *args, **kwargs):
            print(("ERROR: %s" % msg) % args)
        self.console.error = myError

    def tearDown(self):
        flush_console_streams()
        testcase_lock.release()

    @contextmanager
    def assertRaiseEvent(self, event_type, event_client=None, event_data=None, event_target=None):
        """
        USAGE:
            def test_team_change(self):
            # GIVEN
            self.client._team = TEAM_RED
            # THEN
            with self.assertRaiseEvent(
                event_type='EVT_CLIENT_TEAM_CHANGE',
                event_data=24,
                event_client=self.client,
                event_target=None):
                # WHEN
                self.client.team = 24
        """
        if type(event_type) is basestring:
            event_type_name = event_type
        else:
            event_type_name = self.console.getEventName(event_type)
            self.assertIsNotNone(event_type_name, "could not find event with name '%s'" % event_type)

        with patch.object(self.console, 'queueEvent') as queueEvent:
            yield
            if event_type is None:
                assert not queueEvent.called
                return
            assert queueEvent.called, "No event was fired"

        def assertEvent(queueEvent_call_args):
            eventraised = queueEvent_call_args[0][0]
            return type(eventraised) == Event \
                and self.console.getEventName(eventraised.type) == event_type_name \
                and eventraised.data == event_data \
                and eventraised.target == event_target \
                and eventraised.client == event_client

        if not any(map(assertEvent, queueEvent.call_args_list)):
            raise AssertionError("Event %s(%r) not fired" % (self.console.getEventName(event_type), {
                'event_client': event_client,
                'event_data': event_data,
                'event_target': event_target
            }))