def test_admin_dispatching():
    from botnet.modules.builtin.admin import Admin
    from modules.builtin.test_admin import admin_make_message, data4, send_data

    def make_admin_config(command_prefix='.'):
        config = {
            'module_config': {
                'botnet': {
                    'admin': {
                        'admins': ['nick4']
                    }
                }
            }
        }
        config = Config(config)
        return config

    admin_config = make_admin_config()

    t = Tester(Config())
    ad = Admin(admin_config)

    msg = make_privmsg('#channel :.test')
    message_in.send(None, msg=msg)
    assert t.launched_main
    assert t.launched_command
    assert t.launched_priv
    assert not t.launched_admin_command
    assert not t.launched_admin_priv

    msg = admin_make_message('nick4', '.test')
    message_in.send(None, msg=msg)
    send_data(data4)
    assert t.launched_admin_command
    assert t.launched_admin_priv
def test_help(msg_t):
    """Test help command. Only Meta module should respond to that command
    without any parameters."""
    msg = make_message('#channel :.help')

    re = BaseResponder(Config())
    message_in.send(None, msg=msg)

    assert not msg_t.msg
def test_help(msg_t):
    """Test help command. Only Meta module should respond to that command
    without any parameters."""
    msg = make_message('#channel :.help')

    re = BaseResponder(Config())
    message_in.send(None, msg=msg)

    assert not msg_t.msg
def test_dispatching_prefix():
    class PrefixTester(Tester):
        def get_command_prefix(self):
            return ':'

    msg = make_privmsg('#channel ::test arg1 arg2')
    t = PrefixTester(Config())
    message_in.send(None, msg=msg)
    assert_normal(t)
def test_dispatching_prefix():
    class PrefixTester(Tester):

        def get_command_prefix(self):
            return ':'

    msg = make_privmsg('#channel ::test arg1 arg2')
    t = PrefixTester(Config())
    message_in.send(None, msg=msg)
    assert_normal(t)
Beispiel #6
0
def test_quotes(msg_t, make_privmsg):
    dirname = os.path.dirname(os.path.realpath(__file__))
    filename = os.path.join(dirname, 'quotes')

    q = Quotes(Config())
    msg = make_privmsg('.lotr')

    message_in.send(None, msg=msg)
    assert not msg_t.msg

    q.config_set('lotr', filename)
    message_in.send(None, msg=msg)
    assert msg_t.msg
Beispiel #7
0
def test_quotes(msg_t, make_privmsg):
    dirname = os.path.dirname(os.path.realpath(__file__))
    filename = os.path.join(dirname, "quotes")

    q = Quotes(Config())
    msg = make_privmsg(".lotr")

    message_in.send(None, msg=msg)
    assert not msg_t.msg

    q.config_set("lotr", filename)
    message_in.send(None, msg=msg)
    assert msg_t.msg
Beispiel #8
0
def test_signal_freenode(msg_t):

    config = make_config()
    config['module_config']['botnet']['admin']['admins'] = ['nick4']
    a = Admin(config)
    t = AdminTrap()

    msg = admin_make_message('nick4', 'sth')
    message_in.send(None, msg=msg)
    assert len(a._whois_deferred) == 1
    assert not t.msg
    send_data(data4)
    assert t.msg
def test_decorator_dont_launch():
    class TestResponder(BaseResponder):

        def __init__(self, config):
            super(TestResponder, self).__init__(config)
            self.args = None

        @parse_command([('test_type', 1), ('something', '+')], launch_invalid=False)
        def command_test(self, msg, args):
            self.args = True

    msg = make_message('#channel :.test')
    re = TestResponder(Config())
    message_in.send(None, msg=msg)

    assert re.args is None
Beispiel #10
0
def test_whois_intertwined():
    config = make_config()
    a = Admin(config)

    for i in range(len(data1)):
        msg = Message()
        msg.from_string(data1[i])
        message_in.send(None, msg=msg)

        msg = Message()
        msg.from_string(data2[i])
        message_in.send(None, msg=msg)

    assert a._whois_cache.get('nick1')
    assert a._whois_cache.get('nick2')
    assert not a._whois_current
def test_decorator_dont_launch():
    class TestResponder(BaseResponder):
        def __init__(self, config):
            super(TestResponder, self).__init__(config)
            self.args = None

        @parse_command([('test_type', 1), ('something', '+')],
                       launch_invalid=False)
        def command_test(self, msg, args):
            self.args = True

    msg = make_message('#channel :.test')
    re = TestResponder(Config())
    message_in.send(None, msg=msg)

    assert re.args is None
