コード例 #1
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])
コード例 #2
0
    def test_kill_different_teams(self, timer_patch):
        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_BLUE)

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

        joe.kills(mike)
        self.assertEqual(0, joe.warn.call_count)
コード例 #3
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])
コード例 #4
0
    def test_kill_within_10s(self, timer_patch):
        Tk_functional_test.p._round_grace = 10
        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)
        self.assertEqual(1, joe.warn.call_count)
コード例 #5
0
    def test_kill(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.kills(mike)
        self.assertEqual(1, joe.warn.call_count)
        self.assertIsNotNone(mike.getMessageHistoryLike("^7type ^3!fp ^7 to forgive"))
コード例 #6
0
 def test_kill_events_are_caught(self):
     # GIVEN
     joe = FakeClient(console=self.console, name="Joe", guid="joe_guid", team=TEAM_BLUE)
     simon = FakeClient(console=self.console, name="Simon", guid="simon_guid", team=TEAM_RED)
     assert joe.team != simon.team
     joe.connects(cid='1')
     simon.connects(cid='2')
     # WHEN
     # patch.object will replace the "update_killstreaks" property from object self.p with a mock object that does
     # nothing but allows us to assert if it was called or not.
     with patch.object(self.p, "kill") as update_killstreaks_mock:
         joe.kills(simon)
     # THEN
     self.assertTrue(update_killstreaks_mock.called)
コード例 #7
0
    def test_kill_different_teams(self, timer_patch):
        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_BLUE)

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

        joe.kills(mike)
        self.assertEqual(0, joe.warn.call_count)
コード例 #8
0
    def test_kill_within_10s(self, timer_patch):
        Tk_functional_test.p._round_grace = 10
        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)
        self.assertEqual(1, joe.warn.call_count)
コード例 #9
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])
コード例 #10
0
    def test_kill(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.kills(mike)
        self.assertEqual(1, joe.warn.call_count)
        self.assertIsNotNone(
            mike.getMessageHistoryLike("^7type ^3!fp ^7 to forgive"))
コード例 #11
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])
コード例 #12
0
    def test_multikill(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)

        with patch.object(fakeConsole, "say") as patched_say:
            joe.warn = Mock()
            joe.tempban = Mock()
            joe.connects(0)
            mike.connects(1)

            mike.clearMessageHistory()
            joe.kills(mike)
            self.assertEqual(1, joe.warn.call_count)
            self.assertEquals(1, len(mike.getAllMessageHistoryLike("^7type ^3!fp ^7 to forgive")))

            joe.kills(mike)
            self.assertEqual(1, len([call_args[0][0] for call_args in patched_say.call_args_list if "auto-kick if not forgiven" in call_args[0][0]]))

            joe.kills(mike)
            self.assertEqual(1, joe.tempban.call_count)
コード例 #13
0
    def test_multikill(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)

        with patch.object(fakeConsole, "say") as patched_say:
            joe.warn = Mock()
            joe.tempban = Mock()
            joe.connects(0)
            mike.connects(1)

            mike.clearMessageHistory()
            joe.kills(mike)
            self.assertEqual(1, joe.warn.call_count)
            self.assertEquals(
                1,
                len(mike.getAllMessageHistoryLike(
                    "^7type ^3!fp ^7 to forgive")))

            joe.kills(mike)
            self.assertEqual(
                1,
                len([
                    call_args[0][0] for call_args in patched_say.call_args_list
                    if "auto-kick if not forgiven" in call_args[0][0]
                ]))

            joe.kills(mike)
            self.assertEqual(1, joe.tempban.call_count)
