def test_nominal_with_reason(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.tempban("foo 3h theReason")
     foo_player.tempban.assert_called_once_with("theReason", "theReason", 3 * 60, self.mock_client)
 def test_nominal_no_reason(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.permban("foo")
     foo_player.ban.assert_called_once_with("", None, self.mock_client)
    def test_disable(self):
        mock_client = Mock(spec=Client, name="client")
        mock_client.maxLevel = 0
        mock_command = Mock(spec=Command, name="cmd")

        self.p.cmd_disable(data="", client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with("^7You must supply a plugin name to disable.")

        mock_client.reset_mock()
        self.p.cmd_disable(data="admin", client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with("^7You cannot disable/enable the admin plugin.")

        mock_client.reset_mock()
        self.p.console.getPlugin = Mock(return_value=None)
        self.p.cmd_disable(data="foo", client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with("^7No plugin named foo loaded.")

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.isEnabled = Mock(return_value=False)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_disable(data="foo", client=mock_client, cmd=mock_command)
        mock_client.message.assert_called_once_with("^7Plugin foo is already disable.")

        mock_client.reset_mock()
        mock_pluginA = Mock(spec=Plugin)
        mock_pluginA.__class__.__name__ = "MockPlugin"
        mock_pluginA.isEnabled = Mock(return_value=True)
        self.p.console.getPlugin = Mock(return_value=mock_pluginA)
        self.p.cmd_disable(data="foo", client=mock_client, cmd=mock_command)
        self.p.console.say.assert_called_once_with("^7MockPlugin is now ^1OFF")
 def test_nominal_with_reason(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.spank("foo theReason")
     foo_player.kick.assert_called_once_with("theReason", "theReason", self.mock_client, silent=True)
 def test_nominal_with_reason_keyword(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.p.getReason = Mock(return_value="aReason")
     self.permban("foo theKeyword")
     foo_player.ban.assert_called_once_with("aReason", "theKeyword", self.mock_client)
 def test_player_is_higher_level(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 20
     self.mock_client.maxLevel = 0
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.warn("foo")
     self.p.getMessage.assert_called_once_with("warn_denied", self.mock_client.exactName, foo_player.exactName)
     assert not self.p.warnClient.called
Example #7
0
    def test_rebuild(self):
        mock_client = Mock(spec=Client, name="client")
        mock_client.maxLevel = 0
        mock_command = Mock(spec=Command, name="cmd")

        assert not self.p.console.clients.sync.called
        self.p.cmd_rebuild(data="", client=mock_client, cmd=mock_command)
        assert self.p.console.clients.sync.called
 def test_player_is_higher_level(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 20
     foo_player.maskGroup = None
     self.mock_client.maxLevel = 5
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.tempban("foo 3h")
     self.p.getMessage.assert_called_once_with("temp_ban_denied", self.mock_client.exactName, foo_player.exactName)
     assert not self.mock_client.tempban.called
 def test_nominal_with_keyword(self):
     self.p.console.time = Mock(return_value=16)
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     foo_player.var = Mock(return_value=ClientVar(None))
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.warn("foo thekeyword")
     self.p.warnClient.assert_called_once_with(foo_player, "thekeyword", self.mock_client)
Example #10
0
    def test_b3(self):
        self.p.config = Mock(name="config")
        self.p.config.getint = Mock(return_value=10)

        mock_client = Mock(spec=Client, name="client")
        mock_command = Mock(spec=Command, name="cmd")

        mock_client.maxLevel = 0
        self.p.cmd_b3(data="", client=mock_client, cmd=mock_command)
        assert mock_command.sayLoudOrPM.called

        mock_client.maxLevel = 20
        mock_client.reset_mock()
        b3.console.reset_mock()
        self.p.cmd_b3(data="", client=mock_client, cmd=mock_command)
        assert mock_command.sayLoudOrPM.called

        for param in (
            "poke",
            "expose",
            "stare",
            "stab",
            "triangulate",
            "bite",
            "fuck",
            "slap",
            "fight",
            "feed",
            "throw",
            "furniture",
            "indeed",
            "flog",
            "sexor",
            "hate",
            "smoke",
            "maul",
            "procreate",
            "shoot",
        ):
            mock_client.reset_mock()
            b3.console.reset_mock()
            self.p.cmd_b3(data=param, client=mock_client, cmd=mock_command)
            if not b3.console.say.called:
                self.fail("b3.console.say was not called for %r" % param)
Example #11
0
 def test_already_warned_recently(self):
     self.p.console.time = Mock(return_value=8)
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 0
     foo_player.var = Mock(return_value=ClientVar(5))
     self.mock_client.maxLevel = 20
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.warn("foo")
     self.mock_client.message.assert_called_once_with("^7Only one warning per 15 seconds can be issued")
     assert not self.p.warnClient.called
Example #12
0
 def test_player_is_higher_level_but_masked(self):
     foo_player = Mock(spec=Client, name="foo")
     foo_player.maxLevel = 20
     foo_player.maskGroup = Mock()
     foo_player.exactName = "Foo"
     self.mock_client.maxLevel = 5
     self.p.findClientPrompt = Mock(return_value=foo_player)
     self.tempban("foo 3h")
     self.mock_client.message.assert_called_once_with(
         "^7%s ^7is a masked higher level player, can't temp ban" % foo_player.exactName
     )
     assert not self.mock_client.tempban.called