-
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.
Remove domain-level event
raise_
functionality
Events, at this point, should always be connected to aggregates, and raised from within them as part of business logic. Directly adding events at the domain level was helper functionality, but with the addition of metadata and headers at the event level, events have a lot more contextuality. They cannot be raised or appended to event store directly. We will need to revisit this functionality if we need Domain Events (or some variation thereof) that are not connected to aggregates.
- Loading branch information
Showing
6 changed files
with
58 additions
and
34 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
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 |
---|---|---|
|
@@ -23,7 +23,10 @@ def test_raising_event(test_domain): | |
test_domain.register(UserLoggedIn, stream_name="authentication") | ||
|
||
identifier = str(uuid4()) | ||
test_domain.raise_(UserLoggedIn(user_id=identifier)) | ||
user = User(id=identifier, email="[email protected]", name="Test User") | ||
user.raise_(UserLoggedIn(user_id=identifier)) | ||
|
||
test_domain.repository_for(User).add(user) | ||
|
||
messages = test_domain.event_store.store.read("authentication") | ||
|
||
|
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,37 @@ | ||
import mock | ||
import pytest | ||
|
||
from protean import BaseEventSourcedAggregate | ||
from protean.fields import Identifier, String | ||
|
||
|
||
class User(BaseEventSourcedAggregate): | ||
id = Identifier(identifier=True) | ||
email = String() | ||
name = String() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def register_elements(test_domain): | ||
test_domain.register(User) | ||
test_domain.init(traverse=False) | ||
|
||
|
||
@mock.patch("protean.core.repository.UnitOfWork.start") | ||
@mock.patch("protean.core.repository.UnitOfWork.commit") | ||
def test_that_method_is_enclosed_in_uow(mock_commit, mock_start, test_domain): | ||
mock_parent = mock.Mock() | ||
|
||
mock_parent.attach_mock(mock_start, "m1") | ||
mock_parent.attach_mock(mock_commit, "m2") | ||
|
||
with test_domain.domain_context(): | ||
user = User(id=1, email="[email protected]", name="John Doe") | ||
test_domain.repository_for(User).add(user) | ||
|
||
mock_parent.assert_has_calls( | ||
[ | ||
mock.call.m1(), | ||
mock.call.m2(), | ||
] | ||
) |