コード例 #14
0
class Tk_functional_test(B3TestCase):


    def setUp(self):
        B3TestCase.setUp(self)

        self.console.gameName = 'f00'

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

        self.conf = XmlConfigParser()
        self.conf.setXml(r"""
        <configuration plugin="tk">
            <settings name="settings">
                <set name="max_points">400</set>
                <set name="levels">0,1,2,20,40</set>
                <set name="round_grace">7</set>
                <set name="issue_warning">sfire</set>
                <set name="grudge_enable">True</set>
                <set name="private_messages">True</set>
            </settings>
            <settings name="messages">
                <set name="ban">^7team damage over limit</set>
                <set name="forgive">^7$vname^7 has forgiven $aname [^3$points^7]</set>
                <set name="grudged">^7$vname^7 has a ^1grudge ^7against $aname [^3$points^7]</set>
                <set name="forgive_many">^7$vname^7 has forgiven $attackers</set>
                <set name="forgive_warning">^1ALERT^7: $name^7 auto-kick if not forgiven. Type ^3!forgive $cid ^7to forgive. [^3damage: $points^7]</set>
                <set name="no_forgive">^7no one to forgive</set>
                <set name="no_punish">^7no one to punish</set>
                <set name="players">^7Forgive who? %s</set>
                <set name="forgive_info">^7$name^7 has ^3$points^7 TK points</set>
                <set name="grudge_info">^7$name^7 is ^1grudged ^3$points^7 TK points</set>
                <set name="forgive_clear">^7$name^7 cleared of ^3$points^7 TK points</set>
            </settings>
            <settings name="level_0">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_1">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_2">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">1</set>
            </settings>
            <settings name="level_20">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
            <settings name="level_40">
                <set name="kill_multiplier">0.75</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
        </configuration>
        """)
        self.p = TkPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        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 test_dammage_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)


    def test_kill_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.kills(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)


    def test_kill_within_10s(self, timer_patch):
        self.p._round_grace = 10

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

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)

    def test_dammage(self, timer_patch):
        self.p._round_grace = 0

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

        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)


    def test_kill(self, timer_patch):
        self.p._round_grace = 0

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

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)
        self.assertIsNotNone(self.mike.getMessageHistoryLike("^7type ^3!fp ^7 to forgive"))


    def test_multikill(self, timer_patch):
        self.p._round_grace = 0

        with patch.object(self.console, "say") as patched_say:
            self.joe.warn = Mock()
            self.joe.tempban = Mock()
            self.joe.connects(0)
            self.mike.connects(1)

            self.mike.clearMessageHistory()
            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.warn.call_count)
            self.assertEquals(1, len(self.mike.getAllMessageHistoryLike("^7type ^3!fp ^7 to forgive")))

            self.joe.kills(self.mike)
            self.assertEqual(1, len([call_args[0][0] for call_args in patched_say.call_args_list if "auto-kick if not forgiven" in call_args[0][0]]))

            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.tempban.call_count)


    def test_forgiveinfo(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'], self.superadmin.message_history)

        self.joe.damages(self.bill, points=6)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 206 TK points, Attacked: Mike (200), Bill (6)'], self.superadmin.message_history)

        self.mike.damages(self.joe, points=27)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 206 TK points, Attacked: Mike (200), Bill (6), Attacked By: Mike [27]'], self.superadmin.message_history)


    def test_forgive(self, timer_patch):
        self.superadmin.connects(99)
        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'], self.superadmin.message_history)

        self.mike.says("!forgive")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"], self.superadmin.message_history)


    def test_forgiveclear(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'], self.superadmin.message_history)

        self.superadmin.says("!forgiveclear joe")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"], self.superadmin.message_history)


    def test_forgivelist(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(["no one to forgive"], self.joe.message_history)

        self.mike.damages(self.joe, points=14)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'], self.joe.message_history)


        self.bill.damages(self.joe, points=84)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'], self.joe.message_history)


    def test_forgiveall(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'], self.joe.message_history)

        self.joe.says("!forgiveall")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertNotIn("Mike", self.joe.message_history[0])
        self.assertNotIn("Bill", self.joe.message_history[0])


    def test_forgiveprev(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'], self.joe.message_history)

        self.joe.says("!forgiveprev")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'], self.joe.message_history)
コード例 #15
0
class Test_render_cmd_template(CustomcommandsTestCase):

    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")

    def test_no_placeholder(self):
        self.assertEqual("f00", self.p._render_cmd_template("f00", data="", client=self.player1))

    def test_ARG(self):
        self.assertEqual("f00 bill bar", self.p._render_cmd_template("f00 <ARG> bar", data="bill", client=self.player1))
        self.assertRaises(ValueError, self.p._render_cmd_template, "f00 <ARG> bar", data="", client=self.player1)

    def test_ARG_OPT(self):
        self.assertEqual("hi", self.p._render_cmd_template("hi <ARG:OPT:>", data="", client=self.player1))
        self.assertEqual("hi f00", self.p._render_cmd_template("hi <ARG:OPT:f00>", data="", client=self.player1))
        self.assertEqual("hi bar", self.p._render_cmd_template("hi <ARG:OPT:f00>", data="bar", client=self.player1))
        self.assertEqual("hi foo bar", self.p._render_cmd_template("hi <ARG:OPT:f00>", data="foo bar", client=self.player1))

    def test_ARG_FIND_MAP_errors(self):
        # GIVEN
        when(self.p.console).getMaps().thenReturn(["map1", "map2", "map3", "ut4_turnpike", "ut4_casa"])
        # THEN
        self.assertRaises(ValueError, self.p._render_cmd_template, "map <ARG:FIND_MAP>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "do you mean : map2, map3, map1 ?",
                                self.p._render_cmd_template, "map <ARG:FIND_MAP>", data="map", client=self.player1)

    def test_ARG_FIND_MAP_nominal(self):
        def assertFoundMap(expected_map, cmd_parameter):
            self.assertEqual("map " + expected_map, self.p._render_cmd_template("map <ARG:FIND_MAP>",
                                                                                data=cmd_parameter, client=self.player1))
        # GIVEN
        when(self.p.console).getMaps().thenReturn(["map1", "map2", "map3", "ut4_turnpike", "ut4_casa"])
        # THEN
        assertFoundMap("map1", "map1")
        assertFoundMap("map1", " map1 ")
        assertFoundMap("ut4_casa", "ut4_casa")
        assertFoundMap("ut4_casa", "casa")

    def test_ARG_FIND_PLAYER_nominal(self):
        # GIVEN
        when(self.p._adminPlugin).findClientPrompt("f00", self.player1).thenReturn(self.player2)
        # THEN
        self.assertEqual("kick slot2", self.p._render_cmd_template("kick <ARG:FIND_PLAYER:PID>", data="f00", client=self.player1))
        self.assertEqual("kick player2PBID", self.p._render_cmd_template("kick <ARG:FIND_PLAYER:PBID>", data="f00", client=self.player1))
        self.assertEqual("kick player2GUID", self.p._render_cmd_template("kick <ARG:FIND_PLAYER:GUID>", data="f00", client=self.player1))
        self.assertEqual("kick Player2", self.p._render_cmd_template("kick <ARG:FIND_PLAYER:NAME>", data="f00", client=self.player1))
        self.assertEqual("kick Player2^7", self.p._render_cmd_template("kick <ARG:FIND_PLAYER:EXACTNAME>", data="f00", client=self.player1))
        self.assertEqual("kick @%s" % self.player2.id, self.p._render_cmd_template("kick <ARG:FIND_PLAYER:B3ID>", data="f00", client=self.player1))

    def test_PLAYER(self):
        self.assertEqual("f00 slot1", self.p._render_cmd_template("f00 <PLAYER:PID>", data="", client=self.player1))
        self.assertEqual("f00 player1PBID", self.p._render_cmd_template("f00 <PLAYER:PBID>", data="", client=self.player1))
        self.assertEqual("f00 player1GUID", self.p._render_cmd_template("f00 <PLAYER:GUID>", data="", client=self.player1))
        self.assertEqual("f00 Player1", self.p._render_cmd_template("f00 <PLAYER:NAME>", data="", client=self.player1))
        self.assertEqual("f00 Player1^7", self.p._render_cmd_template("f00 <PLAYER:EXACTNAME>", data="", client=self.player1))
        self.assertEqual("f00 @1", self.p._render_cmd_template("f00 <PLAYER:B3ID>", data="", client=self.player1))

    def test_LAST_KILLER(self):
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:PID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:PBID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:GUID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:NAME>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:EXACTNAME>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last killer is unknown", self.p._render_cmd_template, "f00 <LAST_KILLER:B3ID>", data="", client=self.player1)
        # WHEN
        self.player2.kills(self.player1)
        # THEN
        self.assertEqual("f00 slot2", self.p._render_cmd_template("f00 <LAST_KILLER:PID>", data="", client=self.player1))
        self.assertEqual("f00 player2PBID", self.p._render_cmd_template("f00 <LAST_KILLER:PBID>", data="", client=self.player1))
        self.assertEqual("f00 player2GUID", self.p._render_cmd_template("f00 <LAST_KILLER:GUID>", data="", client=self.player1))
        self.assertEqual("f00 Player2", self.p._render_cmd_template("f00 <LAST_KILLER:NAME>", data="", client=self.player1))
        self.assertEqual("f00 Player2^7", self.p._render_cmd_template("f00 <LAST_KILLER:EXACTNAME>", data="", client=self.player1))
        self.assertEqual("f00 @2", self.p._render_cmd_template("f00 <LAST_KILLER:B3ID>", data="", client=self.player1))

    def test_LAST_VICTIM(self):
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:PID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:PBID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:GUID>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:NAME>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:EXACTNAME>", data="", client=self.player1)
        self.assertRaisesRegexp(ValueError, "your last victim is unknown", self.p._render_cmd_template, "f00 <LAST_VICTIM:B3ID>", data="", client=self.player1)
        # WHEN
        self.player1.kills(self.player2)
        # THEN
        self.assertEqual("f00 slot2", self.p._render_cmd_template("f00 <LAST_VICTIM:PID>", data="", client=self.player1))
        self.assertEqual("f00 player2PBID", self.p._render_cmd_template("f00 <LAST_VICTIM:PBID>", data="", client=self.player1))
        self.assertEqual("f00 player2GUID", self.p._render_cmd_template("f00 <LAST_VICTIM:GUID>", data="", client=self.player1))
        self.assertEqual("f00 Player2", self.p._render_cmd_template("f00 <LAST_VICTIM:NAME>", data="", client=self.player1))
        self.assertEqual("f00 Player2^7", self.p._render_cmd_template("f00 <LAST_VICTIM:EXACTNAME>", data="", client=self.player1))
        self.assertEqual("f00 @2", self.p._render_cmd_template("f00 <LAST_VICTIM:B3ID>", data="", client=self.player1))

    def test_ADMINGROUP_SHORT(self):
        groups = {0: 'guest', 1: 'user', 2: 'reg', 8: 'mod', 16: 'admin', 32: 'fulladmin', 64: 'senioradmin', 128: 'superadmin'}
        for groupBits, group_keyword in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual("f00 %s" % group_keyword,
                             self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_SHORT>", data="", client=self.player1),
                             "failed with group %s" % group_keyword)

    def test_ADMINGROUP_LONG(self):
        groups = {0: 'Guest', 1: 'User', 2: 'Regular', 8: 'Moderator', 16: 'Admin', 32: 'Full Admin', 64: 'Senior Admin', 128: 'Super Admin'}
        for groupBits, group_name in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual("f00 %s" % group_name,
                             self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_LONG>", data="", client=self.player1),
                             "failed with group %s" % group_name)

    def test_ADMINGROUP_LEVEL(self):
        groups = {0: 0, 1: 1, 2: 2, 8: 20, 16: 40, 32: 60, 64: 80, 128: 100}
        for groupBits, group_level in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual("f00 %s" % group_level,
                             self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_LEVEL>", data="", client=self.player1),
                             "failed with group %s" % group_level)
コード例 #16
0
class PingkickerPluginTest(TestCase):

    def tearDown(self):
        if hasattr(self, "parser"):
            del self.parser.clients
            self.parser.working = False

    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)

    def test_warning_on_forbidden_kill(self):
        self.joe.connects('joe')
        self.simon.connects('simon')
        #clear message history
        self.joe.message_history = []
        self.simon.message_history = []
        # player simon kills joe with the M1014
        self.simon.kills(self.joe, 'M1014')

        self.assertEqual('You have Joe killed with a M1014. This weapon is forbidden!', self.simon.message_history[0])
        #self.assertEqual(self.p._messages['reminder_ping_warning'], self.simon.message_history[1])

    def test_punish_on_forbidden_kill(self):
        pass

    def test_cmd_weaponlimits(self):
        pass
コード例 #17
0
class Test_first_kill_alert(TestCase):

    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 = Killannouncerbf3Plugin(self.console, self.plugin_conf)
        # initialise the plugin
        self.plugin_conf.loadFromString(r'''
[settings]
announce first kill: yes
[first kill alert]
us1: %(murderer)s takes first blood against %(victim)s! The battle has just began!!!
de1: %(murderer)s hat das erste Blut von %(victim)s genommen! Die Schlacht hat begonnen!!!
[kill streak alerts]
us1 #5: Killing Spree! %(murderer)s is dominating on a %(kill_streak_value)s kill streak!
us2 #10: Killing Spree! %(murderer)s is dominating on a %(kill_streak_value)s kill streak!
[end kill streak alerts]
us1: %(murderer)s has ended %(murderer)s kill streak at %(kill_streak_value)s kills!

        ''')
        # Plugin ipinfodb is required. We trick and set county property later.
        self.p.console._plugins['ipinfodb'] = ''

        self.p.onLoadConfig()
        self.p.onStartup()
        # prepare a few players
        self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, country='de',team=TEAM_RED)
        self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, country='us',team=TEAM_BLUE)
        self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, country='ch',)
        self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, country='fr',)

        self.joe.connects(cid='1')
        self.simon.connects(cid='2')

    def test_kill_events_are_caught(self):
        # GIVEN
        joe = FakeClient(console=self.console, name="Joe", guid="joe_guid", team=TEAM_BLUE)
        simon = FakeClient(console=self.console, name="Simon", guid="simon_guid", team=TEAM_RED)
        assert joe.team != simon.team
        joe.connects(cid='1')
        simon.connects(cid='2')
        # WHEN
        # patch.object will replace the "update_killstreaks" property from object self.p with a mock object that does
        # nothing but allows us to assert if it was called or not.
        with patch.object(self.p, "kill") as update_killstreaks_mock:
            joe.kills(simon)
        # THEN
        self.assertTrue(update_killstreaks_mock.called)

    #
    # Test announcement on first kill
    #
    def test_first_kill_does_get_announced(self):
        # assume a EVT_GAME_ROUND_STARTED event was fired and handled
        self.p._round_started = True
        # WHEN
        with patch(target='b3.fake.FakeClient.message') as saybig_mock:
            self.joe.kills(self.simon)
        # THEN
        self.assertTrue(saybig_mock.called)
        self.assertListEqual([call('Joe hat das erste Blut von Simon genommen! Die Schlacht hat begonnen!!!'),
                              call('Joe takes first blood against Simon! The battle has just began!!!')], saybig_mock.mock_calls)

    def test_second_kill_does_not_get_announced(self):
        # assume a EVT_GAME_ROUND_STARTED event was fired and handled
        self.p._round_started = True

        with patch(target='b3.fake.FakeClient.message') as saybig_mock:
            self.joe.kills(self.simon)
            self.simon.kills(self.joe)
        # THEN
        self.assertTrue(saybig_mock.called)
        self.assertListEqual([call('Joe hat das erste Blut von Simon genommen! Die Schlacht hat begonnen!!!'),
                              call('Joe takes first blood against Simon! The battle has just began!!!')], saybig_mock.mock_calls)

    #
    # Streak tests
    #
    def test_kill_streak(self):
        with patch(target='b3.fake.FakeClient.message') as announce_kill_streak_mock:
            # Joe kills Simon 5 times:
            _count = 0
            while _count < 5 :
                _count += 1
                self.joe.kills(self.simon)
        self.assertTrue(announce_kill_streak_mock.called)
        self.assertListEqual([call('Killing Spree! Joe is dominating on a 5 kill streak!'),
                              call('Killing Spree! Joe is dominating on a 5 kill streak!')], announce_kill_streak_mock.mock_calls)
        # and kill himm again - 10 kills
        with patch(target='b3.fake.FakeClient.message') as announce_kill_streak_mock:
            # Joe kills Simon 5 times again:
            _count = 0
            while _count < 5 :
                _count += 1
                self.joe.kills(self.simon)
        self.assertTrue(announce_kill_streak_mock.called)
        self.assertListEqual([call('Killing Spree! Joe is dominating on a 10 kill streak!'),
                              call('Killing Spree! Joe is dominating on a 10 kill streak!')], announce_kill_streak_mock.mock_calls)
