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 string import ascii_letters
|
||||
|
||||
import six
|
||||
from six.moves import range
|
||||
from swift.common.middleware.acl import format_acl
|
||||
from swift.common.utils import distribute_evenly
|
||||
|
||||
from test.functional import check_response, retry, requires_acls, \
|
||||
load_constraint, SkipTest
|
||||
@ -57,8 +59,8 @@ class TestAccount(unittest2.TestCase):
|
||||
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]
|
||||
buckets = (len(remove_metadata_keys) - 1) // 90 + 1
|
||||
for batch in distribute_evenly(remove_metadata_keys, buckets):
|
||||
resp = retry(post, batch)
|
||||
resp.read()
|
||||
|
||||
@ -148,7 +150,7 @@ class TestAccount(unittest2.TestCase):
|
||||
|
||||
# needs to be an acceptable header size
|
||||
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]]}
|
||||
headers = {'x-account-access-control': format_acl(
|
||||
version=2, acl_dict=acl)}
|
||||
@ -717,7 +719,9 @@ class TestAccount(unittest2.TestCase):
|
||||
return check_response(conn)
|
||||
uni_key = u'X-Account-Meta-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.read()
|
||||
self.assertIn(resp.status, (201, 204))
|
||||
@ -731,9 +735,14 @@ class TestAccount(unittest2.TestCase):
|
||||
resp = retry(head)
|
||||
resp.read()
|
||||
self.assertIn(resp.status, (200, 204))
|
||||
if six.PY2:
|
||||
self.assertEqual(resp.getheader('X-Account-Meta-uni'),
|
||||
uni_value.encode('utf-8'))
|
||||
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.read()
|
||||
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
|
||||
import test.functional as tf
|
||||
|
||||
import six
|
||||
from six.moves import range
|
||||
|
||||
|
||||
@ -71,8 +72,11 @@ class TestContainer(unittest2.TestCase):
|
||||
return check_response(conn)
|
||||
|
||||
def delete(url, token, parsed, conn, container, obj):
|
||||
path = '/'.join([parsed.path, container,
|
||||
obj['name'].encode('utf8')])
|
||||
if six.PY2:
|
||||
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})
|
||||
return check_response(conn)
|
||||
|
||||
@ -153,7 +157,9 @@ class TestContainer(unittest2.TestCase):
|
||||
|
||||
uni_key = u'X-Container-Meta-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.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
@ -167,9 +173,14 @@ class TestContainer(unittest2.TestCase):
|
||||
resp = retry(head)
|
||||
resp.read()
|
||||
self.assertIn(resp.status, (200, 204))
|
||||
if six.PY2:
|
||||
self.assertEqual(resp.getheader('X-Container-Meta-uni'),
|
||||
uni_value.encode('utf-8'))
|
||||
if (tf.web_front_end == 'integral'):
|
||||
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.read()
|
||||
self.assertEqual(resp.status, 204)
|
||||
@ -763,6 +774,8 @@ class TestContainer(unittest2.TestCase):
|
||||
# read-only can list containers
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(self.name, listing)
|
||||
|
||||
@ -778,6 +791,8 @@ class TestContainer(unittest2.TestCase):
|
||||
self.assertEqual(resp.status, 201)
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(new_container_name, listing)
|
||||
|
||||
@ -878,6 +893,8 @@ class TestContainer(unittest2.TestCase):
|
||||
# can list containers
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(self.name, listing)
|
||||
|
||||
@ -888,6 +905,8 @@ class TestContainer(unittest2.TestCase):
|
||||
self.assertIn(resp.status, (201, 202))
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(new_container_name, listing)
|
||||
|
||||
@ -897,6 +916,8 @@ class TestContainer(unittest2.TestCase):
|
||||
self.assertIn(resp.status, (204, 404))
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertNotIn(new_container_name, listing)
|
||||
|
||||
@ -1020,6 +1041,8 @@ class TestContainer(unittest2.TestCase):
|
||||
# can list containers
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(self.name, listing)
|
||||
|
||||
@ -1030,6 +1053,8 @@ class TestContainer(unittest2.TestCase):
|
||||
self.assertEqual(resp.status, 201)
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertIn(new_container_name, listing)
|
||||
|
||||
@ -1039,6 +1064,8 @@ class TestContainer(unittest2.TestCase):
|
||||
self.assertEqual(resp.status, 204)
|
||||
resp = retry(get, use_account=3)
|
||||
listing = resp.read()
|
||||
if not six.PY2:
|
||||
listing = listing.decode('utf8')
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertNotIn(new_container_name, listing)
|
||||
|
||||
@ -1408,7 +1435,7 @@ class TestContainer(unittest2.TestCase):
|
||||
if (tf.web_front_end == 'apache2'):
|
||||
self.assertEqual(resp.status, 404)
|
||||
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)
|
||||
|
||||
def test_create_container_gets_default_policy_by_default(self):
|
||||
@ -1604,12 +1631,12 @@ class TestContainer(unittest2.TestCase):
|
||||
return check_response(conn)
|
||||
|
||||
# upload 11 bytes object
|
||||
resp = retry(put, '01234567890')
|
||||
resp = retry(put, b'01234567890')
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 413)
|
||||
|
||||
# upload 10 bytes object
|
||||
resp = retry(put, '0123456789')
|
||||
resp = retry(put, b'0123456789')
|
||||
resp.read()
|
||||
self.assertEqual(resp.status, 201)
|
||||
|
||||
@ -1622,7 +1649,7 @@ class TestContainer(unittest2.TestCase):
|
||||
resp = retry(get)
|
||||
body = resp.read()
|
||||
self.assertEqual(resp.status, 200)
|
||||
self.assertEqual(body, '0123456789')
|
||||
self.assertEqual(body, b'0123456789')
|
||||
|
||||
|
||||
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_service.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_domain_remap.py \
|
||||
test/functional/test_object.py \
|
||||
|
Loading…
Reference in New Issue
Block a user