-
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.
- Do not allow associations and references in Events and Commands - Use camelcase domain name when constructing event/command type - Validate ValueObject field is connected to a value object - Refactor repository methods to indicate support for both aggregates and views
- Loading branch information
Showing
10 changed files
with
231 additions
and
30 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
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,38 @@ | ||
import pytest | ||
|
||
from protean import BaseAggregate, BaseCommand, BaseEntity | ||
from protean.exceptions import IncorrectUsageError | ||
from protean.fields import HasMany, HasOne, String | ||
|
||
|
||
class User(BaseAggregate): | ||
email = String() | ||
name = String() | ||
account = HasOne("Account") | ||
addresses = HasMany("Address") | ||
|
||
|
||
class Account(BaseEntity): | ||
password_hash = String() | ||
|
||
|
||
class Address(BaseEntity): | ||
street = String() | ||
city = String() | ||
state = String() | ||
postal_code = String() | ||
|
||
|
||
def test_events_cannot_hold_associations(): | ||
with pytest.raises(IncorrectUsageError) as exc: | ||
|
||
class Register(BaseCommand): | ||
email = String() | ||
name = String() | ||
account = HasOne(Account) | ||
|
||
assert exc.value.messages == { | ||
"_event": [ | ||
"Commands cannot have associations. Remove account (HasOne) from class Register" | ||
] | ||
} |
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,38 @@ | ||
import pytest | ||
|
||
from protean import BaseAggregate, BaseEntity, BaseEvent | ||
from protean.exceptions import IncorrectUsageError | ||
from protean.fields import HasMany, HasOne, String | ||
|
||
|
||
class User(BaseAggregate): | ||
email = String() | ||
name = String() | ||
account = HasOne("Account") | ||
addresses = HasMany("Address") | ||
|
||
|
||
class Account(BaseEntity): | ||
password_hash = String() | ||
|
||
|
||
class Address(BaseEntity): | ||
street = String() | ||
city = String() | ||
state = String() | ||
postal_code = String() | ||
|
||
|
||
def test_events_cannot_hold_associations(): | ||
with pytest.raises(IncorrectUsageError) as exc: | ||
|
||
class UserRegistered(BaseEvent): | ||
email = String() | ||
name = String() | ||
account = HasOne(Account) | ||
|
||
assert exc.value.messages == { | ||
"_event": [ | ||
"Events cannot have associations. Remove account (HasOne) from class UserRegistered" | ||
] | ||
} |
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,32 @@ | ||
import pytest | ||
|
||
from protean import BaseAggregate, BaseEntity, BaseValueObject | ||
from protean.exceptions import IncorrectUsageError | ||
from protean.fields import String, ValueObject | ||
from protean.reflection import fields | ||
|
||
|
||
def test_value_object_associated_class(test_domain): | ||
class Address(BaseValueObject): | ||
street_address = String() | ||
|
||
class User(BaseAggregate): | ||
email = String() | ||
address = ValueObject(Address) | ||
|
||
assert fields(User)["address"].value_object_cls == Address | ||
|
||
|
||
def test_value_object_to_cls_is_always_a_base_value_object_subclass(test_domain): | ||
class Address(BaseEntity): | ||
street_address = String() | ||
|
||
with pytest.raises(IncorrectUsageError) as exc: | ||
|
||
class User(BaseAggregate): | ||
email = String() | ||
address = ValueObject(Address) | ||
|
||
assert exc.value.messages == { | ||
"_value_object": ["`Address` is not a valid Value Object"] | ||
} |