Skip to content

Commit

Permalink
update tests to (mostly) work within same container
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ11teen committed May 16, 2021
1 parent 22a73fe commit 608aa4d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 42 deletions.
11 changes: 10 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from uuid import uuid4
import logging

import pytest

from cloudmappings.storageproviders.azureblobstorage import AzureBlobStorageProvider
from cloudmappings.storageproviders.googlecloudstorage import GoogleCloudStorageProvider
from cloudmappings.storageproviders.awss3 import AWSS3Provider
from cloudmappings.cloudstoragemapping import CloudMapping


def pytest_addoption(parser):
Expand Down Expand Up @@ -31,11 +33,13 @@ def pytest_addoption(parser):


storage_providers = {}
test_run_id = str(uuid4())


def pytest_configure(config):
test_container_name = f"pytest-{config.getoption('test_container_id')}"
logging.info(f"Using cloud containers with the name: {test_container_name}")
logging.info(f"Using keys with the prefix: {test_run_id}")

azure_storage_account_url = config.getoption("azure_storage_account_url")
if azure_storage_account_url is not None:
Expand Down Expand Up @@ -65,3 +69,8 @@ def pytest_generate_tests(metafunc):
ids=storage_providers.keys(),
scope="session",
)


@pytest.fixture
def test_id():
return test_run_id
87 changes: 46 additions & 41 deletions tests/tests/2_singletoncloudstoragemapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,71 @@ class SingletonCloudMappingTests:
def test_initialising_mapping(self, storage_provider):
cm = CloudMapping(storageprovider=storage_provider)

def test_basic_setting_and_getting(self, storage_provider):
def test_repr(self, storage_provider):
cm = CloudMapping(storageprovider=storage_provider)

cm["key-A"] = b"100"
cm["key-a"] = b"uncapitalised"
cm["key-3"] = b"three"
_repr = str(cm)

assert "CloudStorageProvider=" in _repr

assert cm["key-A"] == b"100"
assert cm["key-a"] == b"uncapitalised"
assert cm["key-3"] == b"three"
if "Azure" in _repr:
assert "StorageAccountName=" in _repr
assert "ContainerName=" in _repr
elif "Google" in _repr:
assert "Project=" in _repr
assert "BucketName=" in _repr
elif "AWS" in _repr:
assert "BucketName=" in _repr

def test_complex_keys(self, storage_provider):
def test_basic_setting_and_getting(self, storage_provider, test_id):
cm = CloudMapping(storageprovider=storage_provider)

cm["here/are/some/sub/dirs"] = b"0"
cm["howaboutsome ˆøœ¨åß∆∫ı˜ unusual !@#$%^* characters"] = b"1"
cm[test_id + "-key-A"] = b"100"
cm[test_id + "-key-a"] = b"uncapitalised"
cm[test_id + "-key-3"] = b"three"

assert cm["here/are/some/sub/dirs"] == b"0"
assert cm["howaboutsome ˆøœ¨åß∆∫ı˜ unusual !@#$%^* characters"] == b"1"
assert cm[test_id + "-key-A"] == b"100"
assert cm[test_id + "-key-a"] == b"uncapitalised"
assert cm[test_id + "-key-3"] == b"three"

def test_deleting_keys(self, storage_provider):
def test_complex_keys(self, storage_provider, test_id):
cm = CloudMapping(storageprovider=storage_provider)

cm["1"] = b"0"
del cm["1"]
with pytest.raises(KeyError):
cm["1"]
cm[test_id + "/here/are/some/sub/dirs"] = b"0"
cm[test_id + "/howaboutsome ˆøœ¨åß∆∫ı˜ unusual !@#$%^* characters"] = b"1"

def test_contains(self, storage_provider):
cm = CloudMapping(storageprovider=storage_provider)
assert cm[test_id + "/here/are/some/sub/dirs"] == b"0"
assert cm[test_id + "/howaboutsome ˆøœ¨åß∆∫ı˜ unusual !@#$%^* characters"] == b"1"

assert "1" not in cm
def test_deleting_keys(self, storage_provider, test_id):
cm = CloudMapping(storageprovider=storage_provider)
key = test_id + "/delete-test"

cm["1"] = b"1"
assert "1" in cm
cm[key] = b"0"
del cm[key]
with pytest.raises(KeyError):
cm[key]

def test_length(self, storage_provider):
def test_contains(self, storage_provider, test_id):
cm = CloudMapping(storageprovider=storage_provider)
key = test_id + "/contains-test"

assert len(cm) == 0
assert key not in cm

cm["a"] = b"100"
cm["b"] = b"uncapitalised"
assert len(cm) == 2
cm[key] = b"0"
assert key in cm

cm["c"] = b"three"
assert len(cm) == 3

def test_repr(self, storage_provider):
def test_length(self, storage_provider, test_id):
cm = CloudMapping(storageprovider=storage_provider)
key_1 = test_id + "/length-test/1"
key_2 = test_id + "/length-test/2"
key_3 = test_id + "/length-test/3"

_repr = str(cm)
starting_length = len(cm)

assert "CloudStorageProvider=" in _repr
cm[key_1] = b"a"
cm[key_2] = b"b"
assert len(cm) == starting_length + 2

if "Azure" in _repr:
assert "StorageAccountName=" in _repr
assert "ContainerName=" in _repr
elif "Google" in _repr:
assert "Project=" in _repr
assert "BucketName=" in _repr
elif "AWS" in _repr:
assert "BucketName=" in _repr
cm[key_3] = b"c"
assert len(cm) == starting_length + 3

0 comments on commit 608aa4d

Please sign in to comment.