Skip to content

Commit 2143d7c

Browse files
committed
chore(tests): add arrange/act/assert steps
1 parent 72b597b commit 2143d7c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_main.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def test_given_get_when_request_path_has_no_id_then_response_status_code_should_
1616
when request path has no ID
1717
then response Status Code should be 200 OK
1818
"""
19+
# Act
1920
response = client.get(PATH)
21+
# Assert
2022
assert response.status_code == 200
2123

2224

@@ -26,7 +28,9 @@ def test_given_get_when_request_path_has_no_id_then_response_body_should_be_coll
2628
when request path has no ID
2729
then response Status Code should be collection of players
2830
"""
31+
# Act
2932
response = client.get(PATH)
33+
# Assert
3034
players = response.json()
3135
player_id = 0
3236
for player in players:
@@ -42,8 +46,11 @@ def test_given_get_when_request_path_is_nonexistent_id_then_response_status_code
4246
when request path is nonexistent ID
4347
then response Status Code should be 404 (Not Found)
4448
"""
49+
# Arrange
4550
player_id = nonexistent_player().id
51+
# Act
4652
response = client.get(PATH + str(player_id))
53+
# Assert
4754
assert response.status_code == 404
4855

4956

@@ -53,8 +60,11 @@ def test_given_get_when_request_path_is_existing_id_then_response_status_code_sh
5360
when request path is existing ID
5461
then response Status Code should be 200 (OK)
5562
"""
63+
# Arrange
5664
player_id = existing_player().id
65+
# Act
5766
response = client.get(PATH + str(player_id))
67+
# Assert
5868
assert response.status_code == 200
5969

6070

@@ -64,8 +74,11 @@ def test_given_get_when_request_path_is_existing_id_then_response_body_should_be
6474
when request path is existing ID
6575
then response body should be matching Player
6676
"""
77+
# Arrange
6778
player_id = existing_player().id
79+
# Act
6880
response = client.get(PATH + str(player_id))
81+
# Assert
6982
player = response.json()
7083
assert player["id"] == player_id
7184

@@ -78,8 +91,11 @@ def test_given_get_when_request_path_is_nonexistent_squad_number_then_response_s
7891
when request path is nonexistent Squad Number
7992
then response Status Code should be 404 (Not Found)
8093
"""
94+
# Arrange
8195
squad_number = nonexistent_player().squad_number
96+
# Act
8297
response = client.get(PATH + "squadnumber" + "/" + str(squad_number))
98+
# Assert
8399
assert response.status_code == 404
84100

85101

@@ -89,8 +105,11 @@ def test_given_get_when_request_path_is_existing_squad_number_then_response_stat
89105
when request path is existing Squad Number
90106
then response Status Code should be 200 (OK)
91107
"""
108+
# Arrange
92109
squad_number = existing_player().squad_number
110+
# Act
93111
response = client.get(PATH + "squadnumber" + "/" + str(squad_number))
112+
# Assert
94113
assert response.status_code == 200
95114

96115

@@ -100,8 +119,11 @@ def test_given_get_when_request_path_is_existing_squad_number_then_response_body
100119
when request path is existing Squad Number
101120
then response body should be matching Player
102121
"""
122+
# Arrange
103123
squad_number = existing_player().squad_number
124+
# Act
104125
response = client.get(PATH + "squadnumber" + "/" + str(squad_number))
126+
# Assert
105127
player = response.json()
106128
assert player["squadNumber"] == squad_number
107129

@@ -114,8 +136,11 @@ def test_given_post_when_request_body_is_empty_then_response_status_code_should_
114136
when request body is empty
115137
then response Status Code should be 422 (Unprocessable Entity)
116138
"""
139+
# Arrange
117140
body = {}
141+
# Act
118142
response = client.post(PATH, data=body)
143+
# Assert
119144
assert response.status_code == 422
120145

121146

@@ -125,9 +150,12 @@ def test_given_post_when_request_body_is_existing_player_then_response_status_co
125150
when request body is existing Player
126151
then response Status Code should be 409 (Conflict)
127152
"""
153+
# Arrange
128154
player = existing_player()
129155
body = json.dumps(player.__dict__)
156+
# Act
130157
response = client.post(PATH, data=body)
158+
# Assert
131159
assert response.status_code == 409
132160

133161

@@ -137,9 +165,12 @@ def test_given_post_when_request_body_is_nonexistent_player_then_response_status
137165
when request body is nonexistent Player
138166
then response Status Code should be 201 (Created)
139167
"""
168+
# Arrange
140169
player = nonexistent_player()
141170
body = json.dumps(player.__dict__)
171+
# Act
142172
response = client.post(PATH, data=body)
173+
# Assert
143174
assert response.status_code == 201
144175

145176
# PUT /players/{player_id} -----------------------------------------------------
@@ -151,9 +182,12 @@ def test_given_put_when_request_body_is_empty_then_response_status_code_should_b
151182
when request body is empty
152183
then response Status Code should be 422 (Unprocessable Entity)
153184
"""
185+
# Arrange
154186
player_id = existing_player().id
155187
body = {}
188+
# Act
156189
response = client.put(PATH + str(player_id), data=body)
190+
# Assert
157191
assert response.status_code == 422
158192

159193

@@ -163,10 +197,13 @@ def test_given_put_when_request_path_is_unknown_id_then_response_status_code_sho
163197
when request path is unknown ID
164198
then response Status Code should be 404 (Not Found)
165199
"""
200+
# Arrange
166201
player_id = unknown_player().id
167202
player = unknown_player()
168203
body = json.dumps(player.__dict__)
204+
# Act
169205
response = client.put(PATH + str(player_id), data=body)
206+
# Assert
170207
assert response.status_code == 404
171208

172209

@@ -176,12 +213,15 @@ def test_given_put_when_request_path_is_existing_id_then_response_status_code_sh
176213
when request path is existing ID
177214
then response Status Code should be 204 (No Content)
178215
"""
216+
# Arrange
179217
player_id = existing_player().id
180218
player = existing_player()
181219
player.first_name = "Emiliano"
182220
player.middle_name = ""
183221
body = json.dumps(player.__dict__)
222+
# Act
184223
response = client.put(PATH + str(player_id), data=body)
224+
# Assert
185225
assert response.status_code == 204
186226

187227
# DELETE /players/{player_id} --------------------------------------------------
@@ -193,8 +233,11 @@ def test_given_delete_when_request_path_is_unknown_id_then_response_status_code_
193233
when request path is unknown ID
194234
then response Status Code should be 404 (Not Found)
195235
"""
236+
# Arrange
196237
player_id = unknown_player().id
238+
# Act
197239
response = client.delete(PATH + str(player_id))
240+
# Assert
198241
assert response.status_code == 404
199242

200243

@@ -204,6 +247,9 @@ def test_given_delete_when_request_path_is_existing_id_then_response_status_code
204247
when request path is existing ID
205248
then response Status Code should be 204 (No Content)
206249
"""
250+
# Arrange
207251
player_id = 12 # nonexistent_player() previously created
252+
# Act
208253
response = client.delete(PATH + str(player_id))
254+
# Assert
209255
assert response.status_code == 204

0 commit comments

Comments
 (0)