|
7 | 7 | from pythonanywhere_core.base import get_api_endpoint |
8 | 8 | from pythonanywhere_core.exceptions import PythonAnywhereApiException |
9 | 9 | from pythonanywhere_core.website import Website |
| 10 | +from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException |
10 | 11 |
|
11 | 12 |
|
12 | 13 | pytestmark = pytest.mark.usefixtures("api_token") |
@@ -159,3 +160,31 @@ def test_raises_if_ssl_info_does_not_return_200(api_responses, domain_name, doma |
159 | 160 |
|
160 | 161 | assert "GET SSL details via API failed, got" in str(e.value) |
161 | 162 | assert "nope" in str(e.value) |
| 163 | + |
| 164 | + |
| 165 | +def test_website_sanity_check_domain_already_exists(api_responses, websites_base_url, website_info, domain_name): |
| 166 | + api_responses.add( |
| 167 | + responses.GET, |
| 168 | + url=f"{websites_base_url}{domain_name}/", |
| 169 | + status=200, |
| 170 | + body=json.dumps(website_info) |
| 171 | + ) |
| 172 | + |
| 173 | + with pytest.raises(SanityException) as e: |
| 174 | + Website().sanity_check(domain_name=domain_name, nuke=False) |
| 175 | + |
| 176 | + |
| 177 | +def test_website_sanity_check_can_be_bypassed_with_nuke_option(api_responses, websites_base_url, website_info, domain_name): |
| 178 | + # Test that the sanity check does not raise an exception |
| 179 | + Website().sanity_check(domain_name=domain_name, nuke=True) |
| 180 | + |
| 181 | + |
| 182 | +def test_website_sanity_check_tests_api_token_present(api_responses, websites_base_url, website_info, domain_name): |
| 183 | + import os |
| 184 | + del os.environ["API_TOKEN"] |
| 185 | + |
| 186 | + # Test that the sanity check does not raise an exception |
| 187 | + with pytest.raises(SanityException) as e: |
| 188 | + Website().sanity_check(domain_name=domain_name, nuke=False) |
| 189 | + |
| 190 | + assert "Could not find your API token" in str(e.value) |
0 commit comments