added hooks and plugins files missing
This commit is contained in:
10
tests/test_app_init.py
Normal file
10
tests/test_app_init.py
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
import pytest
|
||||
from app import create_app
|
||||
|
||||
def test_app_loads_plugins():
|
||||
app = create_app({'TESTING': True})
|
||||
# Assuming app.plugins is a dict of loaded plugin modules
|
||||
assert hasattr(app, 'plugins'), "App object missing 'plugins' attribute"
|
||||
for plugin in ["auth", "admin", "plant", "cli"]:
|
||||
assert plugin in app.plugins, f"Plugin '{plugin}' not loaded into app.plugins"
|
22
tests/test_event_dispatcher.py
Normal file
22
tests/test_event_dispatcher.py
Normal file
@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from app.hooks import EventDispatcher, listen_event
|
||||
|
||||
def test_register_and_dispatch():
|
||||
results = []
|
||||
def listener1(a, b=None):
|
||||
results.append(('l1', a, b))
|
||||
def listener2(a, b=None):
|
||||
results.append(('l2', a, b))
|
||||
EventDispatcher.register('test_event', listener1)
|
||||
EventDispatcher.register('test_event', listener2)
|
||||
EventDispatcher.dispatch('test_event', 1, b=2)
|
||||
assert ('l1', 1, 2) in results
|
||||
assert ('l2', 1, 2) in results
|
||||
|
||||
def test_listen_event_decorator():
|
||||
results = []
|
||||
@listen_event('decorated_event')
|
||||
def handler(x):
|
||||
results.append(x)
|
||||
EventDispatcher.dispatch('decorated_event', 'hello')
|
||||
assert results == ['hello']
|
7
tests/test_events.py
Normal file
7
tests/test_events.py
Normal file
@ -0,0 +1,7 @@
|
||||
import app.events as events
|
||||
|
||||
def test_event_names_exist():
|
||||
assert hasattr(events, 'ON_USER_CREATED')
|
||||
assert hasattr(events, 'ON_SUBMISSION_SAVED')
|
||||
assert hasattr(events, 'ON_PLANT_TRANSFERRED')
|
||||
assert hasattr(events, 'ON_GROWLOG_UPDATED')
|
25
tests/test_plugin_metadata.py
Normal file
25
tests/test_plugin_metadata.py
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
import importlib
|
||||
|
||||
# Directory containing plugins
|
||||
PLUGINS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'plugins'))
|
||||
|
||||
@pytest.mark.parametrize("plugin", ["auth", "admin", "plant", "cli"])
|
||||
def test_plugin_metadata_and_init(plugin, tmp_path, monkeypatch):
|
||||
# Construct plugin path
|
||||
plugin_path = os.path.join(PLUGINS_DIR, plugin)
|
||||
# Test plugin.json exists and contains required keys
|
||||
meta_path = os.path.join(plugin_path, 'plugin.json')
|
||||
assert os.path.isfile(meta_path), f"plugin.json missing for {plugin}"
|
||||
meta = json.loads(open(meta_path).read())
|
||||
for key in ("name", "version", "description"):
|
||||
assert key in meta, f"{{key}} missing in {plugin}/plugin.json"
|
||||
# Test __init__.py can be imported and has register_cli
|
||||
module_name = f"plugins.{plugin}"
|
||||
spec = importlib.util.spec_from_file_location(module_name, os.path.join(plugin_path, '__init__.py'))
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
assert hasattr(module, "register_cli"), f"register_cli missing in {plugin}/__init__.py"
|
Reference in New Issue
Block a user