Exemplo n.º 1
0
class ControlExtensionTestCase(TestCase):

    def setUp(self):
        self.ctl = ControlExtension(Mock(), mock_bot())

    def test_handle_message_calls_extension_list(self):
        self.ctl.list_extensions = Mock()
        self.ctl.handle_message({'extension': True, 'list': True}, Mock())
        assert self.ctl.list_extensions.called

    def test_handle_message_calls_extension_disable(self):
        self.ctl.disable_extension = Mock()
        self.ctl.handle_message({'extension': True, 'disable': True, '<ext>': 'foo'}, Mock())
        assert self.ctl.disable_extension.called

    def test_list_extensions(self):
        self.ctl.registry.get_enabled.return_value = set(['foo'])

        assert self.ctl.list_extensions('bar') == 'Extensions on this channel: foo'

    @patch('helga.extensions.core.db')
    def test_disable_extension_disables(self, db):
        self.ctl.registry.disable.return_value = True

        assert self.ctl.disable_extension('foo', 'bar') in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_disable_extension_invalid_ext_name(self, db):
        self.ctl.registry.disable.return_value = False

        assert self.ctl.disable_extension('foo', 'bar') not in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_enable_extension_disables(self, db):
        self.ctl.registry.disable.return_value = True

        assert self.ctl.disable_extension('foo', 'bar') in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_enable_extension_invalid_ext_name(self, db):
        self.ctl.registry.enable.return_value = False

        assert self.ctl.enable_extension('foo', 'bar') not in self.ctl.acks
Exemplo n.º 2
0
    def load(self):
        for path in getattr(settings, 'EXTENSIONS', []):
            logger.debug('Loading extension extension %s' % path)

            try:
                module = __import__(*self._make_import_args(path))
            except ImportError:
                logger.warning('Cannot import extension %s' % path)
                continue

            self.load_module_members(module)

        # Core loading
        self.core = set([
            ControlExtension(self, self.bot),
            HelpExtension(self, self.bot),
            IgnoreExtension(self.bot),
        ])
Exemplo n.º 3
0
 def setUp(self):
     self.ctl = ControlExtension(Mock(), mock_bot())
Exemplo n.º 4
0
class ControlExtensionTestCase(TestCase):

    def setUp(self):
        self.ctl = ControlExtension(Mock(), mock_bot())

    def test_handle_message_calls_extension_list(self):
        self.ctl.list_extensions = Mock()
        self.ctl.handle_message({'extension': True, 'list': True}, Mock())
        assert self.ctl.list_extensions.called

    def test_handle_message_calls_extension_disable(self):
        self.ctl.disable_extension = Mock()
        self.ctl.handle_message({'extension': True, 'disable': True, '<ext>': 'foo'}, Mock())
        assert self.ctl.disable_extension.called

    def test_list_extensions_enabled(self):
        self.ctl.registry.get_enabled.return_value = set(['foo'])

        assert self.ctl.list_extensions('bar', type='enabled') == 'Enabled extensions on bar: foo'

    def test_list_extensions_disabled(self):
        self.ctl.registry.get_disabled.return_value = set(['foo'])

        assert self.ctl.list_extensions('bar', type='disabled') == 'Disabled extensions on bar: foo'

    def test_list_extensions(self):
        # Test that we get both
        self.ctl.registry.get_enabled.return_value = set(['foo'])
        self.ctl.registry.get_disabled.return_value = set(['baz'])

        ret = self.ctl.list_extensions('bar')
        assert ret == ['Enabled extensions on bar: foo', 'Disabled extensions on bar: baz']

    def test_list_extensions_all_for_unknown_type(self):
        # Test that we get both
        self.ctl.registry.get_enabled.return_value = set(['foo'])
        self.ctl.registry.get_disabled.return_value = set(['baz'])

        ret = self.ctl.list_extensions('bar', type='foobar')
        assert ret == ['Enabled extensions on bar: foo', 'Disabled extensions on bar: baz']

    @patch('helga.extensions.core.db')
    def test_disable_extension_disables(self, db):
        self.ctl.registry.disable.return_value = True

        assert self.ctl.disable_extension('foo', 'bar') in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_disable_extension_invalid_ext_name(self, db):
        self.ctl.registry.disable.return_value = False

        assert self.ctl.disable_extension('foo', 'bar') not in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_enable_extension_disables(self, db):
        self.ctl.registry.disable.return_value = True

        assert self.ctl.disable_extension('foo', 'bar') in self.ctl.acks

    @patch('helga.extensions.core.db')
    def test_enable_extension_invalid_ext_name(self, db):
        self.ctl.registry.enable.return_value = False

        assert self.ctl.enable_extension('foo', 'bar') not in self.ctl.acks