mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 21:16:46 +00:00
Move broken plugin samples to disabled folders (#5642)
* move broken samples to disabled folders * ensure there are no name clashes * added option to collect plugins on load * made tests aware of reloads * reverted test name change * added tests for broken samples * fixed type signature
This commit is contained in:
parent
46b0d77418
commit
e767516c80
1
InvenTree/plugin/broken/__init__.py
Normal file
1
InvenTree/plugin/broken/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# InvenTree plugin directory
|
@ -202,12 +202,13 @@ class PluginsRegistry:
|
|||||||
|
|
||||||
logger.info('Finished unloading plugins')
|
logger.info('Finished unloading plugins')
|
||||||
|
|
||||||
def reload_plugins(self, full_reload: bool = False, force_reload: bool = False):
|
def reload_plugins(self, full_reload: bool = False, force_reload: bool = False, collect: bool = False):
|
||||||
"""Safely reload.
|
"""Safely reload.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
full_reload (bool, optional): Reload everything - including plugin mechanism. Defaults to False.
|
||||||
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
force_reload (bool, optional): Also reload base apps. Defaults to False.
|
||||||
|
collect (bool, optional): Collect plugins before reloading. Defaults to False.
|
||||||
"""
|
"""
|
||||||
# Do not reload when currently loading
|
# Do not reload when currently loading
|
||||||
if self.is_loading:
|
if self.is_loading:
|
||||||
@ -216,6 +217,10 @@ class PluginsRegistry:
|
|||||||
logger.info('Start reloading plugins')
|
logger.info('Start reloading plugins')
|
||||||
|
|
||||||
with maintenance_mode_on():
|
with maintenance_mode_on():
|
||||||
|
if collect:
|
||||||
|
logger.info('Collecting plugins')
|
||||||
|
self.plugin_modules = self.collect_plugins()
|
||||||
|
|
||||||
self.plugins_loaded = False
|
self.plugins_loaded = False
|
||||||
self.unload_plugins(force_reload=force_reload)
|
self.unload_plugins(force_reload=force_reload)
|
||||||
self.plugins_loaded = True
|
self.plugins_loaded = True
|
||||||
|
@ -195,7 +195,7 @@ class InvenTreePluginTests(TestCase):
|
|||||||
class RegistryTests(TestCase):
|
class RegistryTests(TestCase):
|
||||||
"""Tests for registry loading methods."""
|
"""Tests for registry loading methods."""
|
||||||
|
|
||||||
def mockDir(self) -> None:
|
def mockDir(self) -> str:
|
||||||
"""Returns path to mock dir"""
|
"""Returns path to mock dir"""
|
||||||
return str(Path(__file__).parent.joinpath('mock').absolute())
|
return str(Path(__file__).parent.joinpath('mock').absolute())
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ class RegistryTests(TestCase):
|
|||||||
envs = {'INVENTREE_PLUGIN_TEST_DIR': directory}
|
envs = {'INVENTREE_PLUGIN_TEST_DIR': directory}
|
||||||
with mock.patch.dict(os.environ, envs):
|
with mock.patch.dict(os.environ, envs):
|
||||||
# Reload to redicsover plugins
|
# Reload to redicsover plugins
|
||||||
registry.reload_plugins(full_reload=True)
|
registry.reload_plugins(full_reload=True, collect=True)
|
||||||
|
|
||||||
# Depends on the meta set in InvenTree/plugin/mock/simple:SimplePlugin
|
# Depends on the meta set in InvenTree/plugin/mock/simple:SimplePlugin
|
||||||
plg = registry.get_plugin('simple')
|
plg = registry.get_plugin('simple')
|
||||||
@ -252,9 +252,29 @@ class RegistryTests(TestCase):
|
|||||||
subprocess.check_output('pip install inventree-zapier'.split())
|
subprocess.check_output('pip install inventree-zapier'.split())
|
||||||
|
|
||||||
# Reload to discover plugin
|
# Reload to discover plugin
|
||||||
registry.reload_plugins(full_reload=True)
|
registry.reload_plugins(full_reload=True, collect=True)
|
||||||
|
|
||||||
# Test that plugin was installed
|
# Test that plugin was installed
|
||||||
plg = registry.get_plugin('zapier')
|
plg = registry.get_plugin('zapier')
|
||||||
self.assertEqual(plg.slug, 'zapier')
|
self.assertEqual(plg.slug, 'zapier')
|
||||||
self.assertEqual(plg.name, 'inventree_zapier')
|
self.assertEqual(plg.name, 'inventree_zapier')
|
||||||
|
|
||||||
|
def test_broken_samples(self):
|
||||||
|
"""Test that the broken samples trigger reloads."""
|
||||||
|
|
||||||
|
# In the base setup there are no errors
|
||||||
|
self.assertEqual(len(registry.errors), 1)
|
||||||
|
|
||||||
|
# Reload the registry with the broken samples dir
|
||||||
|
brokenDir = str(Path(__file__).parent.joinpath('broken').absolute())
|
||||||
|
with mock.patch.dict(os.environ, {'INVENTREE_PLUGIN_TEST_DIR': brokenDir}):
|
||||||
|
# Reload to redicsover plugins
|
||||||
|
registry.reload_plugins(full_reload=True, collect=True)
|
||||||
|
|
||||||
|
self.assertEqual(len(registry.errors), 3)
|
||||||
|
# There should be at least one discovery error in the module `broken_file`
|
||||||
|
self.assertTrue(len(registry.errors.get('discovery')) > 0)
|
||||||
|
self.assertEqual(registry.errors.get('discovery')[0]['broken_file'], "name 'bb' is not defined")
|
||||||
|
# There should be at least one load error with an intentional KeyError
|
||||||
|
self.assertTrue(len(registry.errors.get('load')) > 0)
|
||||||
|
self.assertEqual(registry.errors.get('load')[0]['broken_sample'], "'This is a dummy error'")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user