-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the unit tests for the boto3 store
- Loading branch information
1 parent
c898de1
commit 81c1023
Showing
3 changed files
with
105 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
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,88 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
|
||
import pytest | ||
|
||
boto3 = pytest.importorskip('boto3') | ||
from simplekv.net.botostore import BotoStore | ||
from simplekv._compat import BytesIO | ||
|
||
from basic_store import BasicStore | ||
from url_store import UrlStore | ||
from bucket_manager import boto_credentials, boto3_bucket | ||
from conftest import ExtendedKeyspaceTests | ||
from simplekv.contrib import ExtendedKeyspaceMixin | ||
|
||
|
||
@pytest.fixture(params=boto_credentials, | ||
ids=[c['access_key'] for c in boto_credentials]) | ||
def credentials(request): | ||
return request.param | ||
|
||
|
||
@pytest.yield_fixture() | ||
def bucket(credentials): | ||
with boto3_bucket(**credentials) as bucket: | ||
yield bucket | ||
|
||
|
||
class TestBotoStorage(BasicStore, UrlStore): | ||
@pytest.fixture(params=[True, False]) | ||
def reduced_redundancy(self, request): | ||
return request.param | ||
|
||
@pytest.fixture | ||
def storage_class(self, reduced_redundancy): | ||
return 'REDUCED_REDUNDANCY' if reduced_redundancy else 'STANDARD' | ||
|
||
@pytest.fixture(params=['', '/test-prefix']) | ||
def prefix(self, request): | ||
return request.param | ||
|
||
@pytest.fixture | ||
def store(self, bucket, prefix, reduced_redundancy): | ||
return BotoStore(bucket, prefix, reduced_redundancy=reduced_redundancy) | ||
|
||
# Disable max key length test as it leads to problems with minio | ||
test_max_key_length = None | ||
|
||
def test_get_filename_nonexistant(self, store, key, tmp_path): | ||
with pytest.raises(KeyError): | ||
store.get_file(key, os.path.join(str(tmp_path), 'a')) | ||
|
||
def test_key_error_on_nonexistant_get_filename(self, store, key, tmp_path): | ||
with pytest.raises(KeyError): | ||
store.get_file(key, os.path.join(str(tmp_path), 'a')) | ||
|
||
def test_storage_class_put( | ||
self, store, prefix, key, value, storage_class, bucket | ||
): | ||
store.put(key, value) | ||
|
||
keyname = prefix + key | ||
|
||
if storage_class != 'STANDARD': | ||
pytest.xfail('boto does not support checking the storage class?') | ||
|
||
assert bucket.Object(keyname).storage_class == storage_class | ||
|
||
def test_storage_class_putfile( | ||
self, store, prefix, key, value, storage_class, bucket | ||
): | ||
store.put_file(key, BytesIO(value)) | ||
|
||
keyname = prefix + key | ||
|
||
if storage_class != 'STANDARD': | ||
pytest.xfail('boto does not support checking the storage class?') | ||
assert bucket.Object(keyname).storage_class == storage_class | ||
|
||
|
||
class TestExtendedKeyspaceBotoStore(TestBotoStorage, ExtendedKeyspaceTests): | ||
@pytest.fixture | ||
def store(self, bucket, prefix, reduced_redundancy): | ||
class ExtendedKeyspaceStore(ExtendedKeyspaceMixin, BotoStore): | ||
pass | ||
return ExtendedKeyspaceStore(bucket, prefix, | ||
reduced_redundancy=reduced_redundancy) |