Skip to content

Commit 204ee71

Browse files
committed
introduce mypy
1 parent 534a37e commit 204ee71

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+346
-343
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ compose_up = "docker-compose -f docker-compose.dev.yml up"
5454

5555
[tool.black]
5656
exclude = 'tmp'
57+
58+
[tool.mypy]
59+
mypy_path = "src"
60+

src/api/models/bidding.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
from datetime import datetime
2-
from uuid import UUID
32

43
from pydantic import BaseModel
54

5+
from seedwork.domain.value_objects import GenericUUID
6+
67

78
class BidReadModel(BaseModel):
89
amount: float
910
currency: str
10-
bidder_id: UUID
11+
bidder_id: GenericUUID
1112
bidder_username: str
1213

1314

1415
class BiddingResponse(BaseModel):
15-
listing_id: UUID
16+
listing_id: GenericUUID
1617
auction_status: str = "active" # active, ended
1718
auction_end_date: datetime
1819
bids: list[BidReadModel]
1920

2021

2122
class PlaceBidRequest(BaseModel):
22-
bidder_id: UUID
23+
bidder_id: GenericUUID
2324
amount: float

src/api/routers/catalog.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import uuid
21
from typing import Annotated
3-
from uuid import UUID
42

53
from fastapi import APIRouter, Depends
64

@@ -14,7 +12,7 @@
1412
)
1513
from modules.catalog.application.query.get_all_listings import GetAllListings
1614
from modules.catalog.application.query.get_listing_details import GetListingDetails
17-
from seedwork.domain.value_objects import Money
15+
from seedwork.domain.value_objects import GenericUUID, Money
1816

1917
"""
2018
Inspired by https://developer.ebay.com/api-docs/sell/inventory/resources/offer/methods/createOffer
@@ -60,7 +58,7 @@ async def create_listing(
6058
Creates a new listing
6159
"""
6260
command = CreateListingDraftCommand(
63-
listing_id=uuid.uuid4(),
61+
listing_id=GenericUUID.next_id(),
6462
title=request_body.title,
6563
description=request_body.description,
6664
ask_price=Money(request_body.ask_price_amount, request_body.ask_price_currency),
@@ -100,7 +98,7 @@ async def delete_listing(
10098
)
10199
@inject
102100
async def publish_listing(
103-
listing_id: UUID,
101+
listing_id: GenericUUID,
104102
app: Annotated[Application, Depends(get_application)],
105103
current_user: Annotated[User, Depends(get_authenticated_user)],
106104
):

src/api/tests/test_bidding.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CreateListingDraftCommand,
55
PublishListingDraftCommand,
66
)
7-
from seedwork.domain.value_objects import UUID, Money
7+
from seedwork.domain.value_objects import GenericUUID, Money
88
from seedwork.infrastructure.logging import logger
99

1010

@@ -44,9 +44,9 @@ def setup_app_for_bidding_tests(app, listing_id, seller_id, bidder_id):
4444

4545
@pytest.mark.integration
4646
def test_place_bid(app, api_client):
47-
listing_id = UUID(int=1)
48-
seller_id = UUID(int=2)
49-
bidder_id = UUID(int=3)
47+
listing_id = GenericUUID(int=1)
48+
seller_id = GenericUUID(int=2)
49+
bidder_id = GenericUUID(int=3)
5050
setup_app_for_bidding_tests(app, listing_id, seller_id, bidder_id)
5151

5252
url = f"/bidding/{listing_id}/place_bid"

src/api/tests/test_catalog.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CreateListingDraftCommand,
55
PublishListingDraftCommand,
66
)
7-
from seedwork.domain.value_objects import UUID, Money
7+
from seedwork.domain.value_objects import GenericUUID, Money
88

99

