Skip to content

Commit

Permalink
#29 small fixes to files
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Mar 13, 2021
1 parent 1cb65f3 commit 48afd5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pythonanywhere/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, path):
self.api = Files()

def __repr__(self):
return self.url
return self.url

def _make_sharing_url(self, path):
return urljoin(self.api.base_url.split("api")[0], path)
Expand Down
17 changes: 8 additions & 9 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_make_sharing_url_contains_pa_site_address(self, mocker):
mock_urljoin = mocker.patch("pythonanywhere.files.urljoin")
pa_path = PAPath('path')

url = pa_path._make_sharing_url('rest')
pa_path._make_sharing_url('rest')

assert mock_urljoin.call_args == call(pa_path.api.base_url.split("api")[0], 'rest')

Expand Down Expand Up @@ -125,6 +125,7 @@ def test_warns_about_failed_deletion(self, mocker):
PAPath(undeletable_path).delete()

assert mock_snake.call_args == call("error msg")
assert mock_warning.call_args == call(mock_snake.return_value)


@pytest.mark.files
Expand All @@ -142,7 +143,7 @@ def test_informs_about_successful_upload_of_a_file(self, mocker):
assert mock_post.call_args == call(destination_path, content)
assert mock_snake.call_args == call(f"Content successfully uploaded to {destination_path}!")
assert mock_info.call_args == call(mock_snake.return_value)
assert result == True
assert result is True

def test_informs_about_successful_update_of_existing_file_with_provided_stream(self, mocker):
mock_post = mocker.patch("pythonanywhere.api.files_api.Files.path_post")
Expand All @@ -157,15 +158,13 @@ def test_informs_about_successful_update_of_existing_file_with_provided_stream(s
assert mock_post.call_args == call(destination_path, content)
assert mock_snake.call_args == call(f"{destination_path} successfully updated!")
assert mock_info.call_args == call(mock_snake.return_value)
assert result == True

assert result is True

def test_warns_when_file_has_not_been_uploaded(self, mocker):
mock_post = mocker.patch("pythonanywhere.api.files_api.Files.path_post")
mock_post.side_effect = Exception("sth went wrong")
mock_warning = mocker.patch("pythonanywhere.files.logger.warning")
mock_snake = mocker.patch("pythonanywhere.files.snakesay")
mock_info = mocker.patch("pythonanywhere.files.logger.info")
destination_path = "wrong/path"
content = "content".encode()

Expand All @@ -174,7 +173,7 @@ def test_warns_when_file_has_not_been_uploaded(self, mocker):
assert mock_post.call_args == call(destination_path, content)
assert mock_snake.call_args == call("sth went wrong")
assert mock_warning.call_args == call(mock_snake.return_value)
assert result == False
assert result is False


@pytest.mark.files
Expand Down Expand Up @@ -269,7 +268,7 @@ def test_path_is_not_shared_so_cannot_be_unshared(self, mocker):
f"{path_to_unshare} is not being shared, no need to stop sharing..."
)
assert mock_info.call_args == call(mock_snake.return_value)
assert result == True
assert result is True

def test_path_successfully_unshared(self, mocker):
mock_sharing_get = mocker.patch("pythonanywhere.api.files_api.Files.sharing_get")
Expand All @@ -286,7 +285,7 @@ def test_path_successfully_unshared(self, mocker):
assert mock_sharing_delete.call_args == call(path_to_shared_file)
assert mock_snake.call_args == call(f"{path_to_shared_file} is no longer shared!")
assert mock_info.call_args == call(mock_snake.return_value)
assert result == True
assert result is True

def test_warns_if_unshare_not_successful(self, mocker):
mock_sharing_get = mocker.patch("pythonanywhere.api.files_api.Files.sharing_get")
Expand All @@ -303,4 +302,4 @@ def test_warns_if_unshare_not_successful(self, mocker):
assert mock_sharing_delete.call_args == call(path_to_shared_file)
assert mock_snake.call_args == call(f"Could not unshare {path_to_shared_file}... :(")
assert mock_warning.call_args == call(mock_snake.return_value)
assert result == False
assert result is False

0 comments on commit 48afd5f

Please sign in to comment.