-
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.
Ordinarialy, `add` method is called from within Command or Event handler methods. When `add` is invoked by itself, like in independent scripts, we need to ensure all ops in the `add` method are enclosed within a UoW.
- Loading branch information
Showing
3 changed files
with
40 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import mock | ||
|
||
from .elements import Person | ||
|
||
|
||
@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") | ||
|
||
test_domain.register(Person) | ||
test_domain.init(traverse=False) | ||
with test_domain.domain_context(): | ||
person = Person(first_name="John", last_name="Doe", age=29) | ||
test_domain.repository_for(Person).add(person) | ||
|
||
mock_parent.assert_has_calls( | ||
[ | ||
mock.call.m1(), | ||
mock.call.m2(), | ||
] | ||
) |