Skip to content

Commit

Permalink
#118 Added default_bucket_config fixture.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed May 1, 2024
1 parent 1a07ee5 commit ed6002e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
14 changes: 9 additions & 5 deletions tests/fixtures/prepare_bucket_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@


@pytest.fixture(scope="module")
def prepare_bucket():
def default_bucket_config():
connection_config = BucketFSConnectionConfig(
host="localhost", port=6666, user="w", pwd="write", is_https=False
)
bucketfs_config = BucketFSConfig(
connection_config=connection_config, bucketfs_name="bfsdefault"
)
bucket_config = BucketConfig(bucket_name="default", bucketfs_config=bucketfs_config)
return BucketConfig(bucket_name="default", bucketfs_config=bucketfs_config)


@pytest.fixture(scope="module")
def prepare_bucket(default_bucket_config):
test_string = "test_string"

path_list = ["path/in/bucket/file.txt", "path/file2.txt"]
try:
for path_in_bucket in path_list:
upload.upload_string_to_bucketfs(
bucket_config=bucket_config,
bucket_config=default_bucket_config,
bucket_file_path=path_in_bucket,
string=test_string,
)
yield bucket_config
yield default_bucket_config
finally:
for path_in_bucket in path_list:
delete_testfile_from_bucketfs(
file_path=path_in_bucket, bucket_config=bucket_config
file_path=path_in_bucket, bucket_config=default_bucket_config
)
24 changes: 12 additions & 12 deletions tests/integration_tests/without_db/test_bucketfs_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
from exasol_bucketfs_utils_python.bucketfs_factory import BucketFSFactory


def test_factory_http_default(prepare_bucket):
def test_factory_http_default(default_bucket_config):
"""
Tests that all operations work with the default varify option if the connection is http.
"""

bfs_config = prepare_bucket.bucketfs_config
bfs_config = default_bucket_config.bucketfs_config
conn_config = bfs_config.connection_config
url = f'http://{conn_config.host}:{conn_config.port}/{prepare_bucket.bucket_name}/'\
url = f'http://{conn_config.host}:{conn_config.port}/{default_bucket_config.bucket_name}/'\
f'base_dir;{bfs_config.bucketfs_name}'
bfs_location = BucketFSFactory().create_bucketfs_location(url=url, user=conn_config.user,
pwd=conn_config.pwd)

file_name = 'geography.fact'
file_name = 'test_factory_http_default/geography.fact'
content = 'Munich is the capital of Bavaria'
bfs_location.upload_string_to_bucketfs(file_name, content)
assert file_name in bfs_location.list_files_in_bucketfs()
Expand All @@ -24,39 +24,39 @@ def test_factory_http_default(prepare_bucket):
assert file_name not in bfs_location.list_files_in_bucketfs()


def test_factory_https_default(prepare_bucket):
def test_factory_https_default(default_bucket_config):
"""
Tests that the default varify option leads to failure if the connection is https.
"""

bfs_config = prepare_bucket.bucketfs_config
bfs_config = default_bucket_config.bucketfs_config
conn_config = bfs_config.connection_config
url = f'https://{conn_config.host}:{conn_config.port}/{prepare_bucket.bucket_name}/'\
url = f'https://{conn_config.host}:{conn_config.port}/{default_bucket_config.bucket_name}/'\
f'base_dir;{bfs_config.bucketfs_name}'
bfs_location = BucketFSFactory().create_bucketfs_location(url=url, user=conn_config.user,
pwd=conn_config.pwd)

file_name = 'geography.fact'
file_name = 'test_factory_https_default/geography.fact'
content = 'Munich is the capital of Bavaria'

with pytest.raises(Exception):
bfs_location.upload_string_to_bucketfs(file_name, content)


def test_factory_https_not_verify(prepare_bucket):
def test_factory_https_not_verify(default_bucket_config):
"""
Tests that all operations work with a https connection
if the certificate verification is turned off.
"""

bfs_config = prepare_bucket.bucketfs_config
bfs_config = default_bucket_config.bucketfs_config
conn_config = bfs_config.connection_config
url = f'https://{conn_config.host}:{conn_config.port}/{prepare_bucket.bucket_name}/'\
url = f'https://{conn_config.host}:{conn_config.port}/{default_bucket_config.bucket_name}/'\
f'base_dir;{bfs_config.bucketfs_name}#false'
bfs_location = BucketFSFactory().create_bucketfs_location(url=url, user=conn_config.user,
pwd=conn_config.pwd)

file_name = 'geography.fact'
file_name = 'test_factory_https_not_verify/geography.fact'
content = 'Munich is the capital of Bavaria'
bfs_location.upload_string_to_bucketfs(file_name, content)
assert file_name in bfs_location.list_files_in_bucketfs()
Expand Down

0 comments on commit ed6002e

Please sign in to comment.