Skip to content

Commit 1d07bdc

Browse files
committed
test: use json parameter for proper Content-Type in POST/PUT
1 parent fc03b0d commit 1d07bdc

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

tests/test_main.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
- Conflict and edge case behaviors
1717
"""
1818

19-
import json
2019
from tests.player_stub import existing_player, nonexistent_player, unknown_player
2120

2221
PATH = "/players/"
@@ -151,10 +150,8 @@ def test_request_get_player_squadnumber_existing_response_body_player_match(clie
151150

152151
def test_request_post_player_body_empty_response_status_unprocessable(client):
153152
"""POST /players/ with empty body returns 422 Unprocessable Entity"""
154-
# Arrange
155-
body = {}
156153
# Act
157-
response = client.post(PATH, data=body)
154+
response = client.post(PATH, json={})
158155
# Assert
159156
assert response.status_code == 422
160157

@@ -163,9 +160,8 @@ def test_request_post_player_body_existing_response_status_conflict(client):
163160
"""POST /players/ with existing player returns 409 Conflict"""
164161
# Arrange
165162
player = existing_player()
166-
body = json.dumps(player.__dict__)
167163
# Act
168-
response = client.post(PATH, data=body)
164+
response = client.post(PATH, json=player.__dict__)
169165
# Assert
170166
assert response.status_code == 409
171167

@@ -174,9 +170,8 @@ def test_request_post_player_body_nonexistent_response_status_created(client):
174170
"""POST /players/ with nonexistent player returns 201 Created"""
175171
# Arrange
176172
player = nonexistent_player()
177-
body = json.dumps(player.__dict__)
178173
# Act
179-
response = client.post(PATH, data=body)
174+
response = client.post(PATH, json=player.__dict__)
180175
# Assert
181176
assert response.status_code == 201
182177

@@ -190,9 +185,8 @@ def test_request_put_player_id_existing_body_empty_response_status_unprocessable
190185
"""PUT /players/{player_id} with empty body returns 422 Unprocessable Entity"""
191186
# Arrange
192187
player_id = existing_player().id
193-
body = {}
194188
# Act
195-
response = client.put(PATH + str(player_id), data=body)
189+
response = client.put(PATH + str(player_id), json={})
196190
# Assert
197191
assert response.status_code == 422
198192

@@ -202,9 +196,8 @@ def test_request_put_player_id_unknown_response_status_not_found(client):
202196
# Arrange
203197
player_id = unknown_player().id
204198
player = unknown_player()
205-
body = json.dumps(player.__dict__)
206199
# Act
207-
response = client.put(PATH + str(player_id), data=body)
200+
response = client.put(PATH + str(player_id), json=player.__dict__)
208201
# Assert
209202
assert response.status_code == 404
210203

@@ -216,9 +209,8 @@ def test_request_put_player_id_existing_response_status_no_content(client):
216209
player = existing_player()
217210
player.first_name = "Emiliano"
218211
player.middle_name = ""
219-
body = json.dumps(player.__dict__)
220212
# Act
221-
response = client.put(PATH + str(player_id), data=body)
213+
response = client.put(PATH + str(player_id), json=player.__dict__)
222214
# Assert
223215
assert response.status_code == 204
224216

0 commit comments

Comments
 (0)