mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2026-10-26 14:40:05 -05:00
Give the File Manager save tests an absolute path in desktop mode, where there is no storage directory. #10674
In desktop mode get_storage_directory() returns None and a path is absolute, so check_access_permission() returns it unchanged. These tests patch in a storage directory in either mode and passed a path relative to it, which in desktop mode named a file at the root of the filesystem, so the save failed. They now pass a path inside the storage directory in desktop mode, as a desktop user would.
This commit is contained in:
1 parent
d91a2745f0
commit
b39f1a8d79
2 files changed
+14
-4
No files matched your search
@@ -19,6 +19,7 @@ import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import config
|
||||
from pgadmin.misc.file_manager import Filemanager
|
||||
from pgadmin.utils.constants import MY_STORAGE
|
||||
from pgadmin.utils.route import BaseTestGenerator
|
||||
@@ -77,6 +78,11 @@ class TestFileEncodingRoundTrip(BaseTestGenerator):
|
||||
def _path(self, name):
|
||||
return os.path.join(self.storage_dir, name.lstrip('/'))
|
||||
|
||||
def _file_name(self, name):
|
||||
# In server mode a path is relative to the storage directory; in
|
||||
# desktop mode there is no storage directory and a path is absolute.
|
||||
return name if config.SERVER_MODE else self._path(name)
|
||||
|
||||
def _post(self, url, payload):
|
||||
with contextlib.ExitStack() as stack:
|
||||
stack.enter_context(
|
||||
@@ -90,12 +96,13 @@ class TestFileEncodingRoundTrip(BaseTestGenerator):
|
||||
content_type='application/json')
|
||||
|
||||
def runTest(self):
|
||||
response = self._post(LOAD_FILE_URL, {'file_name': self.load})
|
||||
response = self._post(LOAD_FILE_URL,
|
||||
{'file_name': self._file_name(self.load)})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
loaded = response.data.decode('utf-8')
|
||||
|
||||
response = self._post(SAVE_FILE_URL, {
|
||||
'file_name': self.save,
|
||||
'file_name': self._file_name(self.save),
|
||||
'file_content': loaded if self.edit is None else self.edit,
|
||||
})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
@@ -684,10 +684,13 @@ class TestSaveFileWritesRegularFile(_SaveFileMixin, BaseTestGenerator):
|
||||
scenarios = [('default', dict())]
|
||||
|
||||
def runTest(self):
|
||||
response = self._save_file("/ok.sql", "SELECT 1;")
|
||||
target = os.path.join(self.storage_dir, "ok.sql")
|
||||
# In desktop mode there is no storage directory and a path is
|
||||
# absolute.
|
||||
response = self._save_file(
|
||||
"/ok.sql" if config.SERVER_MODE else target, "SELECT 1;")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
target = os.path.join(self.storage_dir, "ok.sql")
|
||||
with open(target, "rb") as f:
|
||||
self.assertEqual(f.read(), b"SELECT 1;")
|
||||
# In server mode the helper opens with mode 0o600; pin it so the
|
||||
|
||||
Reference in new issue
Block a user