Repository: reagento/dishka
Pull request #301 (2024-11-08 23:56:45)

Rename from uow to commiter


Patch:
diff --git a/examples/real_world/myapp/db.py b/examples/real_world/myapp/db.py
index a0f252b..88d1439 100644
--- a/examples/real_world/myapp/db.py
+++ b/examples/real_world/myapp/db.py
@@ -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)
@@ -17,9 +17,9 @@ class FakeDbConnection(UnitOfWork):
 
 
 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)
@@ -27,9 +27,9 @@ class FakeUserGateway(UserGateway):
 
 
 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(
diff --git a/examples/real_world/myapp/ioc.py b/examples/real_world/myapp/ioc.py
index 21308ea..cb94f63 100644
--- a/examples/real_world/myapp/ioc.py
+++ b/examples/real_world/myapp/ioc.py
@@ -7,11 +7,11 @@ from dishka import (
     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,
 )
@@ -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:
diff --git a/examples/real_world/myapp/use_cases.py b/examples/real_world/myapp/use_cases.py
index fdd500a..cd5ca5d 100644
--- a/examples/real_world/myapp/use_cases.py
+++ b/examples/real_world/myapp/use_cases.py
@@ -29,7 +29,7 @@ class ProductGateway(Protocol):
         raise NotImplementedError
 
 
-class UnitOfWork(Protocol):
+class Committer(Protocol):
     @abstractmethod
     def commit(self) -> None:
         raise NotImplementedError
@@ -46,12 +46,12 @@ class AddProductsInteractor:
             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):
@@ -63,4 +63,4 @@ class AddProductsInteractor:
         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()


Test patch:
diff --git a/examples/real_world/tests/test_add_products.py b/examples/real_world/tests/test_add_products.py
index 2c6b516..e602cf9 100644
--- a/examples/real_world/tests/test_add_products.py
+++ b/examples/real_world/tests/test_add_products.py
@@ -9,8 +9,8 @@ import pytest
 from myapp.ioc import InteractorProvider
 from myapp.use_cases import (
     AddProductsInteractor,
+    Committer,
     ProductGateway,
-    UnitOfWork,
     User,
     UserGateway,
     WarehouseClient,
@@ -26,7 +26,7 @@ from dishka import (
 
 # app dependency logic
 class AdaptersProvider(Provider):
-    scope=Scope.APP
+    scope = Scope.APP
 
     @provide
     def users(self) -> UserGateway:
@@ -41,10 +41,10 @@ class AdaptersProvider(Provider):
         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:
@@ -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()