From b8dc8fa04369e07f5d152372eb6acaa857e2a957 Mon Sep 17 00:00:00 2001 From: Piotr Kaznowski Date: Sun, 17 Jan 2021 00:40:58 +0100 Subject: [PATCH] #29 contents in files interface are now a property --- pythonanywhere/files.py | 1 + tests/test_files.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pythonanywhere/files.py b/pythonanywhere/files.py index 2751e40..1c8652a 100644 --- a/pythonanywhere/files.py +++ b/pythonanywhere/files.py @@ -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) diff --git a/tests/test_files.py b/tests/test_files.py index 6c0aba3..1aca7ba 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -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() @@ -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 @@ -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)