Skip to content

Commit 551d2c0

Browse files
committed
Use proper payload field in Website.create api call, by Piotr
1 parent 10c1678 commit 551d2c0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

pythonanywhere_core/website.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def create(self, domain_name: str, command: str):
1111
response = call_api(
1212
self.api_endpoint,
1313
"post",
14-
data={
14+
json={
1515
"domain_name": domain_name,
1616
"enabled": True,
1717
"webapp": {"command": command}

tests/test_website.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ def website_info(domain_name, command):
3737
"webapp": {
3838
"command": command,
3939
"domains": [
40-
{"domain_name": domain_name,
41-
"enabled": True}
40+
{
41+
"domain_name": domain_name,
42+
"enabled": True
43+
}
4244
],
4345
"id": 42
4446
}
@@ -51,9 +53,16 @@ def test_create_returns_json_with_created_website_info(
5153
api_responses.add(
5254
responses.POST, url=webapps_base_url, status=201, body=json.dumps(website_info)
5355
)
56+
expected_request_body = json.dumps(
57+
{"domain_name": domain_name, "enabled": True, "webapp": {"command": command}}
58+
).encode()
5459

55-
assert Website().create(domain_name=domain_name, command=command) == website_info
60+
result = Website().create(domain_name=domain_name, command=command)
5661

62+
assert result == website_info
63+
assert api_responses.calls[0].request.body == expected_request_body, (
64+
"POST to create needs the payload to be passed as json field"
65+
)
5766

5867
def test_get_returns_json_with_info_for_given_domain(
5968
api_responses, webapps_base_url, website_info, domain_name

0 commit comments

Comments
 (0)