Exemple #1
0
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
Exemple #2
0
        def test_domain(self):
            from protean.domain import Domain

            domain = Domain("Test")
            domain.config["DATABASES"]["memory"] = {
                "PROVIDER": "protean.adapters.MemoryProvider"
            }
            yield domain
Exemple #3
0
        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
Exemple #4
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")
Exemple #5
0
        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"])
Exemple #6
0
        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()
Exemple #7
0
from protean import Domain

dom2 = Domain("INSTANCE")
Exemple #8
0
 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 == {}
Exemple #9
0
from protean import Domain

domain = Domain("WEB")
Exemple #10
0
 class Module:
     my_domain1 = Domain("name1")
     my_domain2 = Domain("name2")
Exemple #11
0
from protean import Domain

domain = Domain("FOLDER")
Exemple #12
0
 class Module:
     my_domain = Domain("name")
Exemple #13
0
 class Module:
     subdomain = Domain("name")
Exemple #14
0
 class Module:
     domain = Domain("name")
Exemple #15
0
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()

Exemple #16
0
from protean import Domain

domain = Domain("BASIC")