Skip to content

Commit 73056c7

Browse files
committed
Updated logic in base.get_api_endpoint to return url with correct version based on provided flavor, by: Filip, Piotr
1 parent 386e8a1 commit 73056c7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pythonanywhere_core/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def get_api_endpoint(username: str, flavor: str) -> str:
2020
"PYTHONANYWHERE_SITE",
2121
"www." + os.environ.get("PYTHONANYWHERE_DOMAIN", "pythonanywhere.com"),
2222
)
23+
if flavor == "websites":
24+
return f"https://{hostname}/api/v1/user/{username}/{flavor}/"
2325
return f"https://{hostname}/api/v0/user/{username}/{flavor}/"
2426

2527

tests/test_base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ def test_get_api_endpoint_gets_domain_from_pythonanywhere_domain_and_adds_on_www
4141
assert result == "https://www.foo.com/api/v0/user/bill/webapp/"
4242

4343

44+
@pytest.mark.parametrize(
45+
"flavor,expected_version",
46+
[
47+
("files", "v0"),
48+
("schedule", "v0"),
49+
("students", "v0"),
50+
("webapps", "v0"),
51+
("websites", "v1"),
52+
]
53+
)
54+
def test_get_api_endpoint_returns_url_with_correct_api_version(flavor, expected_version):
55+
result = get_api_endpoint(username="bill", flavor=flavor)
56+
57+
assert result == f"https://www.pythonanywhere.com/api/{expected_version}/user/bill/{flavor}/"
58+
59+
4460
def test_raises_on_401(api_token, api_responses):
4561
url = "https://foo.com/"
4662
api_responses.add(responses.POST, url, status=401, body="nope")

0 commit comments

Comments
 (0)