Skip to content

Commit ec52d9c

Browse files
Makes auto ssl check for errors.
1 parent f60ad24 commit ec52d9c

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pythonanywhere-core"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
description = "API wrapper for programmatic management of PythonAnywhere services."
55
authors = ["PythonAnywhere <developers@pythonanywhere.com>"]
66
license = "MIT"

pythonanywhere_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.3.1"

pythonanywhere_core/website.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def auto_ssl(self, domain_name: str) -> dict:
9090
"post",
9191
json={"cert_type": "letsencrypt-auto-renew"}
9292
)
93+
if not response.ok:
94+
raise PythonAnywhereApiException(
95+
f"POST to set Let's Encrypt SSL certificate via API failed, got {response}:{response.text}"
96+
)
9397
return response.json()
9498

9599
def get_ssl_info(self, domain_name) -> dict:

tests/test_website.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ def test_sets_lets_encrypt_cert(api_responses, domain_name, domains_base_url):
170170
}
171171

172172

173+
def test_raises_if_setting_lets_encrypt_cert_does_not_return_200(
174+
api_responses, domain_name, domains_base_url
175+
):
176+
api_responses.add(
177+
responses.POST,
178+
url=f"{domains_base_url}{domain_name}/ssl/",
179+
status=500,
180+
body='{"status": "error", "error_message": "Certificate issuance failed"}',
181+
)
182+
183+
with pytest.raises(PythonAnywhereApiException) as e:
184+
Website().auto_ssl(domain_name=domain_name)
185+
186+
assert "POST to set Let's Encrypt SSL certificate via API failed, got" in str(e.value)
187+
assert "Certificate issuance failed" in str(e.value)
188+
189+
173190
def test_returns_ssl_info(api_responses, domain_name, domains_base_url):
174191
api_responses.add(
175192
responses.GET,

0 commit comments

Comments
 (0)