Skip to content

Commit 8628cbf

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

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

tests/test_main.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,8 @@ def test_request_get_player_squadnumber_existing_response_body_player_match(clie
151151

152152
def test_request_post_player_body_empty_response_status_unprocessable(client):
153153
"""POST /players/ with empty body returns 422 Unprocessable Entity"""
154-
# Arrange
155-
body = {}
156154
# Act
157-
response = client.post(PATH, data=body)
155+
response = client.post(PATH, json={})
158156
# Assert
159157
assert response.status_code == 422
160158

@@ -163,9 +161,8 @@ def test_request_post_player_body_existing_response_status_conflict(client):
163161
"""POST /players/ with existing player returns 409 Conflict"""
164162
# Arrange
165163
player = existing_player()
166-
body = json.dumps(player.__dict__)
167164
# Act
168-
response = client.post(PATH, data=body)
165+
response = client.post(PATH, json=player.__dict__)
169166
# Assert
170167
assert response.status_code == 409
171168

@@ -174,9 +171,8 @@ def test_request_post_player_body_nonexistent_response_status_created(client):
174171
"""POST /players/ with nonexistent player returns 201 Created"""
175172
# Arrange
176173
player = nonexistent_player()
177-
body = json.dumps(player.__dict__)
178174
# Act
179-
response = client.post(PATH, data=body)
175+
response = client.post(PATH, json=player.__dict__)
180176
# Assert
181177
assert response.status_code == 201
182178

@@ -190,9 +186,8 @@ def test_request_put_player_id_existing_body_empty_response_status_unprocessable
190186
"""PUT /players/{player_id} with empty body returns 422 Unprocessable Entity"""
191187
# Arrange
192188
player_id = existing_player().id
193-
body = {}
194189
# Act
195-
response = client.put(PATH + str(player_id), data=body)
190+
response = client.put(PATH + str(player_id), json={})
196191
# Assert
197192
assert response.status_code == 422
198193

@@ -202,9 +197,8 @@ def test_request_put_player_id_unknown_response_status_not_found(client):
202197
# Arrange
203198
player_id = unknown_player().id
204199
player = unknown_player()
205-
body = json.dumps(player.__dict__)
206200
# Act
207-
response = client.put(PATH + str(player_id), data=body)
201+
response = client.put(PATH + str(player_id), json=player.__dict__)
208202
# Assert
209203
assert response.status_code == 404
210204

@@ -216,9 +210,8 @@ def test_request_put_player_id_existing_response_status_no_content(client):
216210
player = existing_player()
217211
player.first_name = "Emiliano"
218212
player.middle_name = ""
219-
body = json.dumps(player.__dict__)
220213
# Act
221-
response = client.put(PATH + str(player_id), data=body)
214+
response = client.put(PATH + str(player_id), json=player.__dict__)
222215
# Assert
223216
assert response.status_code == 204
224217

0 commit comments

Comments
 (0)