migration and testing
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
|
||||
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"
|
||||
assert hasattr(app, 'plugins'), "App missing plugins attribute"
|
||||
for plugin in ["auth", "admin", "plant", "cli"]:
|
||||
assert plugin in app.plugins, f"Plugin '{plugin}' not loaded into app.plugins"
|
||||
assert plugin in app.plugins, f"Plugin {plugin} not loaded"
|
||||
|
12
tests/test_database_smoke.py
Normal file
12
tests/test_database_smoke.py
Normal file
@ -0,0 +1,12 @@
|
||||
import pytest
|
||||
from app import create_app, db
|
||||
from sqlalchemy import inspect
|
||||
|
||||
def test_database_smoke(tmp_path):
|
||||
db_file = tmp_path / "test.db"
|
||||
app = create_app({"TESTING": True, "SQLALCHEMY_DATABASE_URI": f"sqlite:///{db_file}"})
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
tables = inspect(db.engine).get_table_names()
|
||||
assert 'users' in tables or 'user' in tables
|
@ -3,20 +3,16 @@ 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 listener(a, b=None):
|
||||
results.append((a, b))
|
||||
EventDispatcher.register('evt', listener)
|
||||
EventDispatcher.dispatch('evt', 1, b=2)
|
||||
assert results == [(1, 2)]
|
||||
|
||||
def test_listen_event_decorator():
|
||||
results = []
|
||||
@listen_event('decorated_event')
|
||||
@listen_event('evt2')
|
||||
def handler(x):
|
||||
results.append(x)
|
||||
EventDispatcher.dispatch('decorated_event', 'hello')
|
||||
EventDispatcher.dispatch('evt2', 'hello')
|
||||
assert results == ['hello']
|
||||
|
@ -1,25 +1,21 @@
|
||||
|
||||
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
|
||||
def test_plugin_metadata_and_init(plugin):
|
||||
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"
|
||||
assert key in meta, f"{key} missing in {plugin}/plugin.json"
|
||||
init_path = os.path.join(plugin_path, '__init__.py')
|
||||
if os.path.exists(init_path):
|
||||
spec = importlib.util.spec_from_file_location(f"plugins.{plugin}", init_path)
|
||||
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