Skip to content

Commit

Permalink
#114 Tried to fix the integration test error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Apr 22, 2024
1 parent 9a2c1ad commit 3adfd30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions exasol/bucketfs/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from io import IOBase
from exasol.bucketfs._buckets import BucketLike, SaaSBucket, MountedBucket
from exasol.bucketfs._service import Service
from exasol.bucketfs._error import BucketFsError


class SystemType(Enum):
Expand Down Expand Up @@ -390,24 +391,24 @@ def _create_onprem_bucket(url: str,
username: str,
password: str,
bucket_name: str = 'default',
verify_ca: bool = True,
**kwargs) -> BucketLike:
verify_ca: bool = True
) -> BucketLike:
"""
Creates an on-prem bucket.
"""
credentials = {bucket_name: {'username': username, 'password': password}}
service = Service(url, credentials, verify_ca)
buckets = service.buckets
if bucket_name not in buckets:
raise ValueError(f'Bucket {bucket_name} does not exist.')
raise BucketFsError(f'Bucket {bucket_name} does not exist.')
return buckets[bucket_name]


def _create_saas_bucket(account_id: str,
database_id: str,
pat: str,
url: str = 'https://cloud.exasol.com',
**kwargs) -> BucketLike:
url: str = 'https://cloud.exasol.com'
) -> BucketLike:
"""
Creates a SaaS bucket.
"""
Expand All @@ -416,16 +417,21 @@ def _create_saas_bucket(account_id: str,

def _create_mounted_bucket(service_name: str = 'bfsdefault',
bucket_name: str = 'default',
**kwargs) -> BucketLike:
) -> BucketLike:
"""
Creates a bucket mounted to a UDF.
"""
return MountedBucket(service_name, bucket_name)
bucket = MountedBucket(service_name, bucket_name)
if not bucket.root.exists():
raise BucketFsError(f'Bucket {bucket_name} does not exist.')
return bucket


def build_path(**kwargs) -> PathLike:

system_type = kwargs.get('system', SystemType.onprem)
system_type = kwargs.pop('system', SystemType.onprem)
path = kwargs.pop('path') if 'path' in kwargs else ''

if isinstance(system_type, str):
system_type = SystemType[system_type.lower()]
if system_type == SystemType.onprem:
Expand All @@ -434,5 +440,5 @@ def build_path(**kwargs) -> PathLike:
bucket = _create_saas_bucket(**kwargs)
else:
bucket = _create_mounted_bucket(**kwargs)
path = kwargs.get('path', '')

return BucketPath(path, bucket)
2 changes: 1 addition & 1 deletion test/integration/test_bucket_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_write_delete_onprem(test_config, children_poem, classic_poem):

base_path = build_path(system=SystemType.onprem, url=test_config.url,
username=test_config.username, password=test_config.password)
poems_root = base_path / 'my_poems'
poems_root = base_path / 'my_new_poems'
poem_path1 = poems_root / 'children/little_star.txt'
poem_path2 = poems_root / 'classic/highlands.txt'

Expand Down

0 comments on commit 3adfd30

Please sign in to comment.