예제 #1
0
 def test_bad_get_north_plugin_config(self, exc_name, log_exc_name, msg):
     with patch.object(_logger, log_exc_name) as patch_log_exc:
         with patch.object(common,
                           'load_and_fetch_python_plugin_info',
                           side_effect=[exc_name]):
             PluginDiscovery.get_plugin_config("http", "north", False)
     assert 1 == patch_log_exc.call_count
     args, kwargs = patch_log_exc.call_args
     assert msg in args[0]
예제 #2
0
    def test_bad_get_north_plugin_config(self, exc_name, log_exc_name, msg):
        mock = MagicMock()
        attrs = {"plugin_info.side_effect": exc_name}
        mock.configure_mock(**attrs)

        with patch.object(_logger, log_exc_name) as patch_log_exc:
            with patch('builtins.__import__', return_value=mock):
                PluginDiscovery.get_plugin_config("http", "north", False)
        assert 1 == patch_log_exc.call_count
        args, kwargs = patch_log_exc.call_args
        assert msg in args[0]
예제 #3
0
 def test_deprecated_python_plugins(self, info, warn_count, is_config=True):
     with patch.object(_logger, "warning") as patch_log_warn:
         with patch.object(common,
                           'load_and_fetch_python_plugin_info',
                           side_effect=[info]):
             PluginDiscovery.get_plugin_config(info['name'], info['type'],
                                               is_config)
     assert warn_count == patch_log_warn.call_count
     if warn_count:
         args, kwargs = patch_log_warn.call_args
         assert '"{}" plugin is deprecated'.format(info['name']) == args[0]
예제 #4
0
    def test_bad_get_plugin_config(self):
        mock_plugin_info = {
            'name': "HTTP",
            'version': "1.0.0",
            'type': "north",
            'interface': "1.0.0",
            'config': {
                'plugin': {
                    'description': "HTTP north plugin",
                    'type': 'string',
                    'default': 'http-north'
                }
            }
        }

        mock = MagicMock()
        attrs = {"plugin_info.side_effect": [mock_plugin_info]}
        mock.configure_mock(**attrs)
        with patch.object(_logger, "warning") as patch_log_warn:
            with patch('builtins.__import__', return_value=mock):
                actual = PluginDiscovery.get_plugin_config(
                    "http-north", "south", False)
                assert actual is None
        patch_log_warn.assert_called_once_with(
            'Plugin http-north is discarded due to invalid type')
예제 #5
0
 def test_get_plugin_config(self, info, expected, is_config):
     with patch.object(common,
                       'load_and_fetch_python_plugin_info',
                       side_effect=[info]):
         actual = PluginDiscovery.get_plugin_config("modbus", "south",
                                                    is_config)
         assert expected == actual
예제 #6
0
 def test_get_plugin_config(self, info, expected, is_config):
     mock = MagicMock()
     attrs = {"plugin_info.side_effect": [info]}
     mock.configure_mock(**attrs)
     with patch('builtins.__import__', return_value=mock):
         actual = PluginDiscovery.get_plugin_config("modbus", "south",
                                                    is_config)
         assert expected == actual
예제 #7
0
 def test_bad_get_plugin_config(self):
     mock_plugin_info = {
         'name': "HTTP",
         'version': "1.0.0",
         'type': "north",
         'interface': "1.0.0",
         'config': {
             'plugin': {
                 'description': "HTTP north plugin",
                 'type': 'string',
                 'default': 'http-north'
             }
         }
     }
     with patch.object(_logger, "warning") as patch_log_warn:
         with patch.object(common,
                           'load_and_fetch_python_plugin_info',
                           side_effect=[mock_plugin_info]):
             actual = PluginDiscovery.get_plugin_config(
                 "http-north", "south", False)
             assert actual is None
     patch_log_warn.assert_called_once_with(
         'Plugin http-north is discarded due to invalid type')