@@ -88,9 +88,10 @@ def test_does_not_complain_if_api_token_exists(api_token, api_responses, domain_
8888 webapp .sanity_checks (nuke = False ) # should not raise
8989
9090
91- def test_raises_if_no_api_token_exists (api_responses , no_api_token , webapp ):
91+ @pytest .mark .parametrize ("nuke" , [False , True ])
92+ def test_raises_if_no_api_token_exists (api_responses , no_api_token , webapp , nuke ):
9293 with pytest .raises (SanityException ) as e :
93- webapp .sanity_checks (nuke = False )
94+ webapp .sanity_checks (nuke = nuke )
9495 assert "Could not find your API token" in str (e .value )
9596
9697
@@ -114,6 +115,27 @@ def test_does_not_raise_if_no_webapp(api_token, api_responses, domain_url, webap
114115 webapp .sanity_checks (nuke = False ) # should not raise
115116
116117
118+ @pytest .mark .parametrize ("status_code" , [201 , 202 , 204 , 403 , 429 , 500 ])
119+ @pytest .mark .parametrize ("json_body" , [False , True ])
120+ def test_sanity_checks_raise_on_unexpected_status (
121+ api_token , api_responses , domain_url , webapp , status_code , json_body
122+ ):
123+ body = "" if status_code == 204 else (
124+ '{"detail": "Preflight failed"}' if json_body else "Preflight failed"
125+ )
126+ api_responses .add (
127+ responses .GET , domain_url , status = status_code , body = body ,
128+ content_type = "application/json" if json_body else "text/plain" ,
129+ )
130+
131+ with pytest .raises (PythonAnywhereApiException ) as exc :
132+ webapp .sanity_checks (nuke = False )
133+
134+ assert str (status_code ) in str (exc .value )
135+ assert body in str (exc .value )
136+ assert len (api_responses .calls ) == 1
137+
138+
117139def test_nuke_option_overrides_all_but_token_check (
118140 api_token , api_responses , domain , fake_home , virtualenvs_folder , webapp
119141):
@@ -122,6 +144,8 @@ def test_nuke_option_overrides_all_but_token_check(
122144
123145 webapp .sanity_checks (nuke = True ) # should not raise
124146
147+ assert len (api_responses .calls ) == 0
148+
125149
126150# CREATE
127151## /api/v0/user/{username}/webapps/ : POST
0 commit comments