py3: Cover account/container func tests
Change-Id: I9a754f1eb06debbe16800a05fc8e969af2f89043
This commit is contained in:
parent
2a54619609
commit
7f42309a33
@ -20,8 +20,10 @@ import json
|
|||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from string import ascii_letters
|
from string import ascii_letters
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
from swift.common.middleware.acl import format_acl
|
from swift.common.middleware.acl import format_acl
|
||||||
|
from swift.common.utils import distribute_evenly
|
||||||
|
|
||||||
from test.functional import check_response, retry, requires_acls, \
|
from test.functional import check_response, retry, requires_acls, \
|
||||||
load_constraint, SkipTest
|
load_constraint, SkipTest
|
||||||
@ -57,8 +59,8 @@ class TestAccount(unittest2.TestCase):
|
|||||||
conn.request('POST', parsed.path, '', headers)
|
conn.request('POST', parsed.path, '', headers)
|
||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
|
|
||||||
for i in range(0, len(remove_metadata_keys), 90):
|
buckets = (len(remove_metadata_keys) - 1) // 90 + 1
|
||||||
batch = remove_metadata_keys[i:i + 90]
|
for batch in distribute_evenly(remove_metadata_keys, buckets):
|
||||||
resp = retry(post, batch)
|
resp = retry(post, batch)
|
||||||
resp.read()
|
resp.read()
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ class TestAccount(unittest2.TestCase):
|
|||||||
|
|
||||||
# needs to be an acceptable header size
|
# needs to be an acceptable header size
|
||||||
num_keys = 8
|
num_keys = 8
|
||||||
max_key_size = load_constraint('max_header_size') / num_keys
|
max_key_size = load_constraint('max_header_size') // num_keys
|
||||||
acl = {'admin': [c * max_key_size for c in ascii_letters[:num_keys]]}
|
acl = {'admin': [c * max_key_size for c in ascii_letters[:num_keys]]}
|
||||||
headers = {'x-account-access-control': format_acl(
|
headers = {'x-account-access-control': format_acl(
|
||||||
version=2, acl_dict=acl)}
|
version=2, acl_dict=acl)}
|
||||||
@ -717,7 +719,9 @@ class TestAccount(unittest2.TestCase):
|
|||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
uni_key = u'X-Account-Meta-uni\u0E12'
|
uni_key = u'X-Account-Meta-uni\u0E12'
|
||||||
uni_value = u'uni\u0E12'
|
uni_value = u'uni\u0E12'
|
||||||
if (tf.web_front_end == 'integral'):
|
# Note that py3 has issues with non-ascii header names; see
|
||||||
|
# https://bugs.python.org/issue37093
|
||||||
|
if (tf.web_front_end == 'integral' and six.PY2):
|
||||||
resp = retry(post, uni_key, '1')
|
resp = retry(post, uni_key, '1')
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertIn(resp.status, (201, 204))
|
self.assertIn(resp.status, (201, 204))
|
||||||
@ -731,9 +735,14 @@ class TestAccount(unittest2.TestCase):
|
|||||||
resp = retry(head)
|
resp = retry(head)
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertIn(resp.status, (200, 204))
|
self.assertIn(resp.status, (200, 204))
|
||||||
self.assertEqual(resp.getheader('X-Account-Meta-uni'),
|
if six.PY2:
|
||||||
uni_value.encode('utf-8'))
|
self.assertEqual(resp.getheader('X-Account-Meta-uni'),
|
||||||
if (tf.web_front_end == 'integral'):
|
uni_value.encode('utf8'))
|
||||||
|
else:
|
||||||
|
self.assertEqual(resp.getheader('X-Account-Meta-uni'),
|
||||||
|
uni_value)
|
||||||
|
# See above note about py3 and non-ascii header names
|
||||||
|
if (tf.web_front_end == 'integral' and six.PY2):
|
||||||
resp = retry(post, uni_key, uni_value)
|
resp = retry(post, uni_key, uni_value)
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertEqual(resp.status, 204)
|
self.assertEqual(resp.status, 204)
|
||||||
|
@ -23,6 +23,7 @@ from test.functional import check_response, cluster_info, retry, \
|
|||||||
requires_acls, load_constraint, requires_policies, SkipTest
|
requires_acls, load_constraint, requires_policies, SkipTest
|
||||||
import test.functional as tf
|
import test.functional as tf
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import range
|
from six.moves import range
|
||||||
|
|
||||||
|
|
||||||
@ -71,8 +72,11 @@ class TestContainer(unittest2.TestCase):
|
|||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
|
|
||||||
def delete(url, token, parsed, conn, container, obj):
|
def delete(url, token, parsed, conn, container, obj):
|
||||||
path = '/'.join([parsed.path, container,
|
if six.PY2:
|
||||||
obj['name'].encode('utf8')])
|
obj_name = obj['name'].encode('utf8')
|
||||||
|
else:
|
||||||
|
obj_name = obj['name']
|
||||||
|
path = '/'.join([parsed.path, container, obj_name])
|
||||||
conn.request('DELETE', path, '', {'X-Auth-Token': token})
|
conn.request('DELETE', path, '', {'X-Auth-Token': token})
|
||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
|
|
||||||
@ -153,7 +157,9 @@ class TestContainer(unittest2.TestCase):
|
|||||||
|
|
||||||
uni_key = u'X-Container-Meta-uni\u0E12'
|
uni_key = u'X-Container-Meta-uni\u0E12'
|
||||||
uni_value = u'uni\u0E12'
|
uni_value = u'uni\u0E12'
|
||||||
if (tf.web_front_end == 'integral'):
|
# Note that py3 has issues with non-ascii header names; see
|
||||||
|
# https://bugs.python.org/issue37093
|
||||||
|
if (tf.web_front_end == 'integral' and six.PY2):
|
||||||
resp = retry(post, uni_key, '1')
|
resp = retry(post, uni_key, '1')
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertEqual(resp.status, 204)
|
self.assertEqual(resp.status, 204)
|
||||||
@ -167,9 +173,14 @@ class TestContainer(unittest2.TestCase):
|
|||||||
resp = retry(head)
|
resp = retry(head)
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertIn(resp.status, (200, 204))
|
self.assertIn(resp.status, (200, 204))
|
||||||
self.assertEqual(resp.getheader('X-Container-Meta-uni'),
|
if six.PY2:
|
||||||
uni_value.encode('utf-8'))
|
self.assertEqual(resp.getheader('X-Container-Meta-uni'),
|
||||||
if (tf.web_front_end == 'integral'):
|
uni_value.encode('utf-8'))
|
||||||
|
else:
|
||||||
|
self.assertEqual(resp.getheader('X-Container-Meta-uni'),
|
||||||
|
uni_value)
|
||||||
|
# See above note about py3 and non-ascii header names
|
||||||
|
if (tf.web_front_end == 'integral' and six.PY2):
|
||||||
resp = retry(post, uni_key, uni_value)
|
resp = retry(post, uni_key, uni_value)
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertEqual(resp.status, 204)
|
self.assertEqual(resp.status, 204)
|
||||||
@ -763,6 +774,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
# read-only can list containers
|
# read-only can list containers
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(self.name, listing)
|
self.assertIn(self.name, listing)
|
||||||
|
|
||||||
@ -778,6 +791,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
self.assertEqual(resp.status, 201)
|
self.assertEqual(resp.status, 201)
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(new_container_name, listing)
|
self.assertIn(new_container_name, listing)
|
||||||
|
|
||||||
@ -878,6 +893,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
# can list containers
|
# can list containers
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(self.name, listing)
|
self.assertIn(self.name, listing)
|
||||||
|
|
||||||
@ -888,6 +905,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
self.assertIn(resp.status, (201, 202))
|
self.assertIn(resp.status, (201, 202))
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(new_container_name, listing)
|
self.assertIn(new_container_name, listing)
|
||||||
|
|
||||||
@ -897,6 +916,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
self.assertIn(resp.status, (204, 404))
|
self.assertIn(resp.status, (204, 404))
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertNotIn(new_container_name, listing)
|
self.assertNotIn(new_container_name, listing)
|
||||||
|
|
||||||
@ -1020,6 +1041,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
# can list containers
|
# can list containers
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(self.name, listing)
|
self.assertIn(self.name, listing)
|
||||||
|
|
||||||
@ -1030,6 +1053,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
self.assertEqual(resp.status, 201)
|
self.assertEqual(resp.status, 201)
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertIn(new_container_name, listing)
|
self.assertIn(new_container_name, listing)
|
||||||
|
|
||||||
@ -1039,6 +1064,8 @@ class TestContainer(unittest2.TestCase):
|
|||||||
self.assertEqual(resp.status, 204)
|
self.assertEqual(resp.status, 204)
|
||||||
resp = retry(get, use_account=3)
|
resp = retry(get, use_account=3)
|
||||||
listing = resp.read()
|
listing = resp.read()
|
||||||
|
if not six.PY2:
|
||||||
|
listing = listing.decode('utf8')
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertNotIn(new_container_name, listing)
|
self.assertNotIn(new_container_name, listing)
|
||||||
|
|
||||||
@ -1408,7 +1435,7 @@ class TestContainer(unittest2.TestCase):
|
|||||||
if (tf.web_front_end == 'apache2'):
|
if (tf.web_front_end == 'apache2'):
|
||||||
self.assertEqual(resp.status, 404)
|
self.assertEqual(resp.status, 404)
|
||||||
else:
|
else:
|
||||||
self.assertEqual(resp.read(), 'Invalid UTF8 or contains NULL')
|
self.assertEqual(resp.read(), b'Invalid UTF8 or contains NULL')
|
||||||
self.assertEqual(resp.status, 412)
|
self.assertEqual(resp.status, 412)
|
||||||
|
|
||||||
def test_create_container_gets_default_policy_by_default(self):
|
def test_create_container_gets_default_policy_by_default(self):
|
||||||
@ -1604,12 +1631,12 @@ class TestContainer(unittest2.TestCase):
|
|||||||
return check_response(conn)
|
return check_response(conn)
|
||||||
|
|
||||||
# upload 11 bytes object
|
# upload 11 bytes object
|
||||||
resp = retry(put, '01234567890')
|
resp = retry(put, b'01234567890')
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertEqual(resp.status, 413)
|
self.assertEqual(resp.status, 413)
|
||||||
|
|
||||||
# upload 10 bytes object
|
# upload 10 bytes object
|
||||||
resp = retry(put, '0123456789')
|
resp = retry(put, b'0123456789')
|
||||||
resp.read()
|
resp.read()
|
||||||
self.assertEqual(resp.status, 201)
|
self.assertEqual(resp.status, 201)
|
||||||
|
|
||||||
@ -1622,7 +1649,7 @@ class TestContainer(unittest2.TestCase):
|
|||||||
resp = retry(get)
|
resp = retry(get)
|
||||||
body = resp.read()
|
body = resp.read()
|
||||||
self.assertEqual(resp.status, 200)
|
self.assertEqual(resp.status, 200)
|
||||||
self.assertEqual(body, '0123456789')
|
self.assertEqual(body, b'0123456789')
|
||||||
|
|
||||||
|
|
||||||
class BaseTestContainerACLs(unittest2.TestCase):
|
class BaseTestContainerACLs(unittest2.TestCase):
|
||||||
|
2
tox.ini
2
tox.ini
@ -55,6 +55,8 @@ commands =
|
|||||||
test/functional/s3api/test_presigned.py \
|
test/functional/s3api/test_presigned.py \
|
||||||
test/functional/s3api/test_service.py \
|
test/functional/s3api/test_service.py \
|
||||||
test/functional/test_access_control.py \
|
test/functional/test_access_control.py \
|
||||||
|
test/functional/test_account.py \
|
||||||
|
test/functional/test_container.py \
|
||||||
test/functional/test_dlo.py \
|
test/functional/test_dlo.py \
|
||||||
test/functional/test_domain_remap.py \
|
test/functional/test_domain_remap.py \
|
||||||
test/functional/test_object.py \
|
test/functional/test_object.py \
|
||||||
|
Loading…
Reference in New Issue
Block a user