33# ------------------------------------------------------------------------------
44
55import json
6- from tests .player_stub import existing_player , non_existing_player , unknown_player
6+ from tests .player_stub import existing_player , nonexistent_player , unknown_player
77
88PATH = "/players/"
99
1010# GET /players/ ----------------------------------------------------------------
1111
1212
1313def test_given_get_when_request_path_has_no_id_then_response_status_code_should_be_200_ok (client ):
14+ """
15+ Given GET /players/
16+ when request path has no ID
17+ then response Status Code should be 200 OK
18+ """
1419 response = client .get (PATH )
1520 assert response .status_code == 200
1621
1722
1823def test_given_get_when_request_path_has_no_id_then_response_body_should_be_collection_of_players (client ):
24+ """
25+ Given GET /players/
26+ when request path has no ID
27+ then response Status Code should be collection of players
28+ """
1929 response = client .get (PATH )
2030 players = response .json ()
2131 player_id = 0
@@ -26,41 +36,71 @@ def test_given_get_when_request_path_has_no_id_then_response_body_should_be_coll
2636# GET /players/{player_id} -----------------------------------------------------
2737
2838
29- def test_given_get_when_request_path_is_non_existing_id_then_response_status_code_should_be_404_not_found (client ):
30- player_id = 999
39+ def test_given_get_when_request_path_is_nonexistent_id_then_response_status_code_should_be_404_not_found (client ):
40+ """
41+ Given GET /players/{player_id}
42+ when request path is nonexistent ID
43+ then response Status Code should be 404 (Not Found)
44+ """
45+ player_id = nonexistent_player ().id
3146 response = client .get (PATH + str (player_id ))
3247 assert response .status_code == 404
3348
3449
3550def test_given_get_when_request_path_is_existing_id_then_response_status_code_should_be_200_ok (client ):
36- player_id = 1
51+ """
52+ Given GET /players/{player_id}
53+ when request path is existing ID
54+ then response Status Code should be 200 (OK)
55+ """
56+ player_id = existing_player ().id
3757 response = client .get (PATH + str (player_id ))
3858 assert response .status_code == 200
3959
4060
4161def test_given_get_when_request_path_is_existing_id_then_response_body_should_be_matching_player (client ):
42- player_id = 1
62+ """
63+ Given GET /players/{player_id}
64+ when request path is existing ID
65+ then response body should be matching Player
66+ """
67+ player_id = existing_player ().id
4368 response = client .get (PATH + str (player_id ))
4469 player = response .json ()
4570 assert player ["id" ] == player_id
4671
4772# GET /players/squadnumber/{squad_number} --------------------------------------
4873
4974
50- def test_given_get_when_request_path_is_non_existing_squad_number_then_response_status_code_should_be_404_not_found (client ):
51- squad_number = 999
75+ def test_given_get_when_request_path_is_nonexistent_squad_number_then_response_status_code_should_be_404_not_found (client ):
76+ """
77+ Given GET /players/squadnumber/{squad_number}
78+ when request path is nonexistent Squad Number
79+ then response Status Code should be 404 (Not Found)
80+ """
81+ squad_number = nonexistent_player ().squad_number
5282 response = client .get (PATH + "squadnumber" + "/" + str (squad_number ))
5383 assert response .status_code == 404
5484
5585
5686def test_given_get_when_request_path_is_existing_squad_number_then_response_status_code_should_be_200_ok (client ):
57- squad_number = 10
87+ """
88+ Given GET /players/squadnumber/{squad_number}
89+ when request path is existing Squad Number
90+ then response Status Code should be 200 (OK)
91+ """
92+ squad_number = existing_player ().squad_number
5893 response = client .get (PATH + "squadnumber" + "/" + str (squad_number ))
5994 assert response .status_code == 200
6095
6196
6297def test_given_get_when_request_path_is_existing_squad_number_then_response_body_should_be_matching_player (client ):
63- squad_number = 10
98+ """
99+ Given GET /players/squadnumber/{squad_number}
100+ when request path is existing Squad Number
101+ then response body should be matching Player
102+ """
103+ squad_number = existing_player ().squad_number
64104 response = client .get (PATH + "squadnumber" + "/" + str (squad_number ))
65105 player = response .json ()
66106 assert player ["squadNumber" ] == squad_number
@@ -69,20 +109,35 @@ def test_given_get_when_request_path_is_existing_squad_number_then_response_body
69109
70110
71111def test_given_post_when_request_body_is_empty_then_response_status_code_should_be_422_unprocessable_entity (client ):
72- body = json .dumps ({})
112+ """
113+ Given POST /players/
114+ when request body is empty
115+ then response Status Code should be 422 (Unprocessable Entity)
116+ """
117+ body = {}
73118 response = client .post (PATH , data = body )
74119 assert response .status_code == 422
75120
76121
77122def test_given_post_when_request_body_is_existing_player_then_response_status_code_should_be_409_conflict (client ):
123+ """
124+ Given POST /players/
125+ when request body is existing Player
126+ then response Status Code should be 409 (Conflict)
127+ """
78128 player = existing_player ()
79129 body = json .dumps (player .__dict__ )
80130 response = client .post (PATH , data = body )
81131 assert response .status_code == 409
82132
83133
84- def test_given_post_when_request_body_is_non_existing_player_then_response_status_code_should_be_201_created (client ):
85- player = non_existing_player ()
134+ def test_given_post_when_request_body_is_nonexistent_player_then_response_status_code_should_be_201_created (client ):
135+ """
136+ Given POST /players/
137+ when request body is nonexistent Player
138+ then response Status Code should be 201 (Created)
139+ """
140+ player = nonexistent_player ()
86141 body = json .dumps (player .__dict__ )
87142 response = client .post (PATH , data = body )
88143 assert response .status_code == 201
@@ -91,22 +146,37 @@ def test_given_post_when_request_body_is_non_existing_player_then_response_statu
91146
92147
93148def test_given_put_when_request_body_is_empty_then_response_status_code_should_be_422_unprocessable_entity (client ):
94- player_id = 1
149+ """
150+ Given PUT /players/{player_id}
151+ when request body is empty
152+ then response Status Code should be 422 (Unprocessable Entity)
153+ """
154+ player_id = existing_player ().id
95155 body = {}
96156 response = client .put (PATH + str (player_id ), data = body )
97157 assert response .status_code == 422
98158
99159
100- def test_given_put_when_request_body_is_unknown_player_then_response_status_code_should_be_404_not_found (client ):
101- player_id = 999
160+ def test_given_put_when_request_path_is_unknown_id_then_response_status_code_should_be_404_not_found (client ):
161+ """
162+ Given PUT /players/{player_id}
163+ when request path is unknown ID
164+ then response Status Code should be 404 (Not Found)
165+ """
166+ player_id = unknown_player ().id
102167 player = unknown_player ()
103168 body = json .dumps (player .__dict__ )
104169 response = client .put (PATH + str (player_id ), data = body )
105170 assert response .status_code == 404
106171
107172
108- def test_given_put_when_request_body_is_existing_player_then_response_status_code_should_be_204_no_content (client ):
109- player_id = 1
173+ def test_given_put_when_request_path_is_existing_id_then_response_status_code_should_be_204_no_content (client ):
174+ """
175+ Given PUT /players/{player_id}
176+ when request path is existing ID
177+ then response Status Code should be 204 (No Content)
178+ """
179+ player_id = existing_player ().id
110180 player = existing_player ()
111181 player .first_name = "Emiliano"
112182 player .middle_name = ""
@@ -117,13 +187,23 @@ def test_given_put_when_request_body_is_existing_player_then_response_status_cod
117187# DELETE /players/{player_id} --------------------------------------------------
118188
119189
120- def test_given_delete_when_request_path_is_non_existing_id_then_response_status_code_should_be_404_not_found (client ):
121- player_id = 999
190+ def test_given_delete_when_request_path_is_unknown_id_then_response_status_code_should_be_404_not_found (client ):
191+ """
192+ Given DELETE /players/{player_id}
193+ when request path is unknown ID
194+ then response Status Code should be 404 (Not Found)
195+ """
196+ player_id = unknown_player ().id
122197 response = client .delete (PATH + str (player_id ))
123198 assert response .status_code == 404
124199
125200
126201def test_given_delete_when_request_path_is_existing_id_then_response_status_code_should_be__204_no_content (client ):
127- player_id = 12
202+ """
203+ Given DELETE /players/{player_id}
204+ when request path is existing ID
205+ then response Status Code should be 204 (No Content)
206+ """
207+ player_id = 12 # nonexistent_player() previously created
128208 response = client .delete (PATH + str (player_id ))
129209 assert response .status_code == 204
0 commit comments