-
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.
`to_dict` of embedded VO was not extracting dict-appropriate values from enclosed fields. This commit fixes the issue and adds relevenat test cases.
- Loading branch information
Showing
3 changed files
with
66 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from datetime import datetime | ||
from protean.core.value_object import BaseValueObject | ||
|
||
from protean.fields.basic import DateTime, String | ||
from protean.fields.embedded import ValueObject | ||
from protean import BaseAggregate | ||
|
||
|
||
class SimpleVO(BaseValueObject): | ||
foo = String() | ||
bar = String() | ||
|
||
|
||
class VOWithDateTime(BaseValueObject): | ||
foo = String() | ||
now = DateTime() | ||
|
||
|
||
class SimpleVOEntity(BaseAggregate): | ||
vo = ValueObject(SimpleVO) | ||
|
||
|
||
class EntityWithDateTimeVO(BaseAggregate): | ||
vo = ValueObject(VOWithDateTime) | ||
|
||
|
||
class TestAsDict: | ||
def test_empty_simple_vo(self): | ||
simple = SimpleVOEntity(id=12) | ||
assert simple.to_dict() == {"id": 12} | ||
|
||
def test_simple_vo_dict(self): | ||
vo = SimpleVO(foo="foo", bar="bar") | ||
assert vo.to_dict() == {"foo": "foo", "bar": "bar"} | ||
|
||
def test_embedded_simple_vo(self): | ||
vo = SimpleVO(foo="foo", bar="bar") | ||
simple = SimpleVOEntity(id=12, vo=vo) | ||
assert simple.to_dict() == {"id": 12, "vo_foo": "foo", "vo_bar": "bar"} | ||
|
||
def test_datetime_vo_dict(self): | ||
now = datetime.utcnow() | ||
vo = VOWithDateTime(foo="foo", now=now) | ||
assert vo.to_dict() == {"foo": "foo", "now": str(now)} | ||
|
||
def test_embedded_datetime_vo(self): | ||
now = datetime.utcnow() | ||
vo = VOWithDateTime(foo="foo", now=now) | ||
simple = EntityWithDateTimeVO(id=12, vo=vo) | ||
assert simple.to_dict() == {"id": 12, "vo_foo": "foo", "vo_now": str(now)} |