Skip to content

Commit

Permalink
Merge branch 'fix-plugin-tests' into 'main'
Browse files Browse the repository at this point in the history
Fix flappy plugin loading tests

See merge request reportcreator/reportcreator!752
  • Loading branch information
MWedl committed Nov 6, 2024
2 parents 9f1887a + 2d96674 commit d20759d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/src/reportcreator_api/conf/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions api/src/reportcreator_api/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -67,12 +68,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()
finders.get_finder.cache_clear()

assert finders.find(f'plugins/{DEMOPLUGIN_ID}/plugin.js') is not None
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
Expand All @@ -81,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()
Expand Down

0 comments on commit d20759d

Please sign in to comment.