diff --git a/exasol/bucketfs/__init__.py b/exasol/bucketfs/__init__.py index 57a7bf42..792b7721 100644 --- a/exasol/bucketfs/__init__.py +++ b/exasol/bucketfs/__init__.py @@ -47,6 +47,8 @@ from exasol.bucketfs._buckets import ( Bucket, + SaaSBucket, + MountedBucket, MappedBucket, ) from exasol.bucketfs._convert import ( @@ -61,6 +63,8 @@ __all__ = [ "Service", "Bucket", + "SaaSBucket", + "MountedBucket", "MappedBucket", "BucketFsError", "as_bytes", diff --git a/exasol/bucketfs/_buckets.py b/exasol/bucketfs/_buckets.py index 2f44eec3..1079ce0a 100644 --- a/exasol/bucketfs/_buckets.py +++ b/exasol/bucketfs/_buckets.py @@ -277,7 +277,7 @@ def __init__(self, service_name: str, bucket_name: str): self._name = bucket_name - self.root = Path(service_name) / bucket_name + self.root = Path('buckets') / service_name / bucket_name @property def name(self) -> str: @@ -285,10 +285,7 @@ def name(self) -> str: @property def files(self) -> list[str]: - root_length = len(str(self.root)) - if self.root != self.root.root: - root_length += 1 - return [str(pth)[root_length:] for pth in self.root.rglob('*.*')] + return [str(pth.relative_to(self.root)) for pth in self.root.rglob('*.*')] def delete(self, path: str) -> None: raise PermissionError('File deletion is not allowed.') diff --git a/test/integration/test_bucket_path.py b/test/integration/test_bucket_path.py new file mode 100644 index 00000000..ba15a64e --- /dev/null +++ b/test/integration/test_bucket_path.py @@ -0,0 +1,25 @@ +from exasol.bucketfs._path import build_path, SYSTEM_TYPE_ONPREM +from integration.conftest import delete_file + + +def test_write_read_back(test_config): + + file_name = 'my_poems/little_star.txt' + data = b'twinkle twinkle little star how i wonder what you are' + base_path = build_path(system=SYSTEM_TYPE_ONPREM, url=test_config.url, + username=test_config.username, password=test_config.password) + poem_path = base_path / file_name + + try: + poem_path.write(data) + data_back = b''.join(poem_path.read(20)) + assert data_back == data + finally: + # cleanup + delete_file( + test_config.url, + 'default', + test_config.username, + test_config.password, + file_name, + ) diff --git a/test/unit/bucketfs_test.py b/test/unit/bucketfs_test.py index 27fc23cf..51379275 100644 --- a/test/unit/bucketfs_test.py +++ b/test/unit/bucketfs_test.py @@ -233,3 +233,20 @@ def test_dunder_str_of_mapped_bucket(): ) expected = "MappedBucket>" assert f"{bucket}" == expected + + +def test_mounted_bucket_files(bucket_fake): + content = set(bucket_fake.files) + expected_content = { + 'file00.dat', + 'file01.dat', + 'dir1/file10.dat', + 'dir1/file11.dat', + 'dir1/dir11/file110.dat', + 'dir1/dir11/file111.dat', + 'dir1/dir12/file120.dat', + 'dir1/dir12/file121.dat', + 'dir2/file20.dat', + 'dir2/file21.dat' + } + assert content == expected_content