mirror of
https://github.com/ChristianLight/tutor.git
synced 2025-01-11 09:35:06 +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.mock
|
||||
from unittest.mock import patch
|
||||
|
||||
from tutor import config as tutor_config
|
||||
from tutor import exceptions
|
||||
@ -10,22 +10,22 @@ class PluginsTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
plugins.Plugins.clear()
|
||||
|
||||
def test_iter_installed(self):
|
||||
with unittest.mock.patch.object(
|
||||
plugins.pkg_resources, "iter_entry_points", return_value=[]
|
||||
):
|
||||
@patch.object(plugins.DictPlugin, "iter_installed", return_value=[])
|
||||
def test_iter_installed(self, _dict_plugin_iter_installed):
|
||||
with patch.object(plugins.pkg_resources, "iter_entry_points", return_value=[]):
|
||||
self.assertEqual([], list(plugins.iter_installed()))
|
||||
|
||||
def test_is_installed(self):
|
||||
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)
|
||||
plugin2 = plugins.BasePlugin("plugin2", None)
|
||||
|
||||
plugins.OfficialPlugin.INSTALLED.append(plugin1)
|
||||
plugins.OfficialPlugin.INSTALLED.append(plugin2)
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.EntrypointPlugin, "iter_installed", return_value=[plugin1],
|
||||
):
|
||||
self.assertEqual(
|
||||
@ -34,21 +34,21 @@ class PluginsTests(unittest.TestCase):
|
||||
|
||||
def test_enable(self):
|
||||
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, "plugin1")
|
||||
self.assertEqual(["plugin1", "plugin2"], config[plugins.CONFIG_KEY])
|
||||
|
||||
def test_enable_twice(self):
|
||||
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")
|
||||
self.assertEqual(["plugin1"], config[plugins.CONFIG_KEY])
|
||||
|
||||
def test_enable_not_installed_plugin(self):
|
||||
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")
|
||||
|
||||
def test_disable(self):
|
||||
@ -60,7 +60,7 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
patches = {"patch1": "Hello {{ ID }}"}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -69,7 +69,7 @@ class PluginsTests(unittest.TestCase):
|
||||
self.assertEqual([("plugin1", "Hello {{ ID }}")], patches)
|
||||
|
||||
def test_plugin_without_patches(self):
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", None)],
|
||||
@ -88,7 +88,7 @@ class PluginsTests(unittest.TestCase):
|
||||
"defaults": {"PARAM4": "value4"},
|
||||
}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -112,7 +112,7 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
config = {"set": {"ID": "newid"}}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -127,7 +127,7 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
config = {"set": {"PARAM1": "{{ 128|random_string }}"}}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -142,7 +142,7 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
config = {"defaults": {"PARAM2": "{{ PARAM1 }}"}}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -156,14 +156,14 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
config = {"add": {"PARAM1": "{{ 10|random_string }}"}}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
):
|
||||
tutor_config.load_plugins(config, {})
|
||||
value1 = config["PLUGIN1_PARAM1"]
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -179,7 +179,7 @@ class PluginsTests(unittest.TestCase):
|
||||
class plugin1:
|
||||
hooks = {"init": ["myclient"]}
|
||||
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_enabled",
|
||||
return_value=[plugins.BasePlugin("plugin1", plugin1)],
|
||||
@ -193,7 +193,7 @@ class PluginsTests(unittest.TestCase):
|
||||
plugins1 = plugins.Plugins(config)
|
||||
self.assertEqual(0, len(list(plugins1.iter_enabled())))
|
||||
config["PLUGINS"].append("plugin1")
|
||||
with unittest.mock.patch.object(
|
||||
with patch.object(
|
||||
plugins.Plugins,
|
||||
"iter_installed",
|
||||
return_value=[plugins.BasePlugin("plugin1", None)],
|
||||
|
Loading…
Reference in New Issue
Block a user