-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events can now optionally specify a version with `__version__` class attribute. This commit also contains: - An optional `finalize` flag to `BaseContainer.__init__` to control element finalization - Additional tests for Event Sourced Aggregates
- Loading branch information
Showing
10 changed files
with
361 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from protean.container import BaseContainer, OptionsMixin | ||
from protean.fields import String | ||
|
||
|
||
class TestControlledFinalization: | ||
def test_that_objects_are_initialized_by_default(self): | ||
# FIXME Remove OptionsMixin when it becomes optional | ||
class Foo(BaseContainer, OptionsMixin): | ||
foo = String() | ||
|
||
foo = Foo() | ||
assert foo._initialized is True | ||
|
||
def test_that_objects_can_be_initialized_manually(self): | ||
class Foo(BaseContainer, OptionsMixin): | ||
foo = String() | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, finalize=False, **kwargs) | ||
|
||
foo = Foo() | ||
|
||
assert foo._initialized is False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ class UserAdded(BaseEvent): | |
"_metadata": { | ||
"kind": "EVENT", | ||
"timestamp": str(event._metadata.timestamp), | ||
"version": "v1", | ||
}, | ||
"email": { | ||
"address": "[email protected]", | ||
|
@@ -78,3 +79,38 @@ def special_method(self): | |
pass | ||
|
||
assert fully_qualified_name(AnnotatedDomainEvent) in test_domain.registry.events | ||
|
||
|
||
class TestDomainEventEquivalence: | ||
def test_that_two_domain_events_with_same_values_are_considered_equal(self): | ||
identifier = uuid.uuid4() | ||
event_1 = PersonAdded(id=identifier, first_name="John", last_name="Doe") | ||
event_2 = PersonAdded(id=identifier, first_name="John", last_name="Doe") | ||
|
||
assert event_1 == event_2 | ||
|
||
def test_that_two_domain_events_with_different_values_are_not_considered_equal( | ||
self, | ||
): | ||
identifier = uuid.uuid4() | ||
|
||
event_1 = PersonAdded(id=identifier, first_name="John", last_name="Doe") | ||
event_2 = PersonAdded(id=identifier, first_name="Jane", last_name="Doe") | ||
|
||
assert event_1 != event_2 | ||
|
||
def test_that_two_domain_events_with_different_values_are_not_considered_equal_with_different_types( | ||
self, | ||
): | ||
identifier = uuid.uuid4() | ||
|
||
class User(Person): | ||
pass | ||
|
||
class UserAdded(PersonAdded): | ||
pass | ||
|
||
event_1 = PersonAdded(id=identifier, first_name="John", last_name="Doe") | ||
event_2 = UserAdded(id=identifier, first_name="John", last_name="Doe") | ||
|
||
assert event_1 != event_2 |
Oops, something went wrong.