示例#1
0
 def test_does_not_implement(self):
     with ExitStack() as resources:
         system_path = resources.enter_context(TemporaryDirectory())
         fake_plugin_config = {
             'path': system_path,
             'enabled': 'yes',
             'class': 'ExamplePlugin',
         }
         log_mock = resources.enter_context(
             patch('mailman.plugins.initialize.log'))
         fake_mailman_config = SimpleNamespace(
             plugin_configs=[('example', fake_plugin_config)],
             plugins=[],
         )
         resources.enter_context(
             patch('mailman.plugins.initialize.config',
                   fake_mailman_config))
         resources.enter_context(
             patch(
                 'mailman.plugins.initialize.call_name',
                 # object() does not implement IPlugin.
                 return_value=object()))
         initialize()
         log_mock.error.assert_called_once_with(
             'Plugin class does not implement IPlugin: ExamplePlugin')
         self.assertNotIn(system_path, sys.path)
示例#2
0
 def test_adds_plugins_to_config(self):
     with ExitStack() as resources:
         system_path = resources.enter_context(TemporaryDirectory())
         fake_plugin_config = {
             'path': system_path,
             'enabled': 'yes',
             'class': 'ExamplePlugin',
         }
         fake_mailman_config = SimpleNamespace(
             plugin_configs=[('example', fake_plugin_config)],
             plugins={},
         )
         resources.enter_context(
             patch('mailman.plugins.initialize.config',
                   fake_mailman_config))
         testable_plugin = TestablePlugin()
         resources.enter_context(
             patch(
                 'mailman.plugins.initialize.call_name',
                 # object() does not implement IPlugin.
                 return_value=testable_plugin))
         initialize()
         self.assertIn('example', fake_mailman_config.plugins)
         self.assertEqual(fake_mailman_config.plugins['example'],
                          testable_plugin)
示例#3
0
 def test_not_enabled(self):
     with ExitStack() as resources:
         fake_plugin_config = {
             'path': '/does/not/exist',
             'enabled': 'no',
             'class': 'ExamplePlugin',
             }
         log_mock = resources.enter_context(
             patch('mailman.plugins.initialize.log'))
         fake_mailman_config = SimpleNamespace(
             plugin_configs=[('example', fake_plugin_config)],
             plugins={},
             )
         resources.enter_context(patch(
             'mailman.plugins.initialize.config', fake_mailman_config))
         initialize()
         log_mock.info.assert_called_once_with(
             'Plugin not enabled, or empty class path: example')
示例#4
0
 def test_duplicate_plugin_name(self):
     with ExitStack() as resources:
         system_path = resources.enter_context(TemporaryDirectory())
         fake_plugin_config = {
             'path': system_path,
             'enabled': 'yes',
             'class': 'ExamplePlugin',
             }
         log_mock = resources.enter_context(
             patch('mailman.plugins.initialize.log'))
         fake_mailman_config = SimpleNamespace(
             plugin_configs=[('example', fake_plugin_config)],
             plugins=['example'],
             )
         resources.enter_context(patch(
             'mailman.plugins.initialize.config', fake_mailman_config))
         initialize()
         log_mock.error.assert_called_once_with(
             'Duplicate plugin name: example')