Skip to content

Commit 98df28f

Browse files
committed
Add common fixtures to use nested methods
1 parent 6b583b1 commit 98df28f

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

tests/integration/api/workflows/products/discontinue_product/test_discontinue_product_workflow.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,30 @@
1212
from python_template.domain.entities.product import Product
1313

1414

15-
@pytest.fixture
16-
async def workflow() -> DiscontinueProductWorkflow:
17-
return await DependencyContainer.get_discontinue_product_workflow()
15+
class TestDiscontinueProductWorkflow:
16+
@pytest.fixture
17+
async def workflow_fixture(self) -> DiscontinueProductWorkflow:
18+
return await DependencyContainer.get_discontinue_product_workflow()
1819

20+
@pytest.fixture(autouse=True)
21+
def setup(self, workflow_fixture: DiscontinueProductWorkflow) -> None:
22+
self.workflow = workflow_fixture
1923

20-
class TestDiscontinueProductWorkflow:
21-
async def test_discontinue_product(
22-
self, workflow: DiscontinueProductWorkflow
23-
) -> None:
24+
async def test_discontinue_product(self) -> None:
2425
cosmos_database = await DependencyContainer.get_cosmos_database()
2526
product_container = cosmos_database.get_container_client(Product.__name__)
2627
product = ProductBuilder().build()
2728
await product_container.create_item(product.model_dump())
2829
request = DiscontinueProductRequest(id=product.id)
2930

30-
await workflow.execute(request)
31+
await self.workflow.execute(request)
3132

32-
async def test_fail_when_discontinuing_discontinued_product(
33-
self, workflow: DiscontinueProductWorkflow
34-
) -> None:
33+
async def test_fail_when_discontinuing_discontinued_product(self) -> None:
3534
cosmos_database = await DependencyContainer.get_cosmos_database()
3635
product_container = cosmos_database.get_container_client(Product.__name__)
3736
product = ProductBuilder().discontinued().build()
3837
await product_container.create_item(product.model_dump())
3938
request = DiscontinueProductRequest(id=product.id)
4039

4140
with pytest.raises(ProductAlreadyDiscontinuedError):
42-
await workflow.execute(request)
41+
await self.workflow.execute(request)

tests/integration/api/workflows/products/publish_product/test_publish_product_workflow.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
)
1010

1111

12-
@pytest.fixture
13-
async def workflow() -> PublishProductWorkflow:
14-
return await DependencyContainer.get_publish_product_workflow()
12+
class TestPublishProductWorkflow:
13+
@pytest.fixture
14+
async def workflow_fixture(self) -> PublishProductWorkflow:
15+
return await DependencyContainer.get_publish_product_workflow()
1516

17+
@pytest.fixture(autouse=True)
18+
def setup(self, workflow_fixture: PublishProductWorkflow) -> None:
19+
self.workflow = workflow_fixture
1620

17-
class TestPublishProductWorkflow:
18-
async def test_publish_product(self, workflow: PublishProductWorkflow) -> None:
21+
async def test_publish_product(self) -> None:
1922
request = PublishProductRequestBuilder().build()
2023

21-
await workflow.execute(request)
24+
await self.workflow.execute(request)

0 commit comments

Comments
 (0)