コード例 #1
0
ファイル: test_core.py プロジェクト: mattvonrocketstein/helga
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
コード例 #2
0
ファイル: test_core.py プロジェクト: denete/helga
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