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_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, '')])
 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 #5
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 #6
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 test_checkunknown(self):
     # GIVEN
     p1 = FakeClient(self.console, name="New UrT Player", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     self.p.namecheck()
     # THEN
     p1.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
 def test_checkbadnames(self):
     # GIVEN
     p1 = FakeClient(self.console, name="all", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     self.p.namecheck()
     # THEN
     p1.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
    def test_dammage_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.damages(mike)
        self.assertEqual(0, joe.warn.call_count)
    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)
 def test_checkdupes_with_player_reconnecting(self):
     # GIVEN
     p1 = FakeClient(self.console, name="sameName", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     p1.disconnects()
     p1.connects("2")
     self.p.namecheck()
     # THEN
     self.assertFalse(p1.warn.called)
 def test_checkdupes_with_player_reconnecting(self):
     # GIVEN
     p1 = FakeClient(self.console, name="sameName", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     p1.disconnects()
     p1.connects("2")
     self.p.namecheck()
     # THEN
     self.assertFalse(p1.warn.called)
Example #13
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_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"))
Example #15
0
    def test_dammage_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.damages(mike)
        self.assertEqual(0, joe.warn.call_count)
    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)
Example #17
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)
    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_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])
Example #20
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"))