mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-12-12 06:07:56 +00:00
More robust plugin/env config checking
This commit is contained in:
parent
7fbba104a1
commit
1e995aaf1a
@ -123,3 +123,14 @@ class EnvTests(unittest.TestCase):
|
||||
self.assertTrue(os.path.exists(dst_rendered))
|
||||
with open(dst_rendered) as f:
|
||||
self.assertEqual("Hello my ID is abcd", f.read())
|
||||
|
||||
def test_renderer_is_reset_on_config_change(self):
|
||||
config = {"PLUGINS": []}
|
||||
env1 = env.Renderer.environment(config)
|
||||
config["PLUGINS"].append("minio")
|
||||
env2 = env.Renderer.environment(config)
|
||||
|
||||
self.assertNotIn(
|
||||
"minio/hooks/mino-client/pre-init", env1.loader.list_templates()
|
||||
)
|
||||
self.assertIn("minio/hooks/minio-client/pre-init", env2.loader.list_templates())
|
||||
|
@ -189,3 +189,11 @@ class PluginsTests(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
[("plugin1", "/tmp/templates")], list(plugins.iter_templates({}))
|
||||
)
|
||||
|
||||
def test_plugins_are_updated_on_config_change(self):
|
||||
config = {"PLUGINS": []}
|
||||
instance1 = plugins.Plugins(config)
|
||||
self.assertEqual(0, len(list(instance1.iter_enabled())))
|
||||
config["PLUGINS"].append("minio")
|
||||
instance2 = plugins.Plugins(config)
|
||||
self.assertEqual(1, len(list(instance2.iter_enabled())))
|
||||
|
@ -1,4 +1,5 @@
|
||||
import codecs
|
||||
from copy import deepcopy
|
||||
import os
|
||||
import shutil
|
||||
|
||||
@ -22,7 +23,6 @@ class Renderer:
|
||||
@classmethod
|
||||
def environment(cls, config):
|
||||
if cls.ENVIRONMENT_CONFIG != config:
|
||||
cls.ENVIRONMENT_CONFIG = config
|
||||
template_roots = [TEMPLATES_ROOT]
|
||||
for _, plugin_templates in plugins.iter_templates(config):
|
||||
template_roots.append(plugin_templates)
|
||||
@ -35,6 +35,8 @@ class Renderer:
|
||||
environment.filters["reverse_host"] = utils.reverse_host
|
||||
environment.filters["walk_templates"] = walk_templates
|
||||
environment.globals["TUTOR_VERSION"] = __version__
|
||||
|
||||
cls.ENVIRONMENT_CONFIG = deepcopy(config)
|
||||
cls.ENVIRONMENT = environment
|
||||
|
||||
return cls.ENVIRONMENT
|
||||
@ -42,6 +44,7 @@ class Renderer:
|
||||
@classmethod
|
||||
def reset(cls):
|
||||
cls.ENVIRONMENT = None
|
||||
cls.ENVIRONMENT_CONFIG = None
|
||||
|
||||
@classmethod
|
||||
def render_str(cls, config, text):
|
||||
|
@ -1,3 +1,4 @@
|
||||
from copy import deepcopy
|
||||
import pkg_resources
|
||||
|
||||
from . import exceptions
|
||||
@ -42,7 +43,7 @@ class Plugins:
|
||||
EXTRA_INSTALLED = {}
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.config = deepcopy(config)
|
||||
self.patches = {}
|
||||
self.hooks = {}
|
||||
self.templates = {}
|
||||
|
Loading…
Reference in New Issue
Block a user