@@ -174,15 +174,36 @@ def test_raises_because_attempt_to_get_nonexisting_task(api_token, api_responses
174174 assert str (e .value ) == expected_error_msg
175175
176176
177- def test_returns_tasks_list ( api_token , api_responses , task_base_url ):
178- fake_specs = [{ "fake" : "specs" }, { "and" : "more" }]
177+ @ pytest . mark . parametrize ( "fake_specs" , [[], [{ "fake" : "specs" }, { "and" : "more" }]])
178+ def test_returns_tasks_list ( api_token , api_responses , task_base_url , fake_specs ):
179179 api_responses .add (
180180 responses .GET , url = task_base_url , status = 200 , body = json .dumps (fake_specs ),
181181 )
182182
183183 assert Schedule ().get_list () == fake_specs
184184
185185
186+ @pytest .mark .parametrize ("status_code, body" , [
187+ (201 , "[]" ),
188+ (202 , '{"status": "accepted"}' ),
189+ (204 , "" ),
190+ (403 , '{"detail": "Forbidden"}' ),
191+ (429 , '{"detail": "Throttled"}' ),
192+ (500 , '{"detail": "Server error"}' ),
193+ (500 , "Non-JSON server error" ),
194+ ])
195+ def test_list_raises_unless_response_is_200 (
196+ api_token , api_responses , task_base_url , status_code , body
197+ ):
198+ api_responses .add (responses .GET , task_base_url , status = status_code , body = body )
199+
200+ with pytest .raises (PythonAnywhereApiException ) as exc :
201+ Schedule ().get_list ()
202+
203+ assert str (status_code ) in str (exc .value )
204+ assert body in str (exc .value )
205+
206+
186207def test_updates_daily_task (
187208 api_token , api_responses , task_specs , daily_task_params , task_base_url
188209):
0 commit comments