def test_that_config_is_unique_to_each_domain(): domain1 = Domain() assert domain1.config["IDENTITY_STRATEGY"] == IdentityStrategy.UUID.value domain1.config["IDENTITY_STRATEGY"] = "FOO" domain2 = Domain() assert domain2.config["IDENTITY_STRATEGY"] == IdentityStrategy.UUID.value
def test_domain(self): from protean.domain import Domain domain = Domain("Test") domain.config["DATABASES"]["memory"] = { "PROVIDER": "protean.adapters.MemoryProvider" } yield domain
def test_that_class_reference_is_resolved_on_domain_activation(self): domain = Domain("Inline Domain") class Post(BaseAggregate): content = Text(required=True) comments = HasMany("Comment") domain.register(Post) # Still a string assert isinstance(declared_fields(Post)["comments"].to_cls, str) class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") class Meta: aggregate_cls = Post domain.register(Comment) with domain.domain_context(): # Resolved references assert declared_fields(Post)["comments"].to_cls == Comment assert declared_fields(Comment)["post"].to_cls == Post assert len(domain._pending_class_resolutions) == 0
def test_error_on_message_db_initialization(self): domain = Domain() domain.config["EVENT_STORE"][ "PROVIDER" ] = "protean.adapters.event_store.message_db.MessageDBStore" domain.config["EVENT_STORE"][ "DATABASE_URI" ] = "postgresql://message_store@localhost:5433/dummy" with pytest.raises(ConfigurationError) as exc: domain.event_store.store._write( "testStream-123", "Event1", {"foo": "bar"}, {"kind": "EVENT"} ) assert 'FATAL: database "dummy" does not exist' in str(exc.value) # Reset config value. # FIXME Config should be an argument to the domain domain.config["EVENT_STORE"][ "PROVIDER" ] = "protean.adapters.event_store.memory.MemoryEventStore" domain.config["EVENT_STORE"].pop("DATABASE_URI")
def test_that_class_reference_is_tracked_at_the_domain_level(self): domain = Domain() class Post(BaseAggregate): content = Text(required=True) comments = HasMany("Comment") domain.register(Post) # Still a string assert isinstance(declared_fields(Post)["comments"].to_cls, str) class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") class Meta: aggregate_cls = Post domain.register(Comment) assert len(domain._pending_class_resolutions) == 2 assert all(field_name in domain._pending_class_resolutions for field_name in ["Comment", "Post"])
def test_that_domain_throws_exception_on_unknown_class_references_during_activation( self, ): domain = Domain("Inline Domain") class Post(BaseAggregate): content = Text(required=True) comments = HasMany("Comment") domain.register(Post) # Still a string assert isinstance(declared_fields(Post)["comments"].to_cls, str) class Comment(BaseEntity): content = Text() added_on = DateTime() post = Reference("Post") foo = Reference("Foo") class Meta: aggregate_cls = Post domain.register(Comment) with pytest.raises(ConfigurationError) as exc: with domain.domain_context(): pass assert (exc.value.args[0]["element"] == "Element Foo not registered in domain Inline Domain") # Remove domain context manually, as we lost it when the exception was raised from protean.globals import _domain_context_stack _domain_context_stack.pop()
from protean import Domain dom2 = Domain("INSTANCE")
def test_that_a_domain_can_be_initialized_successfully(self): domain = Domain(__name__) assert domain is not None assert domain.registry is not None assert domain.registry.aggregates == {}
from protean import Domain domain = Domain("WEB")
class Module: my_domain1 = Domain("name1") my_domain2 = Domain("name2")
from protean import Domain domain = Domain("FOLDER")
class Module: my_domain = Domain("name")
class Module: subdomain = Domain("name")
class Module: domain = Domain("name")
from protean import ( BaseEvent, BaseEventHandler, BaseEventSourcedAggregate, Domain, handle, ) from protean.fields import Identifier, String from tests.server.test_command_handling import UserCommandHandler baz = Domain(domain_name="FooBar") class Registered(BaseEvent): id = Identifier() email = String() name = String() password_hash = String() class PasswordChanged(BaseEvent): id = Identifier() password_hash = String() class User(BaseEventSourcedAggregate): email = String() name = String() password_hash = String()
from protean import Domain domain = Domain("BASIC")