Skip to content

Commit

Permalink
#29 adds Files sharing delete method, updates test class names to ma…
Browse files Browse the repository at this point in the history
…tch method names. by Piotr
  • Loading branch information
caseneuve committed Dec 18, 2020
1 parent ba70ccc commit e70fb8b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
10 changes: 8 additions & 2 deletions pythonanywhere/api/files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ class Files:
Covers:
- GET, POST and DELETE for files path endpoint
- POST for files sharing endpoint
- POST, GET and DELETE for files sharing endpoint
**********************************
TODOS:
- GET, DELETE for sharing path
- GET for tree
**********************************
Expand Down Expand Up @@ -127,3 +126,10 @@ def sharing_get(self, path):
result = call_api(url, "GET")

return result.json()["url"] if result.ok else ""

def sharing_delete(self, path):
url = f"{self.sharing_endpoint}?path={path}"

result = call_api(url, "DELETE")

return result.status_code
21 changes: 16 additions & 5 deletions tests/test_api_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestFiles:


@pytest.mark.files
class TestFilesGetPath(TestFiles):
class TestFilesPathGet(TestFiles):
def test_returns_contents_of_directory_when_path_to_dir_provided(
self, api_token, api_responses,
):
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_raises_because_wrong_path_provided(self, api_token, api_responses):


@pytest.mark.files
class TestFilesPostPath(TestFiles):
class TestFilesPathPost(TestFiles):
def test_returns_200_when_file_updated(self, api_token, api_responses):
existing_file_path = f"{self.home_dir_path}/README.txt"
existing_file_url = self.default_home_dir_files["README.txt"]["url"]
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_raises_when_no_contents_provided(self, api_token, api_responses):


@pytest.mark.files
class TestFilesDeletePath(TestFiles):
class TestFilesPathDelete(TestFiles):
def test_returns_204_on_successful_file_deletion(self, api_token, api_responses):
valid_path = f"{self.home_dir_path}/README.txt"
valid_url = urljoin(self.base_url, f"path{valid_path}")
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_raises_when_wrong_path_provided(self, api_token, api_responses):


@pytest.mark.files
class TestFilesPostSharing(TestFiles):
class TestFilesSharingPost(TestFiles):
def test_returns_url_when_path_successfully_shared_or_has_been_shared_before(
self, api_token, api_responses
):
Expand Down Expand Up @@ -269,7 +269,7 @@ def test_raises_exception_when_path_not_provided(self, api_token, api_responses)


@pytest.mark.files
class TestFilesGetSharing(TestFiles):
class TestFilesSharingGet(TestFiles):
def test_returns_sharing_url_when_path_is_shared(self, api_token, api_responses):
valid_path = f"{self.home_dir_path}/README.txt"
sharing_url = urljoin(self.base_url, f"sharing/")
Expand All @@ -292,3 +292,14 @@ def test_returns_empty_string_when_path_not_shared(self, api_token, api_response
api_responses.add(method=responses.GET, url=url, status=404)

assert Files().sharing_get(valid_path) == ""


@pytest.mark.files
class TestFilesSharingDelete(TestFiles):
def test_returns_204_on_sucessful_unshare(self, api_token, api_responses):
valid_path = f"{self.home_dir_path}/README.txt"
url = urljoin(self.base_url, f"sharing/?path={valid_path}")
shared_url = f"/user/{self.username}/shares/asdf1234/"
api_responses.add(method=responses.DELETE, url=url, status=204)

assert Files().sharing_delete(valid_path) == 204

0 comments on commit e70fb8b

Please sign in to comment.