forked from pgorecki/python-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_catalog.py
More file actions
162 lines (136 loc) · 4.41 KB
/
Copy pathtest_catalog.py
File metadata and controls
162 lines (136 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import pytest
from modules.catalog.application.command import (
CreateListingDraftCommand,
PublishListingDraftCommand,
)
from seedwork.domain.value_objects import GenericUUID, Money
@pytest.mark.integration
def test_empty_catalog_list(api_client):
response = api_client.get("/catalog")
assert response.status_code == 200
assert response.json() == {"data": []}
@pytest.mark.integration
@pytest.mark.asyncio
async def test_catalog_list_with_one_item(app, api_client):
# arrange
await app.execute_async(
CreateListingDraftCommand(
listing_id=GenericUUID(int=1),
title="Foo",
description="Bar",
ask_price=Money(10),
seller_id=GenericUUID(int=2),
)
)
# act
response = api_client.get("/catalog")
# assert
assert response.status_code == 200
response_data = response.json()["data"]
assert len(response_data) == 1
assert response.json() == {
"data": [
{
"id": str(GenericUUID(int=1)),
"title": "Foo",
"description": "Bar",
"ask_price_amount": 10.0,
"ask_price_currency": "USD",
}
]
}
@pytest.mark.integration
@pytest.mark.asyncio
async def test_catalog_list_with_two_items(app, api_client):
# arrange
await app.execute_async(
CreateListingDraftCommand(
listing_id=GenericUUID(int=1),
title="Foo #1",
description="Bar",
ask_price=Money(10),
seller_id=GenericUUID(int=2),
)
)
await app.execute_async(
CreateListingDraftCommand(
listing_id=GenericUUID(int=2),
title="Foo #2",
description="Bar",
ask_price=Money(10),
seller_id=GenericUUID(int=2),
)
)
# act
response = api_client.get("/catalog")
# assert
assert response.status_code == 200
response_data = response.json()["data"]
assert len(response_data) == 2
def test_catalog_create_draft_fails_due_to_incomplete_data(
api, authenticated_api_client
):
response = authenticated_api_client.post("/catalog")
assert response.status_code == 422
@pytest.mark.integration
@pytest.mark.asyncio
async def test_catalog_delete_draft(app, authenticated_api_client):
current_user = authenticated_api_client.current_user
await app.execute_async(
CreateListingDraftCommand(
listing_id=GenericUUID(int=1),
title="Listing to be deleted",
description="...",
ask_price=Money(10),
seller_id=current_user.id,
)
)
response = authenticated_api_client.delete(f"/catalog/{str(GenericUUID(int=1))}")
assert response.status_code == 204
@pytest.mark.integration
def test_catalog_delete_non_existing_draft_returns_404(authenticated_api_client):
listing_id = GenericUUID(int=1)
response = authenticated_api_client.delete(f"/catalog/{listing_id}")
assert response.status_code == 404
@pytest.mark.integration
@pytest.mark.asyncio
async def test_catalog_publish_listing_draft(app, authenticated_api_client):
# arrange
current_user = authenticated_api_client.current_user
listing_id = GenericUUID(int=1)
await app.execute_async(
CreateListingDraftCommand(
listing_id=listing_id,
title="Listing to be published",
description="...",
ask_price=Money(10),
seller_id=current_user.id,
)
)
# act
response = authenticated_api_client.post(f"/catalog/{listing_id}/publish")
# assert that the listing was published
assert response.status_code == 200
@pytest.mark.asyncio
async def test_published_listing_appears_in_biddings(app, authenticated_api_client):
# arrange
listing_id = GenericUUID(int=1)
current_user = authenticated_api_client.current_user
await app.execute_async(
CreateListingDraftCommand(
listing_id=listing_id,
title="Listing to be published",
description="...",
ask_price=Money(10),
seller_id=current_user.id,
)
)
await app.execute_async(
PublishListingDraftCommand(
listing_id=listing_id,
seller_id=current_user.id,
)
)
url = f"/bidding/{listing_id}"
response = authenticated_api_client.get(url)
assert response.status_code == 200