Skip to content

Commit

Permalink
#29 contents in files interface are now a property
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Jan 16, 2021
1 parent 9a09dee commit b8dc8fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions pythonanywhere/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def url(self):
files_base = self.api.base_url.replace("/api/v0", "")
return f"{files_base[:-1]}{self.path}"

@property
def contents(self):
try:
content = self.api.path_get(self.path)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_returns_file_contents_as_string_if_path_points_to_a_file(self, mocker):
mock_path_get = mocker.patch("pythonanywhere.api.files_api.Files.path_get")
mock_path_get.return_value = self.readme_contents

result = PAPath(path).contents()
result = PAPath(path).contents

assert mock_path_get.call_args == call(path)
assert result == self.readme_contents.decode()
Expand All @@ -55,7 +55,7 @@ def test_returns_directory_contents_if_path_points_to_a_directory(self, mocker):
mock_path_get = mocker.patch("pythonanywhere.api.files_api.Files.path_get")
mock_path_get.return_value = self.default_home_dir_files

result = PAPath(self.home_dir_path).contents()
result = PAPath(self.home_dir_path).contents

assert result == self.default_home_dir_files

Expand All @@ -65,7 +65,7 @@ def test_warns_when_path_unavailable(self, mocker):
mock_snake = mocker.patch("pythonanywhere.files.snakesay")
mock_warning = mocker.patch("pythonanywhere.files.logger.warning")

result = PAPath('/home/different_user').contents()
result = PAPath('/home/different_user').contents

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

0 comments on commit b8dc8fa

Please sign in to comment.