| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from neutron_lib.plugins import directory |
| 14 |
from neutron_lib.tests import _base as base |
| 15 |
|
| 16 |
|
| 17 |
def fake_plugin(): |
| 18 |
pass |
| 19 |
|
| 20 |
|
| 21 |
class DirectoryTestCase(base.BaseTestCase): |
| 22 |
|
| 23 |
def test__create_plugin_directory(self): |
| 24 |
self.assertIsNotNone(directory._create_plugin_directory()) |
| 25 |
|
| 26 |
def test__get_plugin_directory(self): |
| 27 |
self.assertIsNotNone(directory._get_plugin_directory()) |
| 28 |
|
| 29 |
def test_add_plugin(self): |
| 30 |
directory.add_plugin('foo', fake_plugin) |
| 31 |
self.assertIn('foo', directory.get_plugins()) |
| 32 |
|
| 33 |
def test_get_plugin_core_none(self): |
| 34 |
self.assertIsNone(directory.get_plugin()) |
| 35 |
|
| 36 |
def test_get_plugin_alias_none(self): |
| 37 |
self.assertIsNone(directory.get_plugin('foo')) |
| 38 |
|
| 39 |
def test_get_plugin_core(self): |
| 40 |
directory.add_plugin('CORE', fake_plugin) |
| 41 |
self.assertIsNotNone(directory.get_plugin()) |
| 42 |
|
| 43 |
def test_get_plugin_alias(self): |
| 44 |
directory.add_plugin('foo', fake_plugin) |
| 45 |
self.assertIsNotNone(directory.get_plugin('foo')) |
| 46 |
|
| 47 |
def test_get_plugins_none(self): |
| 48 |
self.assertFalse(directory.get_plugins()) |
| 49 |
|
| 50 |
def test_get_unique_plugins_none(self): |
| 51 |
self.assertFalse(directory.get_unique_plugins()) |
| 52 |
|
| 53 |
def test_get_plugins(self): |
| 54 |
directory.add_plugin('CORE', fake_plugin) |
| 55 |
self.assertIsNotNone(directory.get_plugins()) |
| 56 |
|
| 57 |
def test_get_unique_plugins(self): |
| 58 |
directory.add_plugin('foo1', fake_plugin) |
| 59 |
directory.add_plugin('foo2', fake_plugin) |
| 60 |
self.assertEqual(1, len(directory.get_unique_plugins())) |
| 61 |
|
| 62 |
def test_is_loaded(self): |
| 63 |
self.assertFalse(directory.is_loaded()) |
| 64 |
directory.add_plugin('foo1', fake_plugin) |
| 65 |
self.assertTrue(directory.is_loaded()) |
| 66 |
|
| 67 |
|
| 68 |
class PluginDirectoryTestCase(base.BaseTestCase): |
| 69 |
|
| 70 |
def setUp(self): |
| 71 |
super().setUp() |
| 72 |
self.plugin_directory = directory._PluginDirectory() |
| 73 |
|
| 74 |
def test_add_plugin(self): |
| 75 |
self.plugin_directory.add_plugin('foo', 'bar') |
| 76 |
self.assertEqual(1, len(self.plugin_directory._plugins)) |
| 77 |
|
| 78 |
def test_get_plugin_not_found(self): |
| 79 |
self.assertIsNone(self.plugin_directory.get_plugin('foo')) |
| 80 |
|
| 81 |
def test_get_plugin_found(self): |
| 82 |
self.plugin_directory._plugins = {'foo': lambda *x, **y: 'bar'} |
| 83 |
plugin = self.plugin_directory.get_plugin('foo') |
| 84 |
self.assertEqual('bar', plugin()) |
| 85 |
|
| 86 |
def test_plugins(self): |
| 87 |
self.plugin_directory._plugins = {'foo': lambda *x, **y: 'bar'} |
| 88 |
self.assertIsNotNone(self.plugin_directory.plugins) |
| 89 |
|
| 90 |
def test_unique_plugins(self): |
| 91 |
self.plugin_directory._plugins = { |
| 92 |
'foo1': fake_plugin, |
| 93 |
'foo2': fake_plugin, |
| 94 |
} |
| 95 |
self.assertEqual(1, len(self.plugin_directory.unique_plugins)) |
| 96 |
|
| 97 |
def test_is_loaded(self): |
| 98 |
self.assertFalse(self.plugin_directory.is_loaded) |
| 99 |
self.plugin_directory._plugins = {'foo': lambda *x, **y: 'bar'} |
| 100 |
self.assertTrue(self.plugin_directory.is_loaded) |