48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
"""Contacts-Entity-Registry: single source of truth (Kritikpunkt 11).
|
|
|
|
Beweist, dass die Contacts-Entities (contact/contacts/company) NICHT mehr
|
|
statisch im Core-Registry stehen, sondern ausschliesslich vom ContactsPlugin
|
|
ueber get_entity_models() + register_entity_model() kommen — wie jedes
|
|
andere Plugin auch. is_core=True heisst Pflichtplugin, nicht Core-Verdrahtung.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app.models.contact import Contact
|
|
from app.plugins.builtins.contacts.plugin import ContactsPlugin
|
|
from app.services.entity_permission_service import ENTITY_MODELS
|
|
|
|
|
|
def test_core_registry_source_has_no_static_contacts_entries():
|
|
"""The core registry SOURCE must not hardcode contacts entities anymore.
|
|
|
|
(After bootstrap ENTITY_MODELS legitimately contains them — registered
|
|
via the plugin. This test proves the duplicate static source is gone.)
|
|
"""
|
|
from pathlib import Path
|
|
|
|
module_path = Path(__file__).parent.parent / "app" / "services" / "entity_permission_service.py"
|
|
text = module_path.read_text(encoding="utf-8")
|
|
assert '"contact": Contact' not in text, "statischer contact-Eintrag noch im Core!"
|
|
assert '"contacts": Contact' not in text, "statischer contacts-Eintrag noch im Core!"
|
|
assert '"company": Contact' not in text, "statischer company-Eintrag noch im Core!"
|
|
|
|
|
|
def test_contacts_plugin_is_single_source_for_its_entities():
|
|
"""ContactsPlugin.get_entity_models() defines contact/contacts/company."""
|
|
plugin_models = ContactsPlugin().get_entity_models()
|
|
assert plugin_models == {
|
|
"contact": Contact,
|
|
"contacts": Contact,
|
|
"company": Contact,
|
|
}
|
|
|
|
|
|
def test_bootstrap_registers_contacts_entities_via_plugin():
|
|
"""After the real bootstrap path (conftest mirrors main.py lifespan:
|
|
every plugin's get_entity_models() is registered), contacts entities
|
|
are present — via the plugin, not via the core registry."""
|
|
assert ENTITY_MODELS["contact"] is Contact
|
|
assert ENTITY_MODELS["contacts"] is Contact
|
|
assert ENTITY_MODELS["company"] is Contact
|