You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
from iti.applications import create_app
|
|
from iti.config import TestConfig
|
|
from iti.modules import get_module_registry
|
|
from iti_system import create_system_module
|
|
|
|
|
|
class SystemTestConfig(TestConfig):
|
|
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"
|
|
|
|
|
|
def test_system_module_registers_all_routes_and_commands():
|
|
module = create_system_module()
|
|
app = create_app(
|
|
"test",
|
|
modules=[module],
|
|
config_mapping={"test": SystemTestConfig, "default": SystemTestConfig},
|
|
)
|
|
|
|
rules = {rule.rule for rule in app.url_map.iter_rules()}
|
|
registry = get_module_registry(app)
|
|
|
|
assert app.extensions["iti_system"] is module
|
|
assert registry.get("iti_system") is module
|
|
assert "/auth/loginByPassword" in rules
|
|
assert "/sys/user/list" in rules
|
|
assert "/sys/user/attributes/current" in rules
|
|
assert "/sys/role/list" in rules
|
|
assert "/sys/menu/list" in rules
|
|
assert "/sys/dept/list" in rules
|
|
assert "/sys/config/list" in rules
|
|
assert "/sys/dict/type/page" in rules
|
|
assert "/sys/log/page" in rules
|
|
assert "/sys/file/<string:file_id>" in rules
|
|
assert "/upload" in rules
|
|
assert "/file/<string:file_id>/download" in rules
|
|
assert "iti-system" in app.cli.commands
|
|
|
|
|
|
def test_system_module_adds_system_defaults_to_config():
|
|
app = create_app(
|
|
"test",
|
|
modules=[create_system_module()],
|
|
config_mapping={"test": SystemTestConfig, "default": SystemTestConfig},
|
|
)
|
|
|
|
assert app.config["SYSLOG_MAX_BODY_CHARS"] == 2048
|
|
assert app.config["SYSLOG_ITEMS_SAMPLE"] == 5
|
|
assert app.config["PERMISSION_CONFIG"]["SUPER_ADMIN_ROLE"] == "ADMIN"
|
|
|
|
|
|
def test_system_migration_sync_command_copies_full_migration(tmp_path):
|
|
app = create_app(
|
|
"test",
|
|
modules=[create_system_module()],
|
|
config_mapping={"test": SystemTestConfig, "default": SystemTestConfig},
|
|
)
|
|
runner = app.test_cli_runner()
|
|
|
|
result = runner.invoke(
|
|
args=["iti-system", "migrations", "sync", "--target", str(tmp_path)]
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert "summary: synced 1, skipped 0" in result.output
|
|
assert len(list(tmp_path.glob("*.py"))) == 1
|