From e70fb8b78a09f6c985a6797fc3a774c6108b445a Mon Sep 17 00:00:00 2001 From: Piotr Kaznowski Date: Fri, 18 Dec 2020 13:24:57 +0100 Subject: [PATCH] #29 adds Files sharing delete method, updates test class names to match method names. by Piotr --- pythonanywhere/api/files_api.py | 10 ++++++++-- tests/test_api_files.py | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pythonanywhere/api/files_api.py b/pythonanywhere/api/files_api.py index 2579d82..cb888c6 100644 --- a/pythonanywhere/api/files_api.py +++ b/pythonanywhere/api/files_api.py @@ -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 ********************************** @@ -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 diff --git a/tests/test_api_files.py b/tests/test_api_files.py index fe08ab6..5b2c959 100644 --- a/tests/test_api_files.py +++ b/tests/test_api_files.py @@ -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, ): @@ -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"] @@ -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}") @@ -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 ): @@ -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/") @@ -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