added fixture magic for testing differen S3 backends

This commit is contained in:
Matthias Bisping 2022-02-24 15:08:29 +01:00
parent f3f1c42e57
commit 0eb7aaf795
3 changed files with 14 additions and 10 deletions

View File

@ -24,6 +24,9 @@ class DotIndexable:
def __repr__(self):
return self.x.__repr__()
def __getitem__(self, item):
return self.__getattr__(item)
class Config:
def __init__(self, config_path):

View File

@ -7,7 +7,7 @@ from pyinfra.exceptions import InvalidEndpoint
def parse_endpoint(endpoint):
endpoint_pattern = r"(?P<protocol>https?)://(?P<address>(?:(?:(?:\d{1,3}\.){3}\d{1,3})|\w+):\d+)"
endpoint_pattern = r"(?P<protocol>https?)://(?P<address>(?:(?:(?:\d{1,3}\.){3}\d{1,3})|(?:\w|\.)+)(?:\:\d+)?)"
match = re.match(endpoint_pattern, endpoint)

View File

@ -35,26 +35,27 @@ class TestStorage:
storage.make_bucket(bucket_name)
assert storage.bucket_exists(bucket_name)
def get_adapter(client_name):
def get_adapter(client_name, s3_backend):
if client_name == "mock":
return StorageAdapterMock(StorageClientMock())
if client_name == "azure":
return AzureStorageAdapter(get_azure_client(CONFIG.test.azure))
if client_name == "s3":
return S3StorageAdapter(get_s3_client(CONFIG.test.minio))
return S3StorageAdapter(get_s3_client(CONFIG.test[s3_backend]))
else:
raise UnknownClient(client_name)
@pytest.fixture
def adapter(client_name):
adapter = get_adapter(client_name)
return adapter
# @pytest.mark.parametrize("s3_backend", ["minio", "w"])
# def adapter(client_name, s3_backend):
# adapter = get_adapter(client_name, s3_backend)
# return adapter
@pytest.fixture
def storage(client_name, bucket_name):
storage = Storage(get_adapter(client_name))
@pytest.fixture(params=["minio", "aws"])
def storage(client_name, bucket_name, request):
storage = Storage(get_adapter(client_name, request.param))
storage.make_bucket(bucket_name)
storage.clear_bucket(bucket_name)
logging.info(client_name)