forked from exasol/bucketfs-utils-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for listing all accessible buckets of a bucketfs service * Add test for listing buckets * Update change-log Co-authored-by: Christoph Kuhnke <[email protected]>
- Loading branch information
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class BucketFsError(Exception): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from exasol_bucketfs_utils_python import BucketFsError | ||
import requests | ||
from typing import Iterator | ||
|
||
|
||
def list_buckets( | ||
base_url: str, | ||
path: str = "", | ||
port: int = 2580, | ||
) -> Iterator[str]: | ||
""" | ||
List all buckets for a specific bucketfs service. | ||
The following mapping will be applied for determining the final url: {base_url}:{port}/{path} | ||
:param base_url: URL of the bucketfs service e.g. http://127.0.0.1. | ||
:param path: if the service root is hidden behind a sub-path, the default "" should work in most cases. | ||
:param port: the bucketfs service is listening on (default: 2580). | ||
In case of error make sure the correct port is used. | ||
:raises BucketFsError: | ||
:return: all accessible buckets off the bucketfs service. | ||
""" | ||
url = f"{base_url}:{port}/{path}" | ||
try: | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
except Exception as ex: | ||
raise BucketFsError from ex | ||
lines = (line for line in response.text.split("\n") if not line.isspace()) | ||
return (line for line in lines if line != "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,59 @@ | ||
import pytest | ||
from dataclasses import dataclass | ||
|
||
|
||
def pytest_addoption(parser): | ||
option = "--bucketfs-{name}" | ||
group = parser.getgroup("bucketfs") | ||
group.addoption( | ||
option.format(name="port"), | ||
type=int, | ||
default=6666, | ||
help="Port on which the bucketfs service ist listening (default: 6666)." | ||
) | ||
group.addoption( | ||
option.format(name="url"), | ||
type=str, | ||
default="http://127.0.0.1", | ||
help="Base url used to connect to the bucketfs service (default: 'http://127.0.0.1')." | ||
) | ||
group.addoption( | ||
option.format(name="username"), | ||
type=str, | ||
default="w", | ||
help="Username used to authenticate against the bucketfs service (default: 'w')." | ||
) | ||
group.addoption( | ||
option.format(name="password"), | ||
type=str, | ||
default="write", | ||
help="Password used to authenticate against the bucketfs service (default: 'write')." | ||
) | ||
|
||
|
||
@dataclass | ||
class Config: | ||
"""Bucketfs integration test configuration""" | ||
url: str | ||
port: int | ||
username: str | ||
password: str | ||
|
||
|
||
@pytest.fixture | ||
def bucketfs_test_config(request) -> Config: | ||
options = request.config.option | ||
return Config( | ||
url=options.bucketfs_url, | ||
port=options.bucketfs_port, | ||
username=options.bucketfs_username, | ||
password=options.bucketfs_password | ||
) | ||
|
||
|
||
pytest_plugins = [ | ||
"tests.fixtures.build_language_container_fixture", | ||
"tests.fixtures.bucketfs_location_fixture", | ||
"tests.fixtures.upload_language_container_fixture", | ||
"tests.fixtures.prepare_bucket_fixture" | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from exasol_bucketfs_utils_python.buckets import list_buckets | ||
|
||
|
||
def test_all_default_buckets_are_listed(bucketfs_test_config): | ||
assert set(list(list_buckets( | ||
base_url=bucketfs_test_config.url, | ||
port=bucketfs_test_config.port | ||
))) == {'default', 'myudfs', 'jdbc_adapter'} |