Skip to content

Commit 0f4eff3

Browse files
makes sharing_post return message and file sharing link.
1 parent 50846c5 commit 0f4eff3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

pythonanywhere_core/files.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,18 @@ def path_delete(self, path: str) -> int:
119119
def sharing_post(self, path: str) -> Tuple[int, str]:
120120
"""Starts sharing a file at `path`.
121121
122-
Returns a tuple with a status code and sharing link on
123-
success, raises otherwise. Status code is 201 on success, 200
124-
if file has been already shared."""
122+
Returns a tuple with a message and sharing link on
123+
success, raises otherwise. Message is "successfully shared" on success,
124+
"was already shared" if file has been already shared."""
125125

126126
url = self.sharing_endpoint
127127

128128
result = call_api(url, "POST", json={"path": path})
129129

130130
if result.ok:
131-
return result.status_code, result.json()["url"]
131+
msg = {200: "was already shared", 201: "successfully shared"}[result.status_code]
132+
sharing_url_suffix = result.json()["url"]
133+
return msg, self._make_sharing_url(sharing_url_suffix)
132134

133135
raise PythonAnywhereApiException(
134136
f"POST to {url} to share '{path}' failed, got {result}{self._error_msg(result)}"

tests/test_files.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def test_sharing_post_returns_url_when_path_successfully_shared_or_has_been_shar
252252
):
253253
valid_path = f"{home_dir_path}/README.txt"
254254
shared_url = f"/user/{username}/shares/asdf1234/"
255+
sharing_url = urljoin(base_url.split("api")[0], shared_url)
255256
partial_response = dict(
256257
method=responses.POST,
257258
url=urljoin(base_url, "sharing/"),
@@ -264,13 +265,13 @@ def test_sharing_post_returns_url_when_path_successfully_shared_or_has_been_shar
264265
files = Files()
265266
first_share = files.sharing_post(valid_path)
266267

267-
assert first_share[0] == 201
268-
assert first_share[1] == shared_url
268+
assert first_share[0] == "successfully shared"
269+
assert first_share[1] == sharing_url
269270

270271
second_share = files.sharing_post(valid_path)
271272

272-
assert second_share[0] == 200
273-
assert second_share[1] == shared_url
273+
assert second_share[0] == "was already shared"
274+
assert second_share[1] == sharing_url
274275

275276

276277
@pytest.mark.skip(reason="not implemented in the api yet")

0 commit comments

Comments
 (0)