Skip to content

Commit

Permalink
#75 Fixed the bucketfs_location tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Oct 4, 2024
1 parent d70d668 commit cc54e97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def create_bucketfs_location(**kwargs) -> bfs.path.PathLike:


@dataclass
class ConnObjectData:
class ConnectionInfo:
"""
This is not a connection object. It's just a structure to keep together the data
required for creating a BucketFs connection object. Useful for testing.
Expand All @@ -127,7 +127,7 @@ def _to_json_str(bucketfs_params: dict[str, Any], selected: list[str]) -> str:

def write_bucketfs_conn_object(pyexasol_connection: pyexasol.ExaConnection,
conn_name: str,
conn_obj: ConnObjectData) -> None:
conn_obj: ConnectionInfo) -> None:

query = (f"CREATE OR REPLACE CONNECTION {conn_name} "
f"TO '{conn_obj.to}' "
Expand Down Expand Up @@ -157,7 +157,7 @@ def create_bucketfs_conn_object_onprem(pyexasol_connection: pyexasol.ExaConnecti
conn_password = _to_json_str(bucketfs_params, ['password'])

write_bucketfs_conn_object(pyexasol_connection, conn_name,
ConnObjectData(conn_to, conn_user, conn_password))
ConnectionInfo(conn_to, conn_user, conn_password))


def create_bucketfs_conn_object_saas(pyexasol_connection: pyexasol.ExaConnection,
Expand All @@ -180,7 +180,7 @@ def create_bucketfs_conn_object_saas(pyexasol_connection: pyexasol.ExaConnection
conn_password = _to_json_str(bucketfs_params, ['pat'])

write_bucketfs_conn_object(pyexasol_connection, conn_name,
ConnObjectData(conn_to, conn_user, conn_password))
ConnectionInfo(conn_to, conn_user, conn_password))


def create_bucketfs_conn_object(conn_name: str, **kwargs) -> None:
Expand Down
12 changes: 8 additions & 4 deletions test/integration/connections/test_bucketfs_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
create_bucketfs_location,
create_bucketfs_conn_object,
create_bucketfs_location_from_conn_object,
ConnObjectData)
ConnectionInfo)

TEST_FILE_CONTENT = b'A rose by any other name would smell as sweet.'

Expand All @@ -27,8 +27,8 @@ def rubbish_params() -> dict[str, Any]:

@contextmanager
def write_test_file(bfs_path: bfs.path.PathLike) -> None:
bfs_path.write(TEST_FILE_CONTENT)
try:
bfs_path.write(TEST_FILE_CONTENT)
yield
finally:
# We cannot reuse the same path, in subsequent tests because of the
Expand All @@ -44,7 +44,7 @@ def validate_test_file(bfs_path: bfs.path.PathLike) -> None:

def validate_conn_object(pyexasol_connection: pyexasol.ExaConnection,
conn_name: str,
conn_obj: ConnObjectData):
conn_obj: ConnectionInfo):
bfs_path = create_bucketfs_location_from_conn_object(conn_obj)
validate_test_file(bfs_path)

Expand Down Expand Up @@ -99,8 +99,12 @@ def test_create_bucketfs_conn_object_onprem(write_conn_object_mock,
extra_params = {StdParams.path_in_bucket.name: 'test_create_conn_object'}
bfs_path = create_bucketfs_location(**onprem_bfs_params, **extra_params)
with write_test_file(bfs_path):
# onprem_db_params and onprem_bfs_params have one item in common -
# use_ssl_cert_validation, so we need to take a union before using them as kwargs.
onprem_params = dict(onprem_db_params)
onprem_params.update(onprem_bfs_params)
create_bucketfs_conn_object(conn_name='ONPREM_TEST_BFS',
**onprem_db_params, **onprem_bfs_params, **extra_params)
**onprem_params, **extra_params)


@patch('exasol.python_extension_common.connections.bucketfs_location.write_bucketfs_conn_object')
Expand Down

0 comments on commit cc54e97

Please sign in to comment.