From 5d4e8fcd4c8ccba98d48e8294129fa7cfe6766b6 Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Tue, 5 Nov 2024 15:29:52 +0100 Subject: [PATCH 1/2] Fix flappy plugin loading tests --- api/src/reportcreator_api/conf/plugins.py | 2 +- api/src/reportcreator_api/tests/test_plugins.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/src/reportcreator_api/conf/plugins.py b/api/src/reportcreator_api/conf/plugins.py index 1c2244b8..7cb9dc2f 100644 --- a/api/src/reportcreator_api/conf/plugins.py +++ b/api/src/reportcreator_api/conf/plugins.py @@ -90,7 +90,7 @@ def __init__(self, *args, **kwargs) -> None: self.storages = {} for plugin in enabled_plugins: prefix = f'plugins/{plugin.plugin_id}' - path = Path(plugin.path) / 'static' + path = (Path(plugin.path) / 'static').resolve() if path.is_dir(): self.locations.append((prefix, str(path))) storage = FileSystemStorage(location=path) diff --git a/api/src/reportcreator_api/tests/test_plugins.py b/api/src/reportcreator_api/tests/test_plugins.py index a3430cc2..30868e56 100644 --- a/api/src/reportcreator_api/tests/test_plugins.py +++ b/api/src/reportcreator_api/tests/test_plugins.py @@ -67,12 +67,13 @@ def test_plugin_loading(): # Static files # Create dummy file when the frontend was not built yet from sysreptor_plugins import demoplugin # noqa: I001 - pluginjs_path = Path(demoplugin.__path__[0]) / 'static' / 'plugin.js' + pluginjs_path = (Path(demoplugin.__path__[0]) / 'static' / 'plugin.js').resolve() if not pluginjs_path.exists(): pluginjs_path.parent.mkdir(parents=True, exist_ok=True) pluginjs_path.touch() - assert finders.find(f'plugins/{DEMOPLUGIN_ID}/plugin.js') is not None + finders.get_finder.cache_clear() + res = finders.find(f'plugins/{DEMOPLUGIN_ID}/plugin.js') is not None # URLs registered assert api_client().get(reverse(f'{DEMOPLUGIN_APPLABEL}:helloworld')).status_code == 200 From 2d96674a0d0d4207071f56fb9fa77243b48b6d65 Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Wed, 6 Nov 2024 11:29:06 +0100 Subject: [PATCH 2/2] Handle frontend_entry cache --- api/src/reportcreator_api/tests/test_plugins.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/reportcreator_api/tests/test_plugins.py b/api/src/reportcreator_api/tests/test_plugins.py index 30868e56..ab290e97 100644 --- a/api/src/reportcreator_api/tests/test_plugins.py +++ b/api/src/reportcreator_api/tests/test_plugins.py @@ -13,6 +13,7 @@ from reportcreator_api.management.commands import restorebackup from reportcreator_api.tests.mock import api_client, create_user +from reportcreator_api.utils.utils import omit_keys DEMOPLUGIN_ID = 'db365aa0-ed36-4e90-93b6-a28effc4ed47' DEMOPLUGIN_APPLABEL = 'plugin_db365aa0ed364e9093b6a28effc4ed47' @@ -71,8 +72,8 @@ def test_plugin_loading(): if not pluginjs_path.exists(): pluginjs_path.parent.mkdir(parents=True, exist_ok=True) pluginjs_path.touch() - finders.get_finder.cache_clear() + res = finders.find(f'plugins/{DEMOPLUGIN_ID}/plugin.js') is not None # URLs registered @@ -82,7 +83,7 @@ def test_plugin_loading(): res = api_client().get(reverse('publicutils-settings')) assert res.status_code == 200 demoplugin_config = next(filter(lambda p: p['id'] == DEMOPLUGIN_ID, res.data['plugins'])) - assert demoplugin_config == {'id': DEMOPLUGIN_ID, 'name': 'demoplugin', 'frontend_entry': f'/static/plugins/{DEMOPLUGIN_ID}/plugin.js', 'frontend_settings': {}} + assert omit_keys(demoplugin_config, ['frontend_entry']) == {'id': DEMOPLUGIN_ID, 'name': 'demoplugin', 'frontend_settings': {}} @pytest.mark.django_db()