mirror of
https://github.com/ChristianLight/tutor.git
synced 2025-01-11 17:38:46 +00:00
Fix unit tests in the presence of local yaml plugins
This commit is contained in:
parent
aef0ede0ec
commit
1b1d21c7e7
@ -1,5 +1,5 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import unittest.mock
|
from unittest.mock import patch
|
||||||
|
|
||||||
from tutor import config as tutor_config
|
from tutor import config as tutor_config
|
||||||
from tutor import exceptions
|
from tutor import exceptions
|
||||||
@ -10,22 +10,22 @@ class PluginsTests(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
plugins.Plugins.clear()
|
plugins.Plugins.clear()
|
||||||
|
|
||||||
def test_iter_installed(self):
|
@patch.object(plugins.DictPlugin, "iter_installed", return_value=[])
|
||||||
with unittest.mock.patch.object(
|
def test_iter_installed(self, _dict_plugin_iter_installed):
|
||||||
plugins.pkg_resources, "iter_entry_points", return_value=[]
|
with patch.object(plugins.pkg_resources, "iter_entry_points", return_value=[]):
|
||||||
):
|
|
||||||
self.assertEqual([], list(plugins.iter_installed()))
|
self.assertEqual([], list(plugins.iter_installed()))
|
||||||
|
|
||||||
def test_is_installed(self):
|
def test_is_installed(self):
|
||||||
self.assertFalse(plugins.is_installed("dummy"))
|
self.assertFalse(plugins.is_installed("dummy"))
|
||||||
|
|
||||||
def test_extra_installed(self):
|
@patch.object(plugins.DictPlugin, "iter_installed", return_value=[])
|
||||||
|
def test_extra_installed(self, _dict_plugin_iter_installed):
|
||||||
plugin1 = plugins.BasePlugin("plugin1", None)
|
plugin1 = plugins.BasePlugin("plugin1", None)
|
||||||
plugin2 = plugins.BasePlugin("plugin2", None)
|
plugin2 = plugins.BasePlugin("plugin2", None)
|
||||||
|
|
||||||
plugins.OfficialPlugin.INSTALLED.append(plugin1)
|
plugins.OfficialPlugin.INSTALLED.append(plugin1)
|
||||||
plugins.OfficialPlugin.INSTALLED.append(plugin2)
|
plugins.OfficialPlugin.INSTALLED.append(plugin2)
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.EntrypointPlugin, "iter_installed", return_value=[plugin1],
|
plugins.EntrypointPlugin, "iter_installed", return_value=[plugin1],
|
||||||
):
|
):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -34,21 +34,21 @@ class PluginsTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_enable(self):
|
def test_enable(self):
|
||||||
config = {plugins.CONFIG_KEY: []}
|
config = {plugins.CONFIG_KEY: []}
|
||||||
with unittest.mock.patch.object(plugins, "is_installed", return_value=True):
|
with patch.object(plugins, "is_installed", return_value=True):
|
||||||
plugins.enable(config, "plugin2")
|
plugins.enable(config, "plugin2")
|
||||||
plugins.enable(config, "plugin1")
|
plugins.enable(config, "plugin1")
|
||||||
self.assertEqual(["plugin1", "plugin2"], config[plugins.CONFIG_KEY])
|
self.assertEqual(["plugin1", "plugin2"], config[plugins.CONFIG_KEY])
|
||||||
|
|
||||||
def test_enable_twice(self):
|
def test_enable_twice(self):
|
||||||
config = {plugins.CONFIG_KEY: []}
|
config = {plugins.CONFIG_KEY: []}
|
||||||
with unittest.mock.patch.object(plugins, "is_installed", return_value=True):
|
with patch.object(plugins, "is_installed", return_value=True):
|
||||||
plugins.enable(config, "plugin1")
|
plugins.enable(config, "plugin1")
|
||||||
plugins.enable(config, "plugin1")
|
plugins.enable(config, "plugin1")
|
||||||
self.assertEqual(["plugin1"], config[plugins.CONFIG_KEY])
|
self.assertEqual(["plugin1"], config[plugins.CONFIG_KEY])
|
||||||
|
|
||||||
def test_enable_not_installed_plugin(self):
|
def test_enable_not_installed_plugin(self):
|
||||||
config = {"PLUGINS": []}
|
config = {"PLUGINS": []}
|
||||||
with unittest.mock.patch.object(plugins, "is_installed", return_value=False):
|
with patch.object(plugins, "is_installed", return_value=False):
|
||||||
self.assertRaises(exceptions.TutorError, plugins.enable, config, "plugin1")
|
self.assertRaises(exceptions.TutorError, plugins.enable, config, "plugin1")
|
||||||
|
|
||||||
def test_disable(self):
|
def test_disable(self):
|
||||||
@ -60,7 +60,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
patches = {"patch1": "Hello {{ ID }}"}
|
patches = {"patch1": "Hello {{ ID }}"}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -69,7 +69,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
self.assertEqual([("plugin1", "Hello {{ ID }}")], patches)
|
self.assertEqual([("plugin1", "Hello {{ ID }}")], patches)
|
||||||
|
|
||||||
def test_plugin_without_patches(self):
|
def test_plugin_without_patches(self):
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", None)],
|
return_value=[plugins.BasePlugin("plugin1", None)],
|
||||||
@ -88,7 +88,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
"defaults": {"PARAM4": "value4"},
|
"defaults": {"PARAM4": "value4"},
|
||||||
}
|
}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -112,7 +112,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
config = {"set": {"ID": "newid"}}
|
config = {"set": {"ID": "newid"}}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -127,7 +127,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
config = {"set": {"PARAM1": "{{ 128|random_string }}"}}
|
config = {"set": {"PARAM1": "{{ 128|random_string }}"}}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -142,7 +142,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
config = {"defaults": {"PARAM2": "{{ PARAM1 }}"}}
|
config = {"defaults": {"PARAM2": "{{ PARAM1 }}"}}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -156,14 +156,14 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
config = {"add": {"PARAM1": "{{ 10|random_string }}"}}
|
config = {"add": {"PARAM1": "{{ 10|random_string }}"}}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
):
|
):
|
||||||
tutor_config.load_plugins(config, {})
|
tutor_config.load_plugins(config, {})
|
||||||
value1 = config["PLUGIN1_PARAM1"]
|
value1 = config["PLUGIN1_PARAM1"]
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
class plugin1:
|
class plugin1:
|
||||||
hooks = {"init": ["myclient"]}
|
hooks = {"init": ["myclient"]}
|
||||||
|
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_enabled",
|
"iter_enabled",
|
||||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||||
@ -193,7 +193,7 @@ class PluginsTests(unittest.TestCase):
|
|||||||
plugins1 = plugins.Plugins(config)
|
plugins1 = plugins.Plugins(config)
|
||||||
self.assertEqual(0, len(list(plugins1.iter_enabled())))
|
self.assertEqual(0, len(list(plugins1.iter_enabled())))
|
||||||
config["PLUGINS"].append("plugin1")
|
config["PLUGINS"].append("plugin1")
|
||||||
with unittest.mock.patch.object(
|
with patch.object(
|
||||||
plugins.Plugins,
|
plugins.Plugins,
|
||||||
"iter_installed",
|
"iter_installed",
|
||||||
return_value=[plugins.BasePlugin("plugin1", None)],
|
return_value=[plugins.BasePlugin("plugin1", None)],
|
||||||
|
Loading…
Reference in New Issue
Block a user