Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/tests/test_objstorage_cloud.py
# Copyright (C) 2016 The Software Heritage developers | # Copyright (C) 2016 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
from libcloud.common.types import InvalidCredsError | from libcloud.common.types import InvalidCredsError | ||||
from libcloud.storage.types import (ContainerDoesNotExistError, | from libcloud.storage.types import (ContainerDoesNotExistError, | ||||
ObjectDoesNotExistError) | ObjectDoesNotExistError) | ||||
from typing import Optional | |||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from swh.objstorage.objstorage import decompressors | from swh.objstorage.objstorage import decompressors | ||||
from swh.objstorage.exc import Error | from swh.objstorage.exc import Error | ||||
from swh.objstorage.backends.libcloud import CloudObjStorage | from swh.objstorage.backends.libcloud import CloudObjStorage | ||||
from .objstorage_testing import ObjStorageTestFixture | from .objstorage_testing import ObjStorageTestFixture | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | class MockCloudObjStorage(CloudObjStorage): | ||||
def _get_provider(self): | def _get_provider(self): | ||||
# Implement this for the abc requirement, but behavior is defined in | # Implement this for the abc requirement, but behavior is defined in | ||||
# _get_driver. | # _get_driver. | ||||
pass | pass | ||||
class TestCloudObjStorage(ObjStorageTestFixture, unittest.TestCase): | class TestCloudObjStorage(ObjStorageTestFixture, unittest.TestCase): | ||||
compression = None # type: Optional[str] | compression = 'none' | ||||
def setUp(self): | def setUp(self): | ||||
super().setUp() | super().setUp() | ||||
self.storage = MockCloudObjStorage( | self.storage = MockCloudObjStorage( | ||||
CONTAINER_NAME, | CONTAINER_NAME, | ||||
api_key=API_KEY, api_secret_key=API_SECRET_KEY, | api_key=API_KEY, api_secret_key=API_SECRET_KEY, | ||||
compression=self.compression, | compression=self.compression, | ||||
) | ) | ||||
Show All 13 Lines | def test_trailing_data_on_stored_blob(self): | ||||
content, obj_id = self.hash_content(b'test content without garbage') | content, obj_id = self.hash_content(b'test content without garbage') | ||||
self.storage.add(content, obj_id=obj_id) | self.storage.add(content, obj_id=obj_id) | ||||
data = self.storage.driver.containers[CONTAINER_NAME] | data = self.storage.driver.containers[CONTAINER_NAME] | ||||
obj_id = hashutil.hash_to_hex(obj_id) | obj_id = hashutil.hash_to_hex(obj_id) | ||||
data[obj_id].content.append(b'trailing garbage') | data[obj_id].content.append(b'trailing garbage') | ||||
if self.compression is not None: | if self.compression == 'none': | ||||
with self.assertRaises(Error) as e: | with self.assertRaises(Error) as e: | ||||
self.storage.get(obj_id) | self.storage.check(obj_id) | ||||
assert 'trailing data' in e.exception.args[0] | |||||
else: | else: | ||||
with self.assertRaises(Error) as e: | with self.assertRaises(Error) as e: | ||||
self.storage.check(obj_id) | self.storage.get(obj_id) | ||||
assert 'trailing data' in e.exception.args[0] | |||||
class TestCloudObjStorageBz2(TestCloudObjStorage): | class TestCloudObjStorageBz2(TestCloudObjStorage): | ||||
compression = 'bz2' | compression = 'bz2' | ||||
class TestCloudObjStorageGzip(TestCloudObjStorage): | class TestCloudObjStorageGzip(TestCloudObjStorage): | ||||
compression = 'gzip' | compression = 'gzip' | ||||
class TestCloudObjStorageLzma(TestCloudObjStorage): | class TestCloudObjStorageLzma(TestCloudObjStorage): | ||||
compression = 'lzma' | compression = 'lzma' | ||||
class TestCloudObjStorageZlib(TestCloudObjStorage): | class TestCloudObjStorageZlib(TestCloudObjStorage): | ||||
compression = 'zlib' | compression = 'zlib' |