Skip to content

Commit

Permalink
Merge pull request #301 from PlzTrustMe/edit-naming
Browse files Browse the repository at this point in the history
Rename from uow to commiter
  • Loading branch information
Tishka17 authored Nov 11, 2024
2 parents 39b646a + 4655168 commit aae2d86
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions examples/real_world/myapp/db.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging

from .use_cases import ProductGateway, UnitOfWork, User, UserGateway, Product
from .use_cases import ProductGateway, Committer, User, UserGateway, Product

logger = logging.getLogger(__name__)


class FakeDbConnection(UnitOfWork):
class FakeCommitter(Committer):
def __init__(self):
logger.info("init FakeDbConnection as %s", self)
logger.info("init FakeCommitter as %s", self)

def commit(self) -> None:
logger.info("commit as %s", self)
Expand All @@ -17,19 +17,19 @@ def close(self) -> None:


class FakeUserGateway(UserGateway):
def __init__(self, unit_of_work: FakeDbConnection):
self.unit_of_work = unit_of_work
logger.info("init FakeUserGateway with %s", unit_of_work)
def __init__(self, committer: FakeCommitter):
self.committer = committer
logger.info("init FakeUserGateway with %s", committer)

def get_user(self, user_id: int) -> User:
logger.info("get_user %s as %s", user_id, self)
return User()


class FakeProductGateway(ProductGateway):
def __init__(self, unit_of_work: FakeDbConnection):
self.unit_of_work = unit_of_work
logger.info("init FakeProductGateway with %s", unit_of_work)
def __init__(self, committer: FakeCommitter):
self.committer = committer
logger.info("init FakeProductGateway with %s", committer)

def add_product(self, product: Product) -> None:
logger.info(
Expand Down
14 changes: 7 additions & 7 deletions examples/real_world/myapp/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
provide,
)
from .api_client import FakeWarehouseClient
from .db import FakeDbConnection, FakeProductGateway, FakeUserGateway
from .db import FakeCommitter, FakeProductGateway, FakeUserGateway
from .use_cases import (
AddProductsInteractor,
ProductGateway,
UnitOfWork,
Committer,
UserGateway,
WarehouseClient,
)
Expand All @@ -25,12 +25,12 @@ class AdaptersProvider(Provider):
products = provide(FakeProductGateway, provides=ProductGateway)

@provide
def connection(self) -> Iterable[FakeDbConnection]:
uow = FakeDbConnection()
yield uow
uow.close()
def connection(self) -> Iterable[FakeCommitter]:
committer = FakeCommitter()
yield committer
committer.close()

uow = alias(source=FakeDbConnection, provides=UnitOfWork)
committer = alias(source=FakeCommitter, provides=Committer)

@provide(scope=Scope.APP)
def warehouse(self) -> WarehouseClient:
Expand Down
8 changes: 4 additions & 4 deletions examples/real_world/myapp/use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_product(self, product: Product) -> None:
raise NotImplementedError


class UnitOfWork(Protocol):
class Committer(Protocol):
@abstractmethod
def commit(self) -> None:
raise NotImplementedError
Expand All @@ -46,12 +46,12 @@ def __init__(
self,
user_gateway: UserGateway,
product_gateway: ProductGateway,
unit_of_work: UnitOfWork,
committer: Committer,
warehouse_client: WarehouseClient,
) -> None:
self.user_gateway = user_gateway
self.product_gateway = product_gateway
self.unit_of_work = unit_of_work
self.committer = committer
self.warehouse_client = warehouse_client

def __call__(self, user_id: int):
Expand All @@ -63,4 +63,4 @@ def __call__(self, user_id: int):
self.product_gateway.add_product(product)
product2 = Product(user_id, self.warehouse_client.next_product())
self.product_gateway.add_product(product2)
self.unit_of_work.commit()
self.committer.commit()
14 changes: 7 additions & 7 deletions examples/real_world/tests/test_add_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from myapp.ioc import InteractorProvider
from myapp.use_cases import (
AddProductsInteractor,
Committer,
ProductGateway,
UnitOfWork,
User,
UserGateway,
WarehouseClient,
Expand All @@ -26,7 +26,7 @@

# app dependency logic
class AdaptersProvider(Provider):
scope=Scope.APP
scope = Scope.APP

@provide
def users(self) -> UserGateway:
Expand All @@ -41,10 +41,10 @@ def products(self) -> ProductGateway:
return gateway

@provide
def uow(self) -> UnitOfWork:
uow = Mock()
uow.commit = Mock()
return uow
def committer(self) -> Committer:
committer = Mock()
committer.commit = Mock()
return committer

@provide
def warehouse(self) -> WarehouseClient:
Expand All @@ -63,4 +63,4 @@ def container():
def test_interactor(container):
interactor = container.get(AddProductsInteractor)
interactor(1)
container.get(UnitOfWork).commit.assert_called_once_with()
container.get(Committer).commit.assert_called_once_with()

0 comments on commit aae2d86

Please sign in to comment.