Example #1
0
    def setUp(self):

        B3TestCase.setUp(self)

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

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

            self.joe = FakeClient(self.console,
                                  name="Joe",
                                  guid="joeguid",
                                  groupBits=1,
                                  team=b3.TEAM_RED)
            self.mike = FakeClient(self.console,
                                   name="Mike",
                                   guid="mikeguid",
                                   groupBits=1,
                                   team=b3.TEAM_RED)
            self.bill = FakeClient(self.console,
                                   name="Bill",
                                   guid="billguid",
                                   groupBits=1,
                                   team=b3.TEAM_RED)
            self.superadmin = FakeClient(self.console,
                                         name="SuperAdmin",
                                         guid="superadminguid",
                                         groupBits=128,
                                         team=b3.TEAM_RED)
    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)
Example #3
0
 def test_cmdgrant_with_lower_group_level(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     mike.clearMessageHistory()
     mike.says("!cmdlevel cmdlevel")
     superadmin.says("!cmdgrant mike cmdlevel")
     mike.says("!cmdlevel cmdlevel")
     # THEN
     grantlist = getattr(mike, GRANT_SET_ATTR, None)
     self.assertIsNotNone(grantlist)
     self.assertIn('cmdlevel', grantlist)
     self.assertLess(mike.maxLevel,
                     self.adminPlugin._commands['cmdlevel'].level[0])
     self.assertListEqual(['mike has now a grant for cmdlevel command'],
                          superadmin.message_history)
     self.assertListEqual([
         'You need to be in group Full Admin to use !cmdlevel',
         'command cmdlevel level: fulladmin'
     ], mike.message_history)
Example #4
0
 def test_cmdrevoke_with_client_reconnection(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       id="10",
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdgrant mike cmdlevel")
     superadmin.says("!cmdrevoke mike cmdlevel")
     mike.disconnects()
     del mike  # totally destroy the object
     mike = FakeClient(self.console,
                       id="10",
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # THEN
     grantlist = getattr(mike, GRANT_SET_ATTR, None)
     self.assertIsNotNone(grantlist)
     self.assertIsInstance(grantlist, set)
     self.assertEqual(0, len(grantlist))
    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 #6
0
 def setUp(self):
     XlrstatsTestCase.setUp(self)
     self.init()
     self.p1 = FakeClient(console=self.console, name="P1", guid="P1_GUID")
     self.p1.connects("1")
     self.p2 = FakeClient(console=self.console, name="P2", guid="P2_GUID")
     self.p2.connects("2")
Example #7
0
    def test_forgiveclear(self, timer_patch):
        from b3.fake import superadmin
        superadmin.connects(99)

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

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

        joe.kills(mike)

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

        superadmin.says("!forgiveclear joe")

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

        CallvoteTestCase.setUp(self)

        with logging_disabled():
            from b3.fake import FakeClient

        # create some clients
        self.mike = FakeClient(console=self.console,
                               name="Mike",
                               guid="mikeguid",
                               team=TEAM_RED,
                               groupBits=128)
        self.bill = FakeClient(console=self.console,
                               name="Bill",
                               guid="billguid",
                               team=TEAM_BLUE,
                               groupBits=16)
        self.mark = FakeClient(console=self.console,
                               name="Mark",
                               guid="markguid",
                               team=TEAM_RED,
                               groupBits=2)
        self.sara = FakeClient(console=self.console,
                               name="Sara",
                               guid="saraguid",
                               team=TEAM_SPEC,
                               groupBits=1)

        self.conf = CfgConfigParser()
        self.p = CallvotePlugin(self.console, self.conf)
Example #9
0
    def test_dammage(self, timer_patch):
        Tk_functional_test.p._round_grace = 0
        joe = FakeClient(fakeConsole,
                         name="Joe",
                         exactName="Joe",
                         guid="joeguid",
                         groupBits=1,
                         team=b3.TEAM_RED)
        mike = FakeClient(fakeConsole,
                          name="Mike",
                          exactName="Mike",
                          guid="mikeguid",
                          groupBits=1,
                          team=b3.TEAM_RED)

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

        joe.damages(mike)
        joe.damages(mike)
        joe.damages(mike)
        joe.damages(mike)
        joe.damages(mike)
        self.assertEqual(0, joe.warn.call_count)
Example #10
0
 def testPlugin5():
     jack = FakeClient(fakeConsole, name="Jack", _maxLevel=0)
     jack.connects(1)
     time.sleep(1.1)
     joe = FakeClient(fakeConsole, name="Joe", _maxLevel=2)
     joe.connects(2)
     moderator.connects(0)
     moderator.says('!makeroom')
Example #11
0
 def setUp(self):
     Iourt41TestCase.setUp(self)
     self.console.startup()
     self.joe = FakeClient(self.console, name="Joe", guid="000000000000000")
     self.joe.connects('0')
     self.bob = FakeClient(self.console, name="Bob", guid="111111111111111")
     self.bob.connects('1')
     self.world = self.console.clients['-1']
Example #12
0
    def setUp(self):
        B3TestCase.setUp(self)
        logging.getLogger('output').setLevel(logging.DEBUG)
        with logging_disabled():
            self.console.startup()
            self.conf = CfgConfigParser()
            self.p = ChatloggerPlugin(self.console, self.conf)

        ## prepare the mysql test database
        db = MySQLdb.connect(host=MYSQL_TEST_HOST,
                             user=MYSQL_TEST_USER,
                             passwd=MYSQL_TEST_PASSWORD)
        db.query("DROP DATABASE IF EXISTS %s" % MYSQL_TEST_DB)
        db.query("CREATE DATABASE %s CHARACTER SET utf8;" % MYSQL_TEST_DB)

        self.console.storage = DatabaseStorage(
            'mysql://%s:%s@%s/%s' % (MYSQL_TEST_USER, MYSQL_TEST_PASSWORD,
                                     MYSQL_TEST_HOST, MYSQL_TEST_DB),
            self.console)
        self.console.storage.executeSql("@b3/sql/b3.sql")
        self.console.storage.executeSql(CHATLOGGER_SQL_FILE)

        when(self.console.config).get('b3', 'time_zone').thenReturn('GMT')
        self.p.setup_fileLogger = Mock()

        self.conf.loadFromString(
            dedent("""
            [general]
            save_to_database: Yes
            save_to_file: no

            [file]
            logfile: @conf/chat.log
            rotation_rate: D

            [purge]
            max_age: 0
            hour: 0
            min: 0
        """))
        with logging_disabled():
            self.p.onLoadConfig()
            self.p.onStartup()
            self.joe = FakeClient(self.console,
                                  name="Joe",
                                  guid="joe_guid",
                                  team=TEAM_RED)
            self.simon = FakeClient(self.console,
                                    name="Simon",
                                    guid="simon_guid",
                                    team=TEAM_BLUE)
            self.joe.connects(1)
            self.simon.connects(3)

        self.assertEqual(0, self.count_chatlog_lines())
        self.assertEqual(0, self.count_cmdlog_lines())
Example #13
0
 def setUp(self):
     CustomcommandsTestCase.setUp(self)
     self.conf = CfgConfigParser()
     self.p = CustomcommandsPlugin(self.console, self.conf)
     self.p.onLoadConfig()
     self.p.onStartup()
     self.player1 = FakeClient(console=self.console, name="Player1", guid="player1GUID", pbid="player1PBID")
     self.player2 = FakeClient(console=self.console, name="Player2", guid="player2GUID", pbid="player2PBID")
     self.player1.connects(cid="slot1")
     self.player2.connects(cid="slot2")
Example #14
0
 def setUp(self):
     BFHTestCase.setUp(self)
     self.conf = XmlConfigParser()
     self.conf.loadFromString("""
             <configuration>
             </configuration>
         """)
     self.parser = BfhParser(self.conf)
     self.p1 = FakeClient(self.parser, name="Player1")
     self.p2 = FakeClient(self.parser, name="Player2")
Example #15
0
 def setUp(self):
     XlrstatsTestCase.setUp(self)
     self.init()
     # GIVEN two players P1 and P2 (P1 being a registered user)
     self.p1 = FakeClient(console=self.console, name="P1", guid="P1_GUID", team=TEAM_BLUE)
     self.p1.connects("1")
     self.p1.says("!register")
     self.p2 = FakeClient(console=self.console, name="P2", guid="P2_GUID", team=TEAM_RED)
     self.p2.connects("2")
     self.p._xlrstats_active = True
 def test_cmdrevoke_with_no_grant_given(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has no grant for cmdlevel command'], superadmin.message_history)
 def test_cmduse_access(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmduse mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has access to cmdlevel command'], superadmin.message_history)
Example #18
0
 def setUp(self):
     with logging_disabled():
         CustomcommandsTestCase.setUp(self)
         self.conf = CfgConfigParser()
         self.p = CustomcommandsPlugin(self.console, self.conf)
         self.guest = FakeClient(console=self.console, name="Guest", guid="GuestGUID", pbid="GuestPBID", group_bits=0)
         self.player1 = FakeClient(console=self.console, name="player1", guid="player1GUID", pbid="player1PBID", group_bits=1)
         self.player1.connects(cid="CID1")
         self.player2 = FakeClient(console=self.console, name="player2", guid="player2GUID", pbid="player2PBID", group_bits=1)
         self.player2.connects(cid="CID2")
         self.guest.connects(cid="guestCID")
Example #19
0
    def test_forgiveinfo(self, timer_patch):
        from b3.fake import superadmin
        superadmin.connects(99)

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

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

        joe.kills(mike)

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

        joe.damages(bill, points=6)

        superadmin.message_history = []
        superadmin.says("!forgiveinfo joe")
        self.assertIn("Joe has 206 TK points", superadmin.message_history[0])
        self.assertIn("Attacked: Mike (200), Bill (6)",
                      superadmin.message_history[0])
        self.assertNotIn("Attacked By:", superadmin.message_history[0])

        mike.damages(joe, points=27)

        superadmin.message_history = []
        superadmin.says("!forgiveinfo joe")
        self.assertIn("Joe has 206 TK points", superadmin.message_history[0])
        self.assertIn("Attacked: Mike (200), Bill (6)",
                      superadmin.message_history[0])
        self.assertIn("Attacked By: Mike [27]", superadmin.message_history[0])
 def test_cmdgrant_with_invalid_command(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdgrant mike fakecommand")
     # THEN
     self.assertListEqual(['could not find command fakecommand'], superadmin.message_history)
    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 test_cmdrevoke_with_previously_given_grant(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.says("!cmdgrant mike cmdlevel")
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike\'s grant for cmdlevel command has been removed'], superadmin.message_history)
Example #23
0
 def test_kill_enemy_2(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="76561000000000000")
     p1.connects("76561000000000000")
     p2 = FakeClient(self.parser, guid="70000000000000005")
     p2.connects("70000000000000005")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event('''"txsniper<76561000000000000><1>" killed "Killer Badger<70000000000000005><0>" with R_DmgType_SniperPrimary''')
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL', data=(100, "R_DmgType_SniperPrimary", 'body'), client=p1, target=p2)
Example #24
0
 def test_kill_teammate(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="11111111111111")
     p1.connects("11111111111111")
     p2 = FakeClient(self.parser, guid="2222222222222")
     p2.connects("2222222222222")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event('''"Name1<11111111111111><0>" killed "Name2<2222222222222><0>" with "the_weapon"''')
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL_TEAM', data=(100, "the_weapon", 'body'), client=p1, target=p2)
 def test_cmdgrant_with_higher_group_level(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdgrant mike cmdlevel")
     # THEN
     grantlist = getattr(mike, GRANT_SET_ATTR, None)
     self.assertIsNone(grantlist)
     self.assertListEqual(['mike is already able to use cmdlevel command'], superadmin.message_history)
Example #26
0
    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:
            self.conf.load(b3.getAbsolutePath("@b3/conf/plugin_admin.ini"))
        else:
            self.conf.loadFromString(config_content)

        self.p._commands = {}
        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)
 def test_checkdupes_no_dup(self):
     # GIVEN
     p1 = FakeClient(self.console, name="theName", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     p2 = FakeClient(self.console, name="anotherName", guid="p2guid")
     p2.warn = Mock()
     p2.connects("2")
     # WHEN
     self.assertFalse(p1.name == p2.name)
     self.p.namecheck()
     # THEN
     self.assertFalse(p1.warn.called)
     self.assertFalse(p2.warn.called)
 def test_checkdupes_with_dup(self):
     # GIVEN
     p1 = FakeClient(self.console, name="sameName", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     p2 = FakeClient(self.console, name="sameName", guid="p2guid")
     p2.warn = Mock()
     p2.connects("2")
     # WHEN
     self.assertTrue(p1.name == p2.name)
     self.p.namecheck()
     # THEN
     p1.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
     p2.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
Example #29
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")
Example #30
0
 def test_Hit_2(self):
     fatmatic = FakeClient(self.console,
                           name="Fat'Matic",
                           guid="11111111111111")
     d4dou = FakeClient(self.console,
                        name="[FR]d4dou",
                        guid="11111111111111")
     fatmatic.connects('3')
     d4dou.connects('6')
     self.assertEvent(
         r'''Hit: 3 6 9 17: [FR]d4dou hit Fat'Matic in the Legs''',
         event_type='EVT_CLIENT_DAMAGE',
         event_client=d4dou,
         event_target=fatmatic,
         event_data=(15, '35', '9'))