def test_decorator():
    class TestResponder(BaseResponder):
        def __init__(self, config):
            super(TestResponder, self).__init__(config)
            self.args = None

        @parse_command([('test_type', 1), ('something', '+')])
        def command_test(self, msg, args):
            self.args = args

    msg = make_message('#channel :.test awesome one two three')
    re = TestResponder(Config())
    message_in.send(None, msg=msg)

    assert re.args.command == ['.test']
    assert re.args.test_type == ['awesome']
    assert re.args.something == ['one', 'two', 'three']
def test_decorator():
    class TestResponder(BaseResponder):

        def __init__(self, config):
            super(TestResponder, self).__init__(config)
            self.args = None

        @parse_command([('test_type', 1), ('something', '+')])
        def command_test(self, msg, args):
            self.args = args

    msg = make_message('#channel :.test awesome one two three')
    re = TestResponder(Config())
    message_in.send(None, msg=msg)

    assert re.args.command == ['.test']
    assert re.args.test_type == ['awesome']
    assert re.args.something == ['one', 'two', 'three']
def test_specific(msg_l):
    """Test help regarding a specific command."""
    class Responder(BaseResponder):
        def command_test(self, msg):
            pass

        def admin_command_test(self, msg):
            pass

    msg = make_message('#channel :.help test')

    re = Responder(Config())

    message_in.send(None, msg=msg)
    assert len(msg_l.msgs) == 1

    message_in.send(None, msg=msg)
    assert len(msg_l.msgs) == 2
def test_specific(msg_l):
    """Test help regarding a specific command."""

    class Responder(BaseResponder):

        def command_test(self, msg):
            pass

        def admin_command_test(self, msg):
            pass

    msg = make_message('#channel :.help test')

    re = Responder(Config())

    message_in.send(None, msg=msg)
    assert len(msg_l.msgs) == 1

    message_in.send(None, msg=msg)
    assert len(msg_l.msgs) == 2
def test_admin_dispatching():
    from botnet.modules.builtin.admin import Admin
    from modules.builtin.test_admin import admin_make_message, data4, send_data

    def make_admin_config(command_prefix='.'):
        config = {
            'module_config': {
                'botnet': {
                    'admin': {
                        'admins': [
                            'nick4'
                        ]
                    }
                }
            }
        }
        config = Config(config)
        return config

    admin_config = make_admin_config()

    t = Tester(Config())
    ad = Admin(admin_config)

    msg = make_privmsg('#channel :.test')
    message_in.send(None, msg=msg)
    assert t.launched_main
    assert t.launched_command
    assert t.launched_priv
    assert not t.launched_admin_command
    assert not t.launched_admin_priv

    msg = admin_make_message('nick4', '.test')
    message_in.send(None, msg=msg)
    send_data(data4)
    assert t.launched_admin_command
    assert t.launched_admin_priv
def test_dispatching():
    t = Tester(Config())
    msg = make_privmsg('#channel :.test')
    message_in.send(None, msg=msg)
    assert_normal(t)
def test_dispatching_args():
    msg = make_privmsg('#channel :.test arg1 arg2')
    t = Tester(Config())
    message_in.send(None, msg=msg)
    assert_normal(t)
Beispiel #19
0
def test_quotes_gone(make_privmsg):
    q = Quotes(Config())
    msg = make_privmsg('.gone')

    q.config_set('files.gone', 'gone')
    message_in.send(None, msg=msg)
Beispiel #20
0
def send_data(data):
    for text in data:
        msg = Message()
        msg.from_string(text)
        message_in.send(None, msg=msg)
def test_dispatching():
    t = Tester(Config())
    msg = make_privmsg('#channel :.test')
    message_in.send(None, msg=msg)
    assert_normal(t)
Beispiel #22
0
def test_quotes_gone(make_privmsg):
    q = Quotes(Config())
    msg = make_privmsg(".gone")

    q.config_set("gone", "gone")
    message_in.send(None, msg=msg)
def test_dispatching_args():
    msg = make_privmsg('#channel :.test arg1 arg2')
    t = Tester(Config())
    message_in.send(None, msg=msg)
    assert_normal(t)
Beispiel #24
0
def test_quotes_gone(make_privmsg):
    q = Quotes(Config())
    msg = make_privmsg('.gone')

    q.config_set('gone', 'gone')
    message_in.send(None, msg=msg)
Beispiel #25
0
 def f(msg):
     message_in.send(None, msg=msg)
Beispiel #26
0
 def f(msg):
     message_in.send(None, msg=msg)