1010
@pytest.mark.integration
@@ -17,13 +17,13 @@ def test_empty_catalog_list(api_client):
1717
@pytest.mark.integration
1818
def test_catalog_list_with_one_item(app, api_client):
1919
# arrange
20-
command_result = app.execute_command(
20+
app.execute_command(
2121
CreateListingDraftCommand(
22-
listing_id=UUID(int=1),
22+
listing_id=GenericUUID(int=1),
2323
title="Foo",
2424
description="Bar",
2525
ask_price=Money(10),
26-
seller_id=UUID("00000000000000000000000000000002"),
26+
seller_id=GenericUUID(int=2),
2727
)
2828
)
2929

@@ -37,7 +37,7 @@ def test_catalog_list_with_one_item(app, api_client):
3737
assert response.json() == {
3838
"data": [
3939
{
40-
"id": str(UUID(int=1)),
40+
"id": str(GenericUUID(int=1)),
4141
"title": "Foo",
4242
"description": "Bar",
4343
"ask_price_amount": 10.0,
@@ -52,20 +52,20 @@ def test_catalog_list_with_two_items(app, api_client):
5252
# arrange
5353
app.execute_command(
5454
CreateListingDraftCommand(
55-
listing_id=UUID(int=1),
55+
listing_id=GenericUUID(int=1),
5656
title="Foo #1",
5757
description="Bar",
5858
ask_price=Money(10),
59-
seller_id=UUID("00000000000000000000000000000002"),
59+
seller_id=GenericUUID(int=2),
6060
)
6161
)
6262
app.execute_command(
6363
CreateListingDraftCommand(
64-
listing_id=UUID(int=2),
64+
listing_id=GenericUUID(int=2),
6565
title="Foo #2",
6666
description="Bar",
6767
ask_price=Money(10),
68-
seller_id=UUID("00000000000000000000000000000002"),
68+
seller_id=GenericUUID(int=2),
6969
)
7070
)
7171

@@ -90,22 +90,22 @@ def test_catalog_delete_draft(app, authenticated_api_client):
9090
current_user = authenticated_api_client.current_user
9191
app.execute_command(
9292
CreateListingDraftCommand(
93-
listing_id=UUID(int=1),
93+
listing_id=GenericUUID(int=1),
9494
title="Listing to be deleted",
9595
description="...",
9696
ask_price=Money(10),
9797
seller_id=current_user.id,
9898
)
9999
)
100100

101-
response = authenticated_api_client.delete(f"/catalog/{str(UUID(int=1))}")
101+
response = authenticated_api_client.delete(f"/catalog/{str(GenericUUID(int=1))}")
102102

103103
assert response.status_code == 204
104104

105105

106106
@pytest.mark.integration
107107
def test_catalog_delete_non_existing_draft_returns_404(authenticated_api_client):
108-
listing_id = UUID("00000000000000000000000000000001")
108+
listing_id = GenericUUID(int=1)
109109
response = authenticated_api_client.delete(f"/catalog/{listing_id}")
110110
assert response.status_code == 404
111111

@@ -114,7 +114,7 @@ def test_catalog_delete_non_existing_draft_returns_404(authenticated_api_client)
114114
def test_catalog_publish_listing_draft(app, authenticated_api_client):
115115
# arrange
116116
current_user = authenticated_api_client.current_user
117-
listing_id = UUID(int=1)
117+
listing_id = GenericUUID(int=1)
118118
app.execute_command(
119119
CreateListingDraftCommand(
120120
listing_id=listing_id,
@@ -134,7 +134,7 @@ def test_catalog_publish_listing_draft(app, authenticated_api_client):
134134

135135
def test_published_listing_appears_in_biddings(app, authenticated_api_client):
136136
# arrange
137-
listing_id = UUID(int=1)
137+
listing_id = GenericUUID(int=1)
138138
current_user = authenticated_api_client.current_user
139139
app.execute_command(
140140
CreateListingDraftCommand(

src/api/tests/test_login.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from modules.iam.application.services import IamService
4-
from seedwork.domain.value_objects import UUID
4+
from seedwork.domain.value_objects import GenericUUID
55

66

77
@pytest.mark.integration
@@ -10,7 +10,7 @@ def test_login_with_api_token(app, api_client):
1010
with app.transaction_context() as ctx:
1111
iam_service = ctx.get_service(IamService)
1212
iam_service.create_user(
13-
user_id=UUID(int=1),
13+
user_id=GenericUUID(int=1),
1414
1515
password="admin",
1616
access_token="token",
@@ -33,7 +33,7 @@ def test_login_with_invalid_username_returns_400(app, api_client):
3333
with app.transaction_context() as ctx:
3434
iam_service = ctx.get_service(IamService)
3535
iam_service.create_user(
36-
user_id=UUID(int=1),
36+
user_id=GenericUUID(int=1),
3737
3838
password="admin",
3939
access_token="token",
@@ -55,7 +55,7 @@ def test_login_with_invalid_password_returns_400(app, api_client):
5555
with app.transaction_context() as ctx:
5656
iam_service = ctx.get_service(IamService)
5757
iam_service.create_user(
58-
user_id=UUID(int=1),
58+
user_id=GenericUUID(int=1),
5959
6060
password="admin",
6161
access_token="token",

src/config/__init__.py

Whitespace-only changes.

src/modules/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
foo = "bar"

src/modules/bidding/__init__.py

Whitespace-only changes.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
from dataclasses import dataclass
2-
from decimal import Decimal
32

43
from modules.bidding.application import bidding_module
5-
from modules.bidding.domain.entities import Listing
64
from modules.bidding.domain.repositories import ListingRepository
75
from modules.bidding.domain.value_objects import Bid, Bidder, Money
86
from seedwork.application.command_handlers import CommandResult
97
from seedwork.application.commands import Command
8+
from seedwork.domain.value_objects import GenericUUID
109

1110

1211
@dataclass
1312
class PlaceBidCommand(Command):
14-
listing_id: str
15-
bidder_id: str
16-
amount: Decimal
13+
listing_id: GenericUUID
14+
bidder_id: GenericUUID
15+
amount: int # todo: Decimal
1716
currency: str = "USD"
1817

1918

@@ -24,7 +23,7 @@ def place_bid(
2423
bidder = Bidder(id=command.bidder_id)
2524
bid = Bid(bidder=bidder, max_price=Money(command.amount))
2625

27-
listing: Listing = listing_repository.get_by_id(command.listing_id)
26+
listing = listing_repository.get_by_id(command.listing_id)
2827
listing.place_bid(bid)
2928

3029
return CommandResult.success()

0 commit comments

Comments
 (0)