Files
leocrm/tests/test_manifest_validation.py
T

102 lines
3.5 KiB
Python
Raw Normal View History

"""Tests for PluginManifest validation: SemVer, hook names, marketplace fields."""
from __future__ import annotations
import pytest
from app.plugins.manifest import PluginManifest
class TestManifestValidation:
def test_valid_min_app_version(self):
"""Valid SemVer min_app_version is accepted."""
m = PluginManifest(
name="test", version="1.0.0", display_name="Test",
min_app_version="1.2.3",
)
assert m.min_app_version == "1.2.3"
def test_default_min_app_version(self):
"""Default min_app_version is 0.0.0."""
m = PluginManifest(name="test", version="1.0.0", display_name="Test")
assert m.min_app_version == "0.0.0"
def test_invalid_min_app_version(self):
"""Invalid SemVer min_app_version is rejected."""
with pytest.raises(Exception):
PluginManifest(
name="test", version="1.0.0", display_name="Test",
min_app_version="not-a-version",
)
def test_valid_hooks(self):
"""Valid hook names are accepted."""
m = PluginManifest(
name="test", version="1.0.0", display_name="Test",
hooks=["contact.before_create", "mail.after_send"],
)
assert len(m.hooks) == 2
def test_invalid_hook_name(self):
"""Invalid hook name format is rejected."""
with pytest.raises(Exception):
PluginManifest(
name="test", version="1.0.0", display_name="Test",
hooks=["InvalidHookName"],
)
def test_invalid_hook_no_dot(self):
"""Hook name without dot is rejected."""
with pytest.raises(Exception):
PluginManifest(
name="test", version="1.0.0", display_name="Test",
hooks=["contact"],
)
def test_empty_hooks_allowed(self):
"""Empty hooks list is allowed."""
m = PluginManifest(
name="test", version="1.0.0", display_name="Test",
hooks=[],
)
assert m.hooks == []
def test_marketplace_fields_defaults(self):
"""All marketplace fields have correct defaults."""
m = PluginManifest(name="test", version="1.0.0", display_name="Test")
assert m.author == ""
assert m.author_email == ""
assert m.homepage == ""
assert m.license == "MIT"
assert m.icon == ""
assert m.screenshots == []
assert m.changelog == ""
assert m.marketplace_tags == []
assert m.price == 0.0
assert m.contract_version == "1.0.0"
def test_marketplace_fields_set(self):
"""Marketplace fields can be set."""
m = PluginManifest(
name="test", version="1.0.0", display_name="Test",
author="Jane Doe",
author_email="jane@example.com",
homepage="https://example.com/plugin",
license="Apache-2.0",
icon="📦",
screenshots=["https://example.com/s1.png"],
changelog="https://example.com/changelog.md",
marketplace_tags=["crm", "ai"],
price=9.99,
contract_version="2.0.0",
)
assert m.author == "Jane Doe"
assert m.license == "Apache-2.0"
assert m.price == 9.99
assert m.contract_version == "2.0.0"
def test_name_validation_lowercase(self):
"""Plugin name is lowercased."""
m = PluginManifest(name="MyPlugin", version="1.0.0", display_name="Test")
assert m.name == "myplugin"