-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
198 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -8,6 +8,7 @@ authors = ["Przemysław Górecki <[email protected]>"] | |
python = "^3.9" | ||
pytest = "^6.2.4" | ||
pydantic = "^1.8.2" | ||
black = "^21.5b1" | ||
|
||
[tool.poetry.dev-dependencies] | ||
|
||
|
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class AuctionItem(Entity): | ||
pass | ||
pass |
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 |
---|---|---|
|
@@ -3,5 +3,3 @@ | |
|
||
class DraftCreatedEvent(DomainEvent): | ||
pass | ||
|
||
|
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from seedwork.domain.rules import BusinessRule | ||
from seedwork.domain.value_objects import Currency | ||
|
||
|
||
class AuctionItemPriceMustBeGreaterThanZero(BusinessRule): | ||
message = "Price must be greater that zero" | ||
price: Currency | ||
|
||
def is_broken(self) -> bool: | ||
return self.price <= 0 | ||
return self.price <= 0 |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class Command(BaseModel): | ||
pass | ||
pass |
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,2 @@ | ||
class EntityNotFoundException(Exception): | ||
pass |
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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
class Entity: | ||
pass | ||
from pydantic import BaseModel, Field | ||
import uuid | ||
|
||
|
||
class Entity(BaseModel): | ||
id: uuid.UUID = Field(default_factory=uuid.uuid4) |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class DomainEvent(BaseModel): | ||
pass | ||
pass |
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 |
---|---|---|
|
@@ -3,4 +3,4 @@ class DomainException(Exception): | |
|
||
|
||
class BusinessRuleValidationException(DomainException): | ||
pass | ||
pass |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ def get_message(self) -> str: | |
return self.message | ||
|
||
def is_broken(self) -> bool: | ||
pass | ||
pass |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
class Currency(int): | ||
pass | ||
pass |
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 |
---|---|---|
@@ -1,2 +1,20 @@ | ||
from seedwork.domain.entities import Entity | ||
from seedwork.application.exceptions import EntityNotFoundException | ||
|
||
|
||
class Repository: | ||
pass | ||
pass | ||
|
||
|
||
class InMemoryRepository(Repository): | ||
def __init__(self) -> None: | ||
self.objects = {} | ||
|
||
def get_by_id(self, id) -> Entity: | ||
try: | ||
return self.objects[id] | ||
except KeyError: | ||
raise EntityNotFoundException | ||
|
||
def persist(self, entity: Entity): | ||
self.objects[entity.id] = entity |
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,34 @@ | ||
from seedwork.infrastructure.repository import InMemoryRepository | ||
from seedwork.domain.entities import Entity | ||
|
||
|
||
class Person(Entity): | ||
first_name: str | ||
last_name: str | ||
|
||
|
||
def test_InMemoryRepository_persist_one(): | ||
# arrange | ||
person = Person(first_name="John", last_name="Doe") | ||
repository = InMemoryRepository() | ||
|
||
# act | ||
repository.persist(person) | ||
|
||
# assert | ||
assert repository.get_by_id(person.id) == person | ||
|
||
|
||
def test_InMemoryRepository_persist_two(): | ||
# arrange | ||
person1 = Person(first_name="John", last_name="Doe") | ||
person2 = Person(first_name="Mary", last_name="Doe") | ||
repository = InMemoryRepository() | ||
|
||
# act | ||
repository.persist(person1) | ||
repository.persist(person2) | ||
|
||
# assert | ||
assert repository.get_by_id(person1.id) == person1 | ||
assert repository.get_by_id(person2.id) == person2 |