def test_element_registration(): register = _DomainRegistry() register.register_element(Role) assert ( "tests.test_registry.Role" in register._elements[DomainObjects.AGGREGATE.value] )
def __init__(self, domain_name=__name__, root_path=None, instance_relative_config=False): _PackageBoundObject.__init__( self, domain_name, root_path=root_path, ) self.domain_name = domain_name # Registry for all domain Objects self._domain_registry = _DomainRegistry() #: The configuration dictionary as :class:`Config`. This behaves #: exactly like a regular dictionary but supports additional methods #: to load a config from files. self.config = self.make_config(instance_relative_config) self.providers = Providers(self) self.brokers = Brokers(self) self.email_providers = EmailProviders(self) # Cache for holding Model to Entity/Aggregate associations self._models = {} self._constructed_models = {} #: A list of functions that are called when the domain context #: is destroyed. This is the place to store code that cleans up and #: disconnects from databases, for example. self.teardown_domain_context_functions = []
def test_that_re_registering_an_element_has_no_effect(): register = _DomainRegistry() register.register_element(Role) register.register_element(Role) assert len(register._elements[DomainObjects.AGGREGATE.value]) == 1 assert ("tests.registry.tests.Role" in register._elements[DomainObjects.AGGREGATE.value])
def test_delisting_element(): register = _DomainRegistry() register.register_element(Role) assert ("tests.registry.tests.Role" in register._elements[DomainObjects.AGGREGATE.value]) register.delist_element(Role) assert ("tests.registry.tests.Role" not in register._elements[DomainObjects.AGGREGATE.value])
def __init__( self, domain_name: str = __name__, root_path: str = None, instance_relative_config: bool = False, ): _PackageBoundObject.__init__( self, domain_name, root_path=root_path, ) self.domain_name = domain_name # FIXME Additional domain attributes: (Think if this is needed) # - Type of Domain: Core, Supporting, Third-party(?) # - Type of Implementation: CRUD, CQRS, ES # Registry for all domain Objects self._domain_registry = _DomainRegistry() #: The configuration dictionary as :class:`Config`. This behaves #: exactly like a regular dictionary but supports additional methods #: to load a config from files. self.config = self.make_config(instance_relative_config) self.providers = Providers(self) self.event_store = EventStore(self) self.brokers = Brokers(self) self.caches = Caches(self) self.email_providers = EmailProviders(self) # Cache for holding Model to Entity/Aggregate associations self._models: Dict[str, BaseModel] = {} self._constructed_models: Dict[str, BaseModel] = {} #: A list of functions that are called when the domain context #: is destroyed. This is the place to store code that cleans up and #: disconnects from databases, for example. self.teardown_domain_context_functions: List[Callable] = [] # Placeholder array for resolving classes referenced by domain elements # FIXME Should all protean elements be subclassed from a base element? self._pending_class_resolutions: dict[str, Any] = defaultdict(list)
def test_that_delisting_an_unknown_element_type_triggers_an_error(): class DummyEnum(Enum): UNKNOWN = "UNKNOWN" class FooBar1: element_type = "FOOBAR" class FooBar2: element_type = DummyEnum.UNKNOWN class FooBar3: pass register = _DomainRegistry() with pytest.raises(NotImplementedError): register.delist_element(FooBar1) with pytest.raises(NotImplementedError): register.delist_element(FooBar2) with pytest.raises(NotImplementedError): register.delist_element(FooBar3)
def test_fetching_elements_from_registry(): register = _DomainRegistry() register.register_element(Role) aggregates = register.get(DomainObjects.AGGREGATE) assert "tests.test_registry.Role" in aggregates