Make tempurl functional tests clean up account keys
Addresses a TODO in test/functional/test_account.py where an account metadata test was having to clean up tempurl keys in the account metadata that were left by another test in a different module. This cleanup is necessary because tests in test_account.py fail if there is any pre-existing account metadata. This patch: * makes the tempurl tests clean up their keys from account metadata. * makes the test_account.py:TestAccount class remove any pre-existing metadata before attempting any tests and replacing that metadata when all the tests in that class have completed. This is more robust than the existing code which only removes any tempurl keys that might be in the account - now you could have x-account-meta-foo = bar in the test account and test_account.py will still pass. * consolidates some common setup code currently repeated for many of the functional test classes into into a BaseEnv class. Change-Id: I874a9e23dfcdd1caa934945b46089f11b9f6de65
This commit is contained in:
parent
c0640f8710
commit
9f30c5d31e
@ -482,8 +482,11 @@ class Account(Base):
|
|||||||
fields = [['object_count', 'x-account-object-count'],
|
fields = [['object_count', 'x-account-object-count'],
|
||||||
['container_count', 'x-account-container-count'],
|
['container_count', 'x-account-container-count'],
|
||||||
['bytes_used', 'x-account-bytes-used']]
|
['bytes_used', 'x-account-bytes-used']]
|
||||||
|
optional_fields = [
|
||||||
|
['temp-url-key', 'x-account-meta-temp-url-key'],
|
||||||
|
['temp-url-key-2', 'x-account-meta-temp-url-key-2']]
|
||||||
|
|
||||||
return self.header_fields(fields)
|
return self.header_fields(fields, optional_fields=optional_fields)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path(self):
|
def path(self):
|
||||||
|
@ -38,6 +38,54 @@ def tearDownModule():
|
|||||||
|
|
||||||
|
|
||||||
class TestAccount(unittest2.TestCase):
|
class TestAccount(unittest2.TestCase):
|
||||||
|
existing_metadata = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_meta(cls):
|
||||||
|
def head(url, token, parsed, conn):
|
||||||
|
conn.request('HEAD', parsed.path, '', {'X-Auth-Token': token})
|
||||||
|
return check_response(conn)
|
||||||
|
resp = retry(head)
|
||||||
|
resp.read()
|
||||||
|
return dict((k, v) for k, v in resp.getheaders() if
|
||||||
|
k.lower().startswith('x-account-meta'))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def clear_meta(cls, remove_metadata_keys):
|
||||||
|
def post(url, token, parsed, conn, hdr_keys):
|
||||||
|
headers = {'X-Auth-Token': token}
|
||||||
|
headers.update((k, '') for k in hdr_keys)
|
||||||
|
conn.request('POST', parsed.path, '', headers)
|
||||||
|
return check_response(conn)
|
||||||
|
|
||||||
|
for i in range(0, len(remove_metadata_keys), 90):
|
||||||
|
batch = remove_metadata_keys[i:i + 90]
|
||||||
|
resp = retry(post, batch)
|
||||||
|
resp.read()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def set_meta(cls, metadata):
|
||||||
|
def post(url, token, parsed, conn, meta_hdrs):
|
||||||
|
headers = {'X-Auth-Token': token}
|
||||||
|
headers.update(meta_hdrs)
|
||||||
|
conn.request('POST', parsed.path, '', headers)
|
||||||
|
return check_response(conn)
|
||||||
|
|
||||||
|
if not metadata:
|
||||||
|
return
|
||||||
|
resp = retry(post, metadata)
|
||||||
|
resp.read()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
# remove and stash any existing account user metadata before tests
|
||||||
|
cls.existing_metadata = cls.get_meta()
|
||||||
|
cls.clear_meta(cls.existing_metadata.keys())
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
# replace any stashed account user metadata
|
||||||
|
cls.set_meta(cls.existing_metadata)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.max_meta_count = load_constraint('max_meta_count')
|
self.max_meta_count = load_constraint('max_meta_count')
|
||||||
@ -45,35 +93,10 @@ class TestAccount(unittest2.TestCase):
|
|||||||
self.max_meta_overall_size = load_constraint('max_meta_overall_size')
|
self.max_meta_overall_size = load_constraint('max_meta_overall_size')
|
||||||
self.max_meta_value_length = load_constraint('max_meta_value_length')
|
self.max_meta_value_length = load_constraint('max_meta_value_length')
|
||||||
|
|
||||||
def head(url, token, parsed, conn):
|
|
||||||
conn.request('HEAD', parsed.path, '', {'X-Auth-Token': token})
|
|
||||||
return check_response(conn)
|
|
||||||
resp = retry(head)
|
|
||||||
self.existing_metadata = set([
|
|
||||||
k for k, v in resp.getheaders() if
|
|
||||||
k.lower().startswith('x-account-meta')])
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
def head(url, token, parsed, conn):
|
# clean up any account user metadata created by test
|
||||||
conn.request('HEAD', parsed.path, '', {'X-Auth-Token': token})
|
new_metadata = self.get_meta().keys()
|
||||||
return check_response(conn)
|
self.clear_meta(new_metadata)
|
||||||
resp = retry(head)
|
|
||||||
resp.read()
|
|
||||||
new_metadata = set(
|
|
||||||
[k for k, v in resp.getheaders() if
|
|
||||||
k.lower().startswith('x-account-meta')])
|
|
||||||
|
|
||||||
def clear_meta(url, token, parsed, conn, remove_metadata_keys):
|
|
||||||
headers = {'X-Auth-Token': token}
|
|
||||||
headers.update((k, '') for k in remove_metadata_keys)
|
|
||||||
conn.request('POST', parsed.path, '', headers)
|
|
||||||
return check_response(conn)
|
|
||||||
extra_metadata = list(self.existing_metadata ^ new_metadata)
|
|
||||||
for i in range(0, len(extra_metadata), 90):
|
|
||||||
batch = extra_metadata[i:i + 90]
|
|
||||||
resp = retry(clear_meta, batch)
|
|
||||||
resp.read()
|
|
||||||
self.assertEqual(resp.status // 100, 2)
|
|
||||||
|
|
||||||
def test_metadata(self):
|
def test_metadata(self):
|
||||||
if tf.skip:
|
if tf.skip:
|
||||||
@ -794,11 +817,6 @@ class TestAccount(unittest2.TestCase):
|
|||||||
conn.request('POST', parsed.path, '', headers)
|
conn.request('POST', parsed.path, '', headers)
|
||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
|
|
||||||
# TODO: Find the test that adds these and remove them.
|
|
||||||
headers = {'x-remove-account-meta-temp-url-key': 'remove',
|
|
||||||
'x-remove-account-meta-temp-url-key-2': 'remove'}
|
|
||||||
resp = retry(post, headers)
|
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
for x in range(self.max_meta_count):
|
for x in range(self.max_meta_count):
|
||||||
headers['X-Account-Meta-%d' % x] = 'v'
|
headers['X-Account-Meta-%d' % x] = 'v'
|
||||||
|
@ -15,9 +15,8 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
from test.functional.tests import Utils, Base, Base2
|
from test.functional.tests import Utils, Base, Base2, BaseEnv
|
||||||
from test.functional.swift_test_client import Account, Connection, \
|
from test.functional.swift_test_client import Connection, ResponseError
|
||||||
ResponseError
|
|
||||||
|
|
||||||
|
|
||||||
def setUpModule():
|
def setUpModule():
|
||||||
@ -28,22 +27,16 @@ def tearDownModule():
|
|||||||
tf.teardown_package()
|
tf.teardown_package()
|
||||||
|
|
||||||
|
|
||||||
class TestDloEnv(object):
|
class TestDloEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestDloEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
|
|
||||||
config2 = tf.config.copy()
|
config2 = tf.config.copy()
|
||||||
config2['username'] = tf.config['username3']
|
config2['username'] = tf.config['username3']
|
||||||
config2['password'] = tf.config['password3']
|
config2['password'] = tf.config['password3']
|
||||||
cls.conn2 = Connection(config2)
|
cls.conn2 = Connection(config2)
|
||||||
cls.conn2.authenticate()
|
cls.conn2.authenticate()
|
||||||
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
cls.container2 = cls.account.container(Utils.create_name())
|
cls.container2 = cls.account.container(Utils.create_name())
|
||||||
|
|
||||||
@ -92,7 +85,6 @@ class TestDloEnv(object):
|
|||||||
|
|
||||||
class TestDlo(Base):
|
class TestDlo(Base):
|
||||||
env = TestDloEnv
|
env = TestDloEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def test_get_manifest(self):
|
def test_get_manifest(self):
|
||||||
file_item = self.env.container.file('man1')
|
file_item = self.env.container.file('man1')
|
||||||
@ -394,4 +386,4 @@ class TestDlo(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestDloUTF8(Base2, TestDlo):
|
class TestDloUTF8(Base2, TestDlo):
|
||||||
set_up = False
|
pass
|
||||||
|
@ -23,9 +23,8 @@ from unittest2 import SkipTest
|
|||||||
|
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
from test.functional import cluster_info
|
from test.functional import cluster_info
|
||||||
from test.functional.tests import Utils, Base, Base2
|
from test.functional.tests import Utils, Base, Base2, BaseEnv
|
||||||
from test.functional.swift_test_client import Account, Connection, \
|
from test.functional.swift_test_client import Connection, ResponseError
|
||||||
ResponseError
|
|
||||||
|
|
||||||
|
|
||||||
def setUpModule():
|
def setUpModule():
|
||||||
@ -36,7 +35,7 @@ def tearDownModule():
|
|||||||
tf.teardown_package()
|
tf.teardown_package()
|
||||||
|
|
||||||
|
|
||||||
class TestSloEnv(object):
|
class TestSloEnv(BaseEnv):
|
||||||
slo_enabled = None # tri-state: None initially, then True/False
|
slo_enabled = None # tri-state: None initially, then True/False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -58,8 +57,13 @@ class TestSloEnv(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
if cls.slo_enabled is None:
|
||||||
cls.conn.authenticate()
|
cls.slo_enabled = 'slo' in cluster_info
|
||||||
|
if not cls.slo_enabled:
|
||||||
|
return
|
||||||
|
|
||||||
|
super(TestSloEnv, cls).setUp()
|
||||||
|
|
||||||
config2 = deepcopy(tf.config)
|
config2 = deepcopy(tf.config)
|
||||||
config2['account'] = tf.config['account2']
|
config2['account'] = tf.config['account2']
|
||||||
config2['username'] = tf.config['username2']
|
config2['username'] = tf.config['username2']
|
||||||
@ -74,15 +78,6 @@ class TestSloEnv(object):
|
|||||||
cls.conn3 = Connection(config3)
|
cls.conn3 = Connection(config3)
|
||||||
cls.conn3.authenticate()
|
cls.conn3.authenticate()
|
||||||
|
|
||||||
if cls.slo_enabled is None:
|
|
||||||
cls.slo_enabled = 'slo' in cluster_info
|
|
||||||
if not cls.slo_enabled:
|
|
||||||
return
|
|
||||||
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
cls.container2 = cls.account.container(Utils.create_name())
|
cls.container2 = cls.account.container(Utils.create_name())
|
||||||
|
|
||||||
@ -214,7 +209,6 @@ class TestSloEnv(object):
|
|||||||
|
|
||||||
class TestSlo(Base):
|
class TestSlo(Base):
|
||||||
env = TestSloEnv
|
env = TestSloEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSlo, self).setUp()
|
super(TestSlo, self).setUp()
|
||||||
@ -963,4 +957,4 @@ class TestSlo(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestSloUTF8(Base2, TestSlo):
|
class TestSloUTF8(Base2, TestSlo):
|
||||||
set_up = False
|
pass
|
||||||
|
@ -24,7 +24,7 @@ from unittest2 import SkipTest
|
|||||||
|
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
from test.functional import cluster_info
|
from test.functional import cluster_info
|
||||||
from test.functional.tests import Utils, Base, Base2
|
from test.functional.tests import Utils, Base, Base2, BaseEnv
|
||||||
from test.functional import requires_acls
|
from test.functional import requires_acls
|
||||||
from test.functional.swift_test_client import Account, Connection, \
|
from test.functional.swift_test_client import Account, Connection, \
|
||||||
ResponseError
|
ResponseError
|
||||||
@ -38,25 +38,38 @@ def tearDownModule():
|
|||||||
tf.teardown_package()
|
tf.teardown_package()
|
||||||
|
|
||||||
|
|
||||||
class TestTempurlEnv(object):
|
class TestTempurlBaseEnv(BaseEnv):
|
||||||
|
original_account_meta = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUp(cls):
|
||||||
|
super(TestTempurlBaseEnv, cls).setUp()
|
||||||
|
cls.original_account_meta = cls.account.info()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDown(cls):
|
||||||
|
if cls.original_account_meta:
|
||||||
|
# restore any tempurl keys that the tests may have overwritten
|
||||||
|
cls.account.update_metadata(
|
||||||
|
dict((k, cls.original_account_meta.get(k, ''))
|
||||||
|
for k in ('temp-url-key', 'temp-url-key-2',)))
|
||||||
|
|
||||||
|
|
||||||
|
class TestTempurlEnv(TestTempurlBaseEnv):
|
||||||
tempurl_enabled = None # tri-state: None initially, then True/False
|
tempurl_enabled = None # tri-state: None initially, then True/False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
|
||||||
cls.conn.authenticate()
|
|
||||||
|
|
||||||
if cls.tempurl_enabled is None:
|
if cls.tempurl_enabled is None:
|
||||||
cls.tempurl_enabled = 'tempurl' in cluster_info
|
cls.tempurl_enabled = 'tempurl' in cluster_info
|
||||||
if not cls.tempurl_enabled:
|
if not cls.tempurl_enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
super(TestTempurlEnv, cls).setUp()
|
||||||
|
|
||||||
cls.tempurl_key = Utils.create_name()
|
cls.tempurl_key = Utils.create_name()
|
||||||
cls.tempurl_key2 = Utils.create_name()
|
cls.tempurl_key2 = Utils.create_name()
|
||||||
|
|
||||||
cls.account = Account(
|
|
||||||
cls.conn, tf.config.get('account', tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
cls.account.update_metadata({
|
cls.account.update_metadata({
|
||||||
'temp-url-key': cls.tempurl_key,
|
'temp-url-key': cls.tempurl_key,
|
||||||
'temp-url-key-2': cls.tempurl_key2
|
'temp-url-key-2': cls.tempurl_key2
|
||||||
@ -74,7 +87,6 @@ class TestTempurlEnv(object):
|
|||||||
|
|
||||||
class TestTempurl(Base):
|
class TestTempurl(Base):
|
||||||
env = TestTempurlEnv
|
env = TestTempurlEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestTempurl, self).setUp()
|
super(TestTempurl, self).setUp()
|
||||||
@ -376,29 +388,24 @@ class TestTempURLPrefix(TestTempurl):
|
|||||||
|
|
||||||
|
|
||||||
class TestTempurlUTF8(Base2, TestTempurl):
|
class TestTempurlUTF8(Base2, TestTempurl):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestContainerTempurlEnv(object):
|
class TestContainerTempurlEnv(BaseEnv):
|
||||||
tempurl_enabled = None # tri-state: None initially, then True/False
|
tempurl_enabled = None # tri-state: None initially, then True/False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
|
||||||
cls.conn.authenticate()
|
|
||||||
|
|
||||||
if cls.tempurl_enabled is None:
|
if cls.tempurl_enabled is None:
|
||||||
cls.tempurl_enabled = 'tempurl' in cluster_info
|
cls.tempurl_enabled = 'tempurl' in cluster_info
|
||||||
if not cls.tempurl_enabled:
|
if not cls.tempurl_enabled:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
super(TestContainerTempurlEnv, cls).setUp()
|
||||||
|
|
||||||
cls.tempurl_key = Utils.create_name()
|
cls.tempurl_key = Utils.create_name()
|
||||||
cls.tempurl_key2 = Utils.create_name()
|
cls.tempurl_key2 = Utils.create_name()
|
||||||
|
|
||||||
cls.account = Account(
|
|
||||||
cls.conn, tf.config.get('account', tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
# creating another account and connection
|
# creating another account and connection
|
||||||
# for ACL tests
|
# for ACL tests
|
||||||
config2 = deepcopy(tf.config)
|
config2 = deepcopy(tf.config)
|
||||||
@ -426,7 +433,6 @@ class TestContainerTempurlEnv(object):
|
|||||||
|
|
||||||
class TestContainerTempurl(Base):
|
class TestContainerTempurl(Base):
|
||||||
env = TestContainerTempurlEnv
|
env = TestContainerTempurlEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestContainerTempurl, self).setUp()
|
super(TestContainerTempurl, self).setUp()
|
||||||
@ -647,25 +653,20 @@ class TestContainerTempurl(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestContainerTempurlUTF8(Base2, TestContainerTempurl):
|
class TestContainerTempurlUTF8(Base2, TestContainerTempurl):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestSloTempurlEnv(object):
|
class TestSloTempurlEnv(TestTempurlBaseEnv):
|
||||||
enabled = None # tri-state: None initially, then True/False
|
enabled = None # tri-state: None initially, then True/False
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestSloTempurlEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
|
|
||||||
if cls.enabled is None:
|
if cls.enabled is None:
|
||||||
cls.enabled = 'tempurl' in cluster_info and 'slo' in cluster_info
|
cls.enabled = 'tempurl' in cluster_info and 'slo' in cluster_info
|
||||||
|
|
||||||
cls.tempurl_key = Utils.create_name()
|
cls.tempurl_key = Utils.create_name()
|
||||||
|
|
||||||
cls.account = Account(
|
|
||||||
cls.conn, tf.config.get('account', tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
cls.account.update_metadata({'temp-url-key': cls.tempurl_key})
|
cls.account.update_metadata({'temp-url-key': cls.tempurl_key})
|
||||||
|
|
||||||
cls.manifest_container = cls.account.container(Utils.create_name())
|
cls.manifest_container = cls.account.container(Utils.create_name())
|
||||||
@ -698,7 +699,6 @@ class TestSloTempurlEnv(object):
|
|||||||
|
|
||||||
class TestSloTempurl(Base):
|
class TestSloTempurl(Base):
|
||||||
env = TestSloTempurlEnv
|
env = TestSloTempurlEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSloTempurl, self).setUp()
|
super(TestSloTempurl, self).setUp()
|
||||||
@ -734,4 +734,4 @@ class TestSloTempurl(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestSloTempurlUTF8(Base2, TestSloTempurl):
|
class TestSloTempurlUTF8(Base2, TestSloTempurl):
|
||||||
set_up = False
|
pass
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import unittest2
|
||||||
from unittest2 import SkipTest
|
from unittest2 import SkipTest
|
||||||
|
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from test.functional.tests import Base, Base2, Utils
|
from test.functional.tests import Base, Base2, BaseEnv, Utils
|
||||||
from test.functional import cluster_info
|
from test.functional import cluster_info
|
||||||
from test.functional.swift_test_client import Account, Connection, \
|
from test.functional.swift_test_client import Account, Connection, \
|
||||||
ResponseError
|
ResponseError
|
||||||
@ -34,18 +35,14 @@ def tearDownModule():
|
|||||||
tf.teardown_package()
|
tf.teardown_package()
|
||||||
|
|
||||||
|
|
||||||
class TestObjectVersioningEnv(object):
|
class TestObjectVersioningEnv(BaseEnv):
|
||||||
versioning_enabled = None # tri-state: None initially, then True/False
|
versioning_enabled = None # tri-state: None initially, then True/False
|
||||||
location_header_key = 'X-Versions-Location'
|
location_header_key = 'X-Versions-Location'
|
||||||
|
account2 = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestObjectVersioningEnv, cls).setUp()
|
||||||
cls.storage_url, cls.storage_token = cls.conn.authenticate()
|
|
||||||
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
|
|
||||||
# Second connection for ACL tests
|
# Second connection for ACL tests
|
||||||
config2 = deepcopy(tf.config)
|
config2 = deepcopy(tf.config)
|
||||||
config2['account'] = tf.config['account2']
|
config2['account'] = tf.config['account2']
|
||||||
@ -96,22 +93,23 @@ class TestObjectVersioningEnv(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDown(cls):
|
def tearDown(cls):
|
||||||
cls.account.delete_containers()
|
if cls.account:
|
||||||
cls.account2.delete_containers()
|
cls.account.delete_containers()
|
||||||
|
if cls.account2:
|
||||||
|
cls.account2.delete_containers()
|
||||||
|
|
||||||
|
|
||||||
class TestCrossPolicyObjectVersioningEnv(object):
|
class TestCrossPolicyObjectVersioningEnv(BaseEnv):
|
||||||
# tri-state: None initially, then True/False
|
# tri-state: None initially, then True/False
|
||||||
versioning_enabled = None
|
versioning_enabled = None
|
||||||
multiple_policies_enabled = None
|
multiple_policies_enabled = None
|
||||||
policies = None
|
policies = None
|
||||||
location_header_key = 'X-Versions-Location'
|
location_header_key = 'X-Versions-Location'
|
||||||
|
account2 = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestCrossPolicyObjectVersioningEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
|
|
||||||
if cls.multiple_policies_enabled is None:
|
if cls.multiple_policies_enabled is None:
|
||||||
try:
|
try:
|
||||||
cls.policies = tf.FunctionalStoragePolicyCollection.from_info()
|
cls.policies = tf.FunctionalStoragePolicyCollection.from_info()
|
||||||
@ -131,9 +129,6 @@ class TestCrossPolicyObjectVersioningEnv(object):
|
|||||||
policy = cls.policies.select()
|
policy = cls.policies.select()
|
||||||
version_policy = cls.policies.exclude(name=policy['name']).select()
|
version_policy = cls.policies.exclude(name=policy['name']).select()
|
||||||
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
|
|
||||||
# Second connection for ACL tests
|
# Second connection for ACL tests
|
||||||
config2 = deepcopy(tf.config)
|
config2 = deepcopy(tf.config)
|
||||||
config2['account'] = tf.config['account2']
|
config2['account'] = tf.config['account2']
|
||||||
@ -185,8 +180,10 @@ class TestCrossPolicyObjectVersioningEnv(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDown(cls):
|
def tearDown(cls):
|
||||||
cls.account.delete_containers()
|
if cls.account:
|
||||||
cls.account2.delete_containers()
|
cls.account.delete_containers()
|
||||||
|
if cls.account2:
|
||||||
|
cls.account2.delete_containers()
|
||||||
|
|
||||||
|
|
||||||
class TestObjectVersioningHistoryModeEnv(TestObjectVersioningEnv):
|
class TestObjectVersioningHistoryModeEnv(TestObjectVersioningEnv):
|
||||||
@ -195,7 +192,6 @@ class TestObjectVersioningHistoryModeEnv(TestObjectVersioningEnv):
|
|||||||
|
|
||||||
class TestObjectVersioning(Base):
|
class TestObjectVersioning(Base):
|
||||||
env = TestObjectVersioningEnv
|
env = TestObjectVersioningEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestObjectVersioning, self).setUp()
|
super(TestObjectVersioning, self).setUp()
|
||||||
@ -487,7 +483,6 @@ class TestObjectVersioning(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestObjectVersioningUTF8(Base2, TestObjectVersioning):
|
class TestObjectVersioningUTF8(Base2, TestObjectVersioning):
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self._tear_down_files()
|
self._tear_down_files()
|
||||||
@ -496,7 +491,6 @@ class TestObjectVersioningUTF8(Base2, TestObjectVersioning):
|
|||||||
|
|
||||||
class TestCrossPolicyObjectVersioning(TestObjectVersioning):
|
class TestCrossPolicyObjectVersioning(TestObjectVersioning):
|
||||||
env = TestCrossPolicyObjectVersioningEnv
|
env = TestCrossPolicyObjectVersioningEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCrossPolicyObjectVersioning, self).setUp()
|
super(TestCrossPolicyObjectVersioning, self).setUp()
|
||||||
@ -511,7 +505,6 @@ class TestCrossPolicyObjectVersioning(TestObjectVersioning):
|
|||||||
|
|
||||||
class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
||||||
env = TestObjectVersioningHistoryModeEnv
|
env = TestObjectVersioningHistoryModeEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
# those override tests includes assertions for delete versioned objects
|
# those override tests includes assertions for delete versioned objects
|
||||||
# behaviors different from default object versioning using
|
# behaviors different from default object versioning using
|
||||||
@ -695,7 +688,7 @@ class TestObjectVersioningHistoryMode(TestObjectVersioning):
|
|||||||
self.assertEqual(expected, prev_version.read())
|
self.assertEqual(expected, prev_version.read())
|
||||||
|
|
||||||
|
|
||||||
class TestSloWithVersioning(Base):
|
class TestSloWithVersioning(unittest2.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
if 'slo' not in cluster_info:
|
if 'slo' not in cluster_info:
|
||||||
|
@ -67,12 +67,33 @@ class Utils(object):
|
|||||||
create_name = create_ascii_name
|
create_name = create_ascii_name
|
||||||
|
|
||||||
|
|
||||||
|
class BaseEnv(object):
|
||||||
|
account = conn = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUp(cls):
|
||||||
|
cls.conn = Connection(tf.config)
|
||||||
|
cls.conn.authenticate()
|
||||||
|
cls.account = Account(cls.conn, tf.config.get('account',
|
||||||
|
tf.config['username']))
|
||||||
|
cls.account.delete_containers()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDown(cls):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Base(unittest2.TestCase):
|
class Base(unittest2.TestCase):
|
||||||
def setUp(self):
|
# subclasses may override env class
|
||||||
cls = type(self)
|
env = BaseEnv
|
||||||
if not cls.set_up:
|
|
||||||
cls.env.setUp()
|
@classmethod
|
||||||
cls.set_up = True
|
def setUpClass(cls):
|
||||||
|
cls.env.setUp()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
cls.env.tearDown()
|
||||||
|
|
||||||
def assert_body(self, body):
|
def assert_body(self, body):
|
||||||
response_body = self.env.conn.response.read()
|
response_body = self.env.conn.response.read()
|
||||||
@ -105,15 +126,10 @@ class Base2(object):
|
|||||||
Utils.create_name = Utils.create_ascii_name
|
Utils.create_name = Utils.create_ascii_name
|
||||||
|
|
||||||
|
|
||||||
class TestAccountEnv(object):
|
class TestAccountEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestAccountEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.containers = []
|
cls.containers = []
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
cont = cls.account.container(Utils.create_name())
|
cont = cls.account.container(Utils.create_name())
|
||||||
@ -125,16 +141,14 @@ class TestAccountEnv(object):
|
|||||||
|
|
||||||
class TestAccountDev(Base):
|
class TestAccountDev(Base):
|
||||||
env = TestAccountEnv
|
env = TestAccountEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestAccountDevUTF8(Base2, TestAccountDev):
|
class TestAccountDevUTF8(Base2, TestAccountDev):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestAccount(Base):
|
class TestAccount(Base):
|
||||||
env = TestAccountEnv
|
env = TestAccountEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testNoAuthToken(self):
|
def testNoAuthToken(self):
|
||||||
self.assertRaises(ResponseError, self.env.account.info,
|
self.assertRaises(ResponseError, self.env.account.info,
|
||||||
@ -352,23 +366,10 @@ class TestAccount(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestAccountUTF8(Base2, TestAccount):
|
class TestAccountUTF8(Base2, TestAccount):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestAccountNoContainersEnv(object):
|
|
||||||
@classmethod
|
|
||||||
def setUp(cls):
|
|
||||||
cls.conn = Connection(tf.config)
|
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
|
|
||||||
class TestAccountNoContainers(Base):
|
class TestAccountNoContainers(Base):
|
||||||
env = TestAccountNoContainersEnv
|
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testGetRequest(self):
|
def testGetRequest(self):
|
||||||
for format_type in [None, 'json', 'xml']:
|
for format_type in [None, 'json', 'xml']:
|
||||||
self.assertFalse(self.env.account.containers(
|
self.assertFalse(self.env.account.containers(
|
||||||
@ -381,18 +382,13 @@ class TestAccountNoContainers(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestAccountNoContainersUTF8(Base2, TestAccountNoContainers):
|
class TestAccountNoContainersUTF8(Base2, TestAccountNoContainers):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestAccountSortingEnv(object):
|
class TestAccountSortingEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestAccountSortingEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
postfix = Utils.create_name()
|
postfix = Utils.create_name()
|
||||||
cls.cont_items = ('a1', 'a2', 'A3', 'b1', 'B2', 'a10', 'b10', 'zz')
|
cls.cont_items = ('a1', 'a2', 'A3', 'b1', 'B2', 'a10', 'b10', 'zz')
|
||||||
cls.cont_items = ['%s%s' % (x, postfix) for x in cls.cont_items]
|
cls.cont_items = ['%s%s' % (x, postfix) for x in cls.cont_items]
|
||||||
@ -405,7 +401,6 @@ class TestAccountSortingEnv(object):
|
|||||||
|
|
||||||
class TestAccountSorting(Base):
|
class TestAccountSorting(Base):
|
||||||
env = TestAccountSortingEnv
|
env = TestAccountSortingEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testAccountContainerListSorting(self):
|
def testAccountContainerListSorting(self):
|
||||||
# name (byte order) sorting.
|
# name (byte order) sorting.
|
||||||
@ -470,15 +465,10 @@ class TestAccountSorting(Base):
|
|||||||
self.assertEqual([], cont_listing)
|
self.assertEqual([], cont_listing)
|
||||||
|
|
||||||
|
|
||||||
class TestContainerEnv(object):
|
class TestContainerEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestContainerEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
if not cls.container.create():
|
if not cls.container.create():
|
||||||
raise ResponseError(cls.conn.response)
|
raise ResponseError(cls.conn.response)
|
||||||
@ -494,16 +484,14 @@ class TestContainerEnv(object):
|
|||||||
|
|
||||||
class TestContainerDev(Base):
|
class TestContainerDev(Base):
|
||||||
env = TestContainerEnv
|
env = TestContainerEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestContainerDevUTF8(Base2, TestContainerDev):
|
class TestContainerDevUTF8(Base2, TestContainerDev):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestContainer(Base):
|
class TestContainer(Base):
|
||||||
env = TestContainerEnv
|
env = TestContainerEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testContainerNameLimit(self):
|
def testContainerNameLimit(self):
|
||||||
limit = load_constraint('max_container_name_length')
|
limit = load_constraint('max_container_name_length')
|
||||||
@ -889,18 +877,13 @@ class TestContainer(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestContainerUTF8(Base2, TestContainer):
|
class TestContainerUTF8(Base2, TestContainer):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestContainerSortingEnv(object):
|
class TestContainerSortingEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestContainerSortingEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
if not cls.container.create():
|
if not cls.container.create():
|
||||||
raise ResponseError(cls.conn.response)
|
raise ResponseError(cls.conn.response)
|
||||||
@ -916,7 +899,6 @@ class TestContainerSortingEnv(object):
|
|||||||
|
|
||||||
class TestContainerSorting(Base):
|
class TestContainerSorting(Base):
|
||||||
env = TestContainerSortingEnv
|
env = TestContainerSortingEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testContainerFileListSortingReversed(self):
|
def testContainerFileListSortingReversed(self):
|
||||||
file_list = list(sorted(self.env.file_items))
|
file_list = list(sorted(self.env.file_items))
|
||||||
@ -1004,15 +986,10 @@ class TestContainerSorting(Base):
|
|||||||
self.assertEqual(file_list, cont_files)
|
self.assertEqual(file_list, cont_files)
|
||||||
|
|
||||||
|
|
||||||
class TestContainerPathsEnv(object):
|
class TestContainerPathsEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestContainerPathsEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.file_size = 8
|
cls.file_size = 8
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
@ -1082,7 +1059,6 @@ class TestContainerPathsEnv(object):
|
|||||||
|
|
||||||
class TestContainerPaths(Base):
|
class TestContainerPaths(Base):
|
||||||
env = TestContainerPathsEnv
|
env = TestContainerPathsEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testTraverseContainer(self):
|
def testTraverseContainer(self):
|
||||||
found_files = []
|
found_files = []
|
||||||
@ -1183,13 +1159,10 @@ class TestContainerPaths(Base):
|
|||||||
['dir1/subdir with spaces/file B'])
|
['dir1/subdir with spaces/file B'])
|
||||||
|
|
||||||
|
|
||||||
class TestFileEnv(object):
|
class TestFileEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestFileEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
# creating another account and connection
|
# creating another account and connection
|
||||||
# for account to account copy tests
|
# for account to account copy tests
|
||||||
config2 = deepcopy(tf.config)
|
config2 = deepcopy(tf.config)
|
||||||
@ -1199,9 +1172,6 @@ class TestFileEnv(object):
|
|||||||
cls.conn2 = Connection(config2)
|
cls.conn2 = Connection(config2)
|
||||||
cls.conn2.authenticate()
|
cls.conn2.authenticate()
|
||||||
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
cls.account2 = cls.conn2.get_account()
|
cls.account2 = cls.conn2.get_account()
|
||||||
cls.account2.delete_containers()
|
cls.account2.delete_containers()
|
||||||
|
|
||||||
@ -1223,16 +1193,14 @@ class TestFileEnv(object):
|
|||||||
|
|
||||||
class TestFileDev(Base):
|
class TestFileDev(Base):
|
||||||
env = TestFileEnv
|
env = TestFileEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileDevUTF8(Base2, TestFileDev):
|
class TestFileDevUTF8(Base2, TestFileDev):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestFile(Base):
|
class TestFile(Base):
|
||||||
env = TestFileEnv
|
env = TestFileEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testCopy(self):
|
def testCopy(self):
|
||||||
# makes sure to test encoded characters
|
# makes sure to test encoded characters
|
||||||
@ -2505,18 +2473,13 @@ class TestFile(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestFileUTF8(Base2, TestFile):
|
class TestFileUTF8(Base2, TestFile):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestFileComparisonEnv(object):
|
class TestFileComparisonEnv(BaseEnv):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUp(cls):
|
def setUp(cls):
|
||||||
cls.conn = Connection(tf.config)
|
super(TestFileComparisonEnv, cls).setUp()
|
||||||
cls.conn.authenticate()
|
|
||||||
cls.account = Account(cls.conn, tf.config.get('account',
|
|
||||||
tf.config['username']))
|
|
||||||
cls.account.delete_containers()
|
|
||||||
|
|
||||||
cls.container = cls.account.container(Utils.create_name())
|
cls.container = cls.account.container(Utils.create_name())
|
||||||
|
|
||||||
if not cls.container.create():
|
if not cls.container.create():
|
||||||
@ -2542,7 +2505,6 @@ class TestFileComparisonEnv(object):
|
|||||||
|
|
||||||
class TestFileComparison(Base):
|
class TestFileComparison(Base):
|
||||||
env = TestFileComparisonEnv
|
env = TestFileComparisonEnv
|
||||||
set_up = False
|
|
||||||
|
|
||||||
def testIfMatch(self):
|
def testIfMatch(self):
|
||||||
for file_item in self.env.files:
|
for file_item in self.env.files:
|
||||||
@ -2662,7 +2624,7 @@ class TestFileComparison(Base):
|
|||||||
|
|
||||||
|
|
||||||
class TestFileComparisonUTF8(Base2, TestFileComparison):
|
class TestFileComparisonUTF8(Base2, TestFileComparison):
|
||||||
set_up = False
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestServiceToken(unittest2.TestCase):
|
class TestServiceToken(unittest2.TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user