コード例 #18
0
class Test_render_cmd_template(CustomcommandsTestCase):
    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")

    def test_no_placeholder(self):
        self.assertEqual(
            "f00",
            self.p._render_cmd_template("f00", data="", client=self.player1))

    def test_ARG(self):
        self.assertEqual(
            "f00 bill bar",
            self.p._render_cmd_template("f00 <ARG> bar",
                                        data="bill",
                                        client=self.player1))
        self.assertRaises(ValueError,
                          self.p._render_cmd_template,
                          "f00 <ARG> bar",
                          data="",
                          client=self.player1)

    def test_ARG_OPT(self):
        self.assertEqual(
            "hi",
            self.p._render_cmd_template("hi <ARG:OPT:>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "hi f00",
            self.p._render_cmd_template("hi <ARG:OPT:f00>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "hi bar",
            self.p._render_cmd_template("hi <ARG:OPT:f00>",
                                        data="bar",
                                        client=self.player1))
        self.assertEqual(
            "hi foo bar",
            self.p._render_cmd_template("hi <ARG:OPT:f00>",
                                        data="foo bar",
                                        client=self.player1))

    def test_ARG_FIND_MAP_errors(self):
        # GIVEN
        when(self.p.console).getMaps().thenReturn(
            ["map1", "map2", "map3", "ut4_turnpike", "ut4_casa"])
        # THEN
        self.assertRaises(ValueError,
                          self.p._render_cmd_template,
                          "map <ARG:FIND_MAP>",
                          data="",
                          client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "do you mean : map2, map3, map1 ?",
                                self.p._render_cmd_template,
                                "map <ARG:FIND_MAP>",
                                data="map",
                                client=self.player1)

    def test_ARG_FIND_MAP_nominal(self):
        def assertFoundMap(expected_map, cmd_parameter):
            self.assertEqual(
                "map " + expected_map,
                self.p._render_cmd_template("map <ARG:FIND_MAP>",
                                            data=cmd_parameter,
                                            client=self.player1))

        # GIVEN
        when(self.p.console).getMaps().thenReturn(
            ["map1", "map2", "map3", "ut4_turnpike", "ut4_casa"])
        # THEN
        assertFoundMap("map1", "map1")
        assertFoundMap("map1", " map1 ")
        assertFoundMap("ut4_casa", "ut4_casa")
        assertFoundMap("ut4_casa", "casa")

    def test_ARG_FIND_PLAYER_nominal(self):
        # GIVEN
        when(self.p._adminPlugin).findClientPrompt(
            "f00", self.player1).thenReturn(self.player2)
        # THEN
        self.assertEqual(
            "kick slot2",
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:PID>",
                                        data="f00",
                                        client=self.player1))
        self.assertEqual(
            "kick player2PBID",
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:PBID>",
                                        data="f00",
                                        client=self.player1))
        self.assertEqual(
            "kick player2GUID",
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:GUID>",
                                        data="f00",
                                        client=self.player1))
        self.assertEqual(
            "kick Player2",
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:NAME>",
                                        data="f00",
                                        client=self.player1))
        self.assertEqual(
            "kick Player2^7",
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:EXACTNAME>",
                                        data="f00",
                                        client=self.player1))
        self.assertEqual(
            "kick @%s" % self.player2.id,
            self.p._render_cmd_template("kick <ARG:FIND_PLAYER:B3ID>",
                                        data="f00",
                                        client=self.player1))

    def test_PLAYER(self):
        self.assertEqual(
            "f00 slot1",
            self.p._render_cmd_template("f00 <PLAYER:PID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player1PBID",
            self.p._render_cmd_template("f00 <PLAYER:PBID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player1GUID",
            self.p._render_cmd_template("f00 <PLAYER:GUID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player1",
            self.p._render_cmd_template("f00 <PLAYER:NAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player1^7",
            self.p._render_cmd_template("f00 <PLAYER:EXACTNAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 @1",
            self.p._render_cmd_template("f00 <PLAYER:B3ID>",
                                        data="",
                                        client=self.player1))

    def test_LAST_KILLER(self):
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:PID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:PBID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:GUID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:NAME>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:EXACTNAME>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last killer is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_KILLER:B3ID>",
                                data="",
                                client=self.player1)
        # WHEN
        self.player2.kills(self.player1)
        # THEN
        self.assertEqual(
            "f00 slot2",
            self.p._render_cmd_template("f00 <LAST_KILLER:PID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player2PBID",
            self.p._render_cmd_template("f00 <LAST_KILLER:PBID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player2GUID",
            self.p._render_cmd_template("f00 <LAST_KILLER:GUID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player2",
            self.p._render_cmd_template("f00 <LAST_KILLER:NAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player2^7",
            self.p._render_cmd_template("f00 <LAST_KILLER:EXACTNAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 @2",
            self.p._render_cmd_template("f00 <LAST_KILLER:B3ID>",
                                        data="",
                                        client=self.player1))

    def test_LAST_VICTIM(self):
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:PID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:PBID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:GUID>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:NAME>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:EXACTNAME>",
                                data="",
                                client=self.player1)
        self.assertRaisesRegexp(ValueError,
                                "Your last victim is unknown",
                                self.p._render_cmd_template,
                                "f00 <LAST_VICTIM:B3ID>",
                                data="",
                                client=self.player1)
        # WHEN
        self.player1.kills(self.player2)
        # THEN
        self.assertEqual(
            "f00 slot2",
            self.p._render_cmd_template("f00 <LAST_VICTIM:PID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player2PBID",
            self.p._render_cmd_template("f00 <LAST_VICTIM:PBID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 player2GUID",
            self.p._render_cmd_template("f00 <LAST_VICTIM:GUID>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player2",
            self.p._render_cmd_template("f00 <LAST_VICTIM:NAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 Player2^7",
            self.p._render_cmd_template("f00 <LAST_VICTIM:EXACTNAME>",
                                        data="",
                                        client=self.player1))
        self.assertEqual(
            "f00 @2",
            self.p._render_cmd_template("f00 <LAST_VICTIM:B3ID>",
                                        data="",
                                        client=self.player1))

    def test_ADMINGROUP_SHORT(self):
        groups = {
            0: 'guest',
            1: 'user',
            2: 'reg',
            8: 'mod',
            16: 'admin',
            32: 'fulladmin',
            64: 'senioradmin',
            128: 'superadmin'
        }
        for groupBits, group_keyword in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual(
                "f00 %s" % group_keyword,
                self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_SHORT>",
                                            data="",
                                            client=self.player1),
                "failed with group %s" % group_keyword)

    def test_ADMINGROUP_LONG(self):
        groups = {
            0: 'Guest',
            1: 'User',
            2: 'Regular',
            8: 'Moderator',
            16: 'Admin',
            32: 'Full Admin',
            64: 'Senior Admin',
            128: 'Super Admin'
        }
        for groupBits, group_name in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual(
                "f00 %s" % group_name,
                self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_LONG>",
                                            data="",
                                            client=self.player1),
                "failed with group %s" % group_name)

    def test_ADMINGROUP_LEVEL(self):
        groups = {0: 0, 1: 1, 2: 2, 8: 20, 16: 40, 32: 60, 64: 80, 128: 100}
        for groupBits, group_level in groups.items():
            # WHEN
            self.player1.groupBits = groupBits
            # THEN
            self.assertEqual(
                "f00 %s" % group_level,
                self.p._render_cmd_template("f00 <PLAYER:ADMINGROUP_LEVEL>",
                                            data="",
                                            client=self.player1),
                "failed with group %s" % group_level)
コード例 #19
0
class Test_kill(XlrstatsTestCase):
    """
    Validates that the stats get updated as expected upon kill events
    """

    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_p1_kills_p2(self):
        # GIVEN
        self.p1.kills(self.p2)
        s = self.p.get_PlayerStats(self.p1)
        # WHEN
        self.p1.clearMessageHistory()
        self.p1.says("!xlrstats")
        # THEN
        self.assertEqual(['XLR Stats: P1 : K 1 D 0 TK 0 Ratio 0.00 Skill 1024.00'], self.p1.message_history)

    def test_p1_teamkills_p2(self):
        # GIVEN
        self.p2.team = self.p1.team
        self.p1.kills(self.p2)
        s = self.p.get_PlayerStats(self.p1)
        # WHEN
        self.p1.clearMessageHistory()
        self.p1.says("!xlrstats")
        # THEN
        self.assertEqual(['XLR Stats: P1 : K 0 D 0 TK 1 Ratio 0.00 Skill 999.00'], self.p1.message_history)

    def test_p1_kills_p2_twice(self):
        # GIVEN
        self.p1.kills(self.p2)
        self.p1.kills(self.p2)
        s = self.p.get_PlayerStats(self.p1)
        # WHEN
        self.p1.clearMessageHistory()
        self.p1.says("!xlrstats")
        # THEN
        self.assertEqual(['XLR Stats: P1 : K 2 D 0 TK 0 Ratio 0.00 Skill 1035.45'], self.p1.message_history)

    def test_p1_kills_p2_then_p2_kills_p1(self):
        # GIVEN
        self.p1.kills(self.p2)
        self.p2.kills(self.p1)
        s = self.p.get_PlayerStats(self.p1)
        # WHEN
        self.p1.clearMessageHistory()
        self.p1.says("!xlrstats")
        # THEN
        self.assertEqual(['XLR Stats: P1 : K 1 D 1 TK 0 Ratio 1.00 Skill 1015.63'], self.p1.message_history)


    def test_p1_kills_bot(self):
        # GIVEN
        self.p2.bot = True
        self.p.exclude_bots = True
        self.console.verbose = Mock()
        # WHEN
        self.p1.kills(self.p2)
        # THEN
        self.console.verbose.assert_called_with("XlrstatsPlugin: bot involved: do not process!")
コード例 #20
0
class Tk_functional_test(B3TestCase):
    def setUp(self):
        B3TestCase.setUp(self)

        self.console.gameName = 'f00'

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

        self.conf = XmlConfigParser()
        self.conf.setXml(r"""
        <configuration plugin="tk">
            <settings name="settings">
                <set name="max_points">400</set>
                <set name="levels">0,1,2,20,40</set>
                <set name="round_grace">7</set>
                <set name="issue_warning">sfire</set>
                <set name="grudge_enable">True</set>
                <set name="private_messages">True</set>
            </settings>
            <settings name="messages">
                <set name="ban">^7team damage over limit</set>
                <set name="forgive">^7$vname^7 has forgiven $aname [^3$points^7]</set>
                <set name="grudged">^7$vname^7 has a ^1grudge ^7against $aname [^3$points^7]</set>
                <set name="forgive_many">^7$vname^7 has forgiven $attackers</set>
                <set name="forgive_warning">^1ALERT^7: $name^7 auto-kick if not forgiven. Type ^3!forgive $cid ^7to forgive. [^3damage: $points^7]</set>
                <set name="no_forgive">^7no one to forgive</set>
                <set name="no_punish">^7no one to punish</set>
                <set name="players">^7Forgive who? %s</set>
                <set name="forgive_info">^7$name^7 has ^3$points^7 TK points</set>
                <set name="grudge_info">^7$name^7 is ^1grudged ^3$points^7 TK points</set>
                <set name="forgive_clear">^7$name^7 cleared of ^3$points^7 TK points</set>
            </settings>
            <settings name="level_0">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_1">
                <set name="kill_multiplier">2</set>
                <set name="damage_multiplier">1</set>
                <set name="ban_length">2</set>
            </settings>
            <settings name="level_2">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">1</set>
            </settings>
            <settings name="level_20">
                <set name="kill_multiplier">1</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
            <settings name="level_40">
                <set name="kill_multiplier">0.75</set>
                <set name="damage_multiplier">0.5</set>
                <set name="ban_length">0</set>
            </settings>
        </configuration>
        """)
        self.p = TkPlugin(self.console, self.conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        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 test_dammage_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill_different_teams(self, timer_patch):
        self.joe.warn = Mock()
        self.joe.connects(0)
        self.mike.connects(1)
        self.mike.team = b3.TEAM_BLUE
        self.joe.kills(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill_within_10s(self, timer_patch):
        self.p._round_grace = 10

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

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)

    def test_dammage(self, timer_patch):
        self.p._round_grace = 0

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

        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.joe.damages(self.mike)
        self.assertEqual(0, self.joe.warn.call_count)

    def test_kill(self, timer_patch):
        self.p._round_grace = 0

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

        self.joe.kills(self.mike)
        self.assertEqual(1, self.joe.warn.call_count)
        self.assertIsNotNone(
            self.mike.getMessageHistoryLike("^7type ^3!fp ^7 to forgive"))

    def test_multikill(self, timer_patch):
        self.p._round_grace = 0

        with patch.object(self.console, "say") as patched_say:
            self.joe.warn = Mock()
            self.joe.tempban = Mock()
            self.joe.connects(0)
            self.mike.connects(1)

            self.mike.clearMessageHistory()
            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.warn.call_count)
            self.assertEquals(
                1,
                len(
                    self.mike.getAllMessageHistoryLike(
                        "^7type ^3!fp ^7 to forgive")))

            self.joe.kills(self.mike)
            self.assertEqual(
                1,
                len([
                    call_args[0][0] for call_args in patched_say.call_args_list
                    if "auto-kick if not forgiven" in call_args[0][0]
                ]))

            self.joe.kills(self.mike)
            self.assertEqual(1, self.joe.tempban.call_count)

    def test_forgiveinfo(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.joe.damages(self.bill, points=6)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(
            ['Joe has 206 TK points, Attacked: Mike (200), Bill (6)'],
            self.superadmin.message_history)

        self.mike.damages(self.joe, points=27)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual([
            'Joe has 206 TK points, Attacked: Mike (200), Bill (6), Attacked By: Mike [27]'
        ], self.superadmin.message_history)

    def test_forgive(self, timer_patch):
        self.superadmin.connects(99)
        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.mike.says("!forgive")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"],
                         self.superadmin.message_history)

    def test_forgiveclear(self, timer_patch):
        self.superadmin.connects(99)

        self.p._round_grace = 0

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

        self.joe.kills(self.mike)

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(['Joe has 200 TK points, Attacked: Mike (200)'],
                         self.superadmin.message_history)

        self.superadmin.says("!forgiveclear joe")

        self.superadmin.clearMessageHistory()
        self.superadmin.says("!forgiveinfo joe")
        self.assertEqual(["Joe has 0 TK points"],
                         self.superadmin.message_history)

    def test_forgivelist(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(["no one to forgive"], self.joe.message_history)

        self.mike.damages(self.joe, points=14)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'],
                         self.joe.message_history)

        self.bill.damages(self.joe, points=84)
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

    def test_forgiveall(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

        self.joe.says("!forgiveall")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertNotIn("Mike", self.joe.message_history[0])
        self.assertNotIn("Bill", self.joe.message_history[0])

    def test_forgiveprev(self, timer_patcher):
        self.p._round_grace = 0

        self.joe.connects(0)
        self.mike.connects(1)
        self.bill.connects(2)

        self.mike.damages(self.joe, points=14)
        self.bill.damages(self.joe, points=84)

        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14], [2] Bill [84]'],
                         self.joe.message_history)

        self.joe.says("!forgiveprev")
        self.joe.clearMessageHistory()
        self.joe.says("!forgivelist")
        self.assertEqual(['Forgive who? [1] Mike [14]'],
                         self.joe.message_history)
コード例 #21
0
class PingkickerPluginTest(TestCase):
    def tearDown(self):
        if hasattr(self, "parser"):
            del self.parser.clients
            self.parser.working = False

    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)

    def test_warning_on_forbidden_kill(self):
        self.joe.connects('joe')
        self.simon.connects('simon')
        #clear message history
        self.joe.message_history = []
        self.simon.message_history = []
        # player simon kills joe with the M1014
        self.simon.kills(self.joe, 'M1014')

        self.assertEqual(
            'You have Joe killed with a M1014. This weapon is forbidden!',
            self.simon.message_history[0])
        #self.assertEqual(self.p._messages['reminder_ping_warning'], self.simon.message_history[1])

    def test_punish_on_forbidden_kill(self):
        pass

    def test_cmd_weaponlimits(self):
        pass