Skip to content

Commit

Permalink
#114 Added the first integration test for the path builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Apr 22, 2024
1 parent ea77009 commit ce3e392
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
4 changes: 4 additions & 0 deletions exasol/bucketfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

from exasol.bucketfs._buckets import (
Bucket,
SaaSBucket,
MountedBucket,
MappedBucket,
)
from exasol.bucketfs._convert import (
Expand All @@ -61,6 +63,8 @@
__all__ = [
"Service",
"Bucket",
"SaaSBucket",
"MountedBucket",
"MappedBucket",
"BucketFsError",
"as_bytes",
Expand Down
7 changes: 2 additions & 5 deletions exasol/bucketfs/_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,15 @@ 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:
return self._name

@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.')
Expand Down
25 changes: 25 additions & 0 deletions test/integration/test_bucket_path.py
Original file line number Diff line number Diff line change
@@ -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,
)
17 changes: 17 additions & 0 deletions test/unit/bucketfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,20 @@ def test_dunder_str_of_mapped_bucket():
)
expected = "MappedBucket<Bucket<foobar | on: https://127.0.0.1:6666>>"
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

0 comments on commit ce3e392

Please sign in to comment.