Merge "fix some format issure"
This commit is contained in:
commit
7f89e50eaf
@ -38,6 +38,7 @@ def chunks(s, length=3):
|
||||
yield s[i:j]
|
||||
i, j = j, j + length
|
||||
|
||||
|
||||
def timeout(seconds, method, *args, **kwargs):
|
||||
class TimeoutThread(threading.Thread):
|
||||
def __init__(self, method, *args, **kwargs):
|
||||
@ -66,6 +67,7 @@ def timeout(seconds, method, *args, **kwargs):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class Utils:
|
||||
@classmethod
|
||||
def create_ascii_name(cls, length=None):
|
||||
@ -83,11 +85,12 @@ class Utils:
|
||||
u'\u1802\u0901\uF111\uD20F\uB30D\u940B\u850A\u5607'\
|
||||
u'\u3705\u1803\u0902\uF112\uD210\uB30E\u940C\u850B'\
|
||||
u'\u5608\u3706\u1804\u0903\u03A9\u2603'
|
||||
return ''.join([random.choice(utf8_chars) for x in \
|
||||
xrange(length)]).encode('utf-8')
|
||||
return ''.join([random.choice(utf8_chars)
|
||||
for x in xrange(length)]).encode('utf-8')
|
||||
|
||||
create_name = create_ascii_name
|
||||
|
||||
|
||||
class Base(unittest.TestCase):
|
||||
def setUp(self):
|
||||
cls = type(self)
|
||||
@ -107,6 +110,7 @@ class Base(unittest.TestCase):
|
||||
'Status returned: %d Expected: %s' %
|
||||
(self.env.conn.response.status, status_or_statuses))
|
||||
|
||||
|
||||
class Base2(object):
|
||||
def setUp(self):
|
||||
Utils.create_name = Utils.create_utf8_name
|
||||
@ -115,6 +119,7 @@ class Base2(object):
|
||||
def tearDown(self):
|
||||
Utils.create_name = Utils.create_ascii_name
|
||||
|
||||
|
||||
class TestAccountEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -132,13 +137,16 @@ class TestAccountEnv:
|
||||
|
||||
cls.containers.append(cont)
|
||||
|
||||
|
||||
class TestAccountDev(Base):
|
||||
env = TestAccountEnv
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestAccountDevUTF8(Base2, TestAccountDev):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestAccount(Base):
|
||||
env = TestAccountEnv
|
||||
set_up = False
|
||||
@ -210,9 +218,7 @@ class TestAccount(Base):
|
||||
container_info[container.name] = info
|
||||
|
||||
for format in ['json', 'xml']:
|
||||
for a in self.env.account.containers(
|
||||
parms={'format':format}):
|
||||
|
||||
for a in self.env.account.containers(parms={'format': format}):
|
||||
self.assert_(a['count'] >= 0)
|
||||
self.assert_(a['bytes'] >= 0)
|
||||
|
||||
@ -270,7 +276,7 @@ class TestAccount(Base):
|
||||
|
||||
def testMarkerLimitContainerList(self):
|
||||
for format in [None, 'json', 'xml']:
|
||||
for marker in ['0', 'A', 'I', 'R', 'Z', 'a', 'i', 'r', 'z', \
|
||||
for marker in ['0', 'A', 'I', 'R', 'Z', 'a', 'i', 'r', 'z',
|
||||
'abc123', 'mnop', 'xyz']:
|
||||
|
||||
limit = random.randint(2, 9)
|
||||
@ -291,9 +297,11 @@ class TestAccount(Base):
|
||||
self.assertEquals(sorted(containers, cmp=locale.strcoll),
|
||||
containers)
|
||||
|
||||
|
||||
class TestAccountUTF8(Base2, TestAccount):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestAccountNoContainersEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -303,6 +311,7 @@ class TestAccountNoContainersEnv:
|
||||
config['username']))
|
||||
cls.account.delete_containers()
|
||||
|
||||
|
||||
class TestAccountNoContainers(Base):
|
||||
env = TestAccountNoContainersEnv
|
||||
set_up = False
|
||||
@ -317,9 +326,11 @@ class TestAccountNoContainers(Base):
|
||||
else:
|
||||
self.assert_status(200)
|
||||
|
||||
|
||||
class TestAccountNoContainersUTF8(Base2, TestAccountNoContainers):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestContainerEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -341,13 +352,16 @@ class TestContainerEnv:
|
||||
file.write_random(cls.file_size)
|
||||
cls.files.append(file.name)
|
||||
|
||||
|
||||
class TestContainerDev(Base):
|
||||
env = TestContainerEnv
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestContainerDevUTF8(Base2, TestContainerDev):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestContainer(Base):
|
||||
env = TestContainerEnv
|
||||
set_up = False
|
||||
@ -357,7 +371,6 @@ class TestContainer(Base):
|
||||
|
||||
for l in (limit - 100, limit - 10, limit - 1, limit,
|
||||
limit + 1, limit + 10, limit + 100):
|
||||
|
||||
cont = self.env.account.container('a' * l)
|
||||
if l <= limit:
|
||||
self.assert_(cont.create())
|
||||
@ -392,7 +405,8 @@ class TestContainer(Base):
|
||||
for i in xrange(len(files)):
|
||||
f = files[i]
|
||||
for j in xrange(1, len(files) - i):
|
||||
self.assert_(cont.files(parms={'limit':j, 'marker':f}) == files[i+1:i+j+1])
|
||||
self.assert_(cont.files(parms={'limit': j, 'marker': f}) ==
|
||||
files[i + 1: i + j + 1])
|
||||
self.assert_(cont.files(parms={'marker': f}) == files[i + 1:])
|
||||
self.assert_(cont.files(parms={'marker': f, 'prefix': f}) == [])
|
||||
self.assert_(cont.files(parms={'prefix': f}) == [f])
|
||||
@ -541,12 +555,12 @@ class TestContainer(Base):
|
||||
|
||||
def testMarkerLimitFileList(self):
|
||||
for format in [None, 'json', 'xml']:
|
||||
for marker in ['0', 'A', 'I', 'R', 'Z', 'a', 'i', 'r', 'z', \
|
||||
for marker in ['0', 'A', 'I', 'R', 'Z', 'a', 'i', 'r', 'z',
|
||||
'abc123', 'mnop', 'xyz']:
|
||||
|
||||
limit = random.randint(2, self.env.file_count - 1)
|
||||
files = self.env.container.files(parms={'format':format, \
|
||||
'marker':marker, 'limit':limit})
|
||||
files = self.env.container.files(parms={'format': format,
|
||||
'marker': marker,
|
||||
'limit': limit})
|
||||
|
||||
if not files:
|
||||
continue
|
||||
@ -587,8 +601,8 @@ class TestContainer(Base):
|
||||
|
||||
def testTooLongName(self):
|
||||
cont = self.env.account.container('x' * 257)
|
||||
self.assert_(not cont.create(), 'created container with name %s' % \
|
||||
(cont.name))
|
||||
self.assert_(not cont.create(),
|
||||
'created container with name %s' % (cont.name))
|
||||
self.assert_status(400)
|
||||
|
||||
def testContainerExistenceCachingProblem(self):
|
||||
@ -603,9 +617,11 @@ class TestContainer(Base):
|
||||
file = cont.file(Utils.create_name())
|
||||
file.write_random()
|
||||
|
||||
|
||||
class TestContainerUTF8(Base2, TestContainer):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestContainerPathsEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -668,9 +684,10 @@ class TestContainerPathsEnv:
|
||||
if f.endswith('/'):
|
||||
file.write(hdrs={'content-type': 'application/directory'})
|
||||
else:
|
||||
file.write_random(cls.file_size, hdrs={'content-type': \
|
||||
file.write_random(cls.file_size, hdrs={'content-type':
|
||||
'application/directory'})
|
||||
|
||||
|
||||
class TestContainerPaths(Base):
|
||||
env = TestContainerPathsEnv
|
||||
set_up = False
|
||||
@ -678,6 +695,7 @@ class TestContainerPaths(Base):
|
||||
def testTraverseContainer(self):
|
||||
found_files = []
|
||||
found_dirs = []
|
||||
|
||||
def recurse_path(path, count=0):
|
||||
if count > 10:
|
||||
raise ValueError('too deep recursion')
|
||||
@ -689,6 +707,7 @@ class TestContainerPaths(Base):
|
||||
found_dirs.append(file)
|
||||
else:
|
||||
found_files.append(file)
|
||||
|
||||
recurse_path('')
|
||||
for file in self.env.files:
|
||||
if file.startswith('/'):
|
||||
@ -726,7 +745,7 @@ class TestContainerPaths(Base):
|
||||
for format in ('json', 'xml'):
|
||||
for file in self.env.container.files(parms={'format': format}):
|
||||
self.assert_(int(file['bytes']) >= 0)
|
||||
self.assert_(file.has_key('last_modified'))
|
||||
self.assert_('last_modified' in file)
|
||||
if file['name'].endswith('/'):
|
||||
self.assertEquals(file['content_type'],
|
||||
'application/directory')
|
||||
@ -767,6 +786,7 @@ class TestContainerPaths(Base):
|
||||
assert_listing('dir1/subdir with spaces/',
|
||||
['dir1/subdir with spaces/file B'])
|
||||
|
||||
|
||||
class TestFileEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -782,13 +802,16 @@ class TestFileEnv:
|
||||
|
||||
cls.file_size = 128
|
||||
|
||||
|
||||
class TestFileDev(Base):
|
||||
env = TestFileEnv
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestFileDevUTF8(Base2, TestFileDev):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestFile(Base):
|
||||
env = TestFileEnv
|
||||
set_up = False
|
||||
@ -921,14 +944,16 @@ class TestFile(Base):
|
||||
# invalid source container
|
||||
file = self.env.container.file(Utils.create_name())
|
||||
self.assertRaises(ResponseError, file.write,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' % (prefix,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' %
|
||||
(prefix,
|
||||
Utils.create_name(), source_filename)})
|
||||
self.assert_status(404)
|
||||
|
||||
# invalid source object
|
||||
file = self.env.container.file(Utils.create_name())
|
||||
self.assertRaises(ResponseError, file.write,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' % (prefix,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' %
|
||||
(prefix,
|
||||
self.env.container.name, Utils.create_name())})
|
||||
self.assert_status(404)
|
||||
|
||||
@ -936,7 +961,8 @@ class TestFile(Base):
|
||||
dest_cont = self.env.account.container(Utils.create_name())
|
||||
file = dest_cont.file(Utils.create_name())
|
||||
self.assertRaises(ResponseError, file.write,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' % (prefix,
|
||||
hdrs={'X-Copy-From': '%s%s/%s' %
|
||||
(prefix,
|
||||
self.env.container.name, source_filename)})
|
||||
self.assert_status(404)
|
||||
|
||||
@ -976,9 +1002,8 @@ class TestFile(Base):
|
||||
|
||||
file.metadata = {Utils.create_name(): Utils.create_name()}
|
||||
|
||||
for method in (file.info, file.read, file.sync_metadata, \
|
||||
for method in (file.info, file.read, file.sync_metadata,
|
||||
file.delete):
|
||||
|
||||
self.assertRaises(ResponseError, method)
|
||||
self.assert_status(404)
|
||||
|
||||
@ -993,7 +1018,6 @@ class TestFile(Base):
|
||||
|
||||
for i in (number_limit - 10, number_limit - 1, number_limit,
|
||||
number_limit + 1, number_limit + 10, number_limit + 100):
|
||||
|
||||
size_limit = 4096
|
||||
|
||||
j = size_limit / (i * 2)
|
||||
@ -1099,8 +1123,8 @@ class TestFile(Base):
|
||||
limit = 5 * 2 ** 30 + 2
|
||||
tsecs = 3
|
||||
|
||||
for i in (limit-100, limit-10, limit-1, limit, limit+1, limit+10,
|
||||
limit+100):
|
||||
for i in (limit - 100, limit - 10, limit - 1, limit, limit + 1,
|
||||
limit + 10, limit + 100):
|
||||
|
||||
file = self.env.container.file(Utils.create_name())
|
||||
|
||||
@ -1135,25 +1159,28 @@ class TestFile(Base):
|
||||
|
||||
# content length x
|
||||
self.assertRaises(ResponseError, file.write_random, file_length,
|
||||
hdrs={'Content-Length':'X'}, cfg={'no_content_length':True})
|
||||
hdrs={'Content-Length': 'X'},
|
||||
cfg={'no_content_length': True})
|
||||
self.assert_status(400)
|
||||
|
||||
# bad request types
|
||||
#for req in ('LICK', 'GETorHEAD_base', 'container_info', 'best_response'):
|
||||
#for req in ('LICK', 'GETorHEAD_base', 'container_info',
|
||||
# 'best_response'):
|
||||
for req in ('LICK', 'GETorHEAD_base'):
|
||||
self.env.account.conn.make_request(req)
|
||||
self.assert_status(405)
|
||||
|
||||
# bad range headers
|
||||
self.assert_(len(file.read(hdrs={'Range':'parsecs=8-12'})) == \
|
||||
self.assert_(len(file.read(hdrs={'Range': 'parsecs=8-12'})) ==
|
||||
file_length)
|
||||
self.assert_status(200)
|
||||
|
||||
def testMetadataLengthLimits(self):
|
||||
key_limit, value_limit = 128, 256
|
||||
lengths = [[key_limit, value_limit], [key_limit, value_limit+1], \
|
||||
[key_limit+1, value_limit], [key_limit, 0], \
|
||||
[key_limit, value_limit*10], [key_limit*10, value_limit]]
|
||||
lengths = [[key_limit, value_limit], [key_limit, value_limit + 1],
|
||||
[key_limit + 1, value_limit], [key_limit, 0],
|
||||
[key_limit, value_limit * 10],
|
||||
[key_limit * 10, value_limit]]
|
||||
|
||||
for l in lengths:
|
||||
metadata = {'a' * l[0]: 'b' * l[1]}
|
||||
@ -1205,7 +1232,7 @@ class TestFile(Base):
|
||||
self.assertEquals(info['content_length'], self.env.file_size)
|
||||
self.assertEquals(info['etag'], md5)
|
||||
self.assertEquals(info['content_type'], content_type)
|
||||
self.assert_(info.has_key('last_modified'))
|
||||
self.assert_('last_modified' in info)
|
||||
|
||||
def testDeleteOfFileThatDoesNotExist(self):
|
||||
# in container that exists
|
||||
@ -1309,7 +1336,7 @@ class TestFile(Base):
|
||||
|
||||
files = []
|
||||
for i in (0, 1, 10, 100, 1000, 10000):
|
||||
files.append({'name': Utils.create_name(), \
|
||||
files.append({'name': Utils.create_name(),
|
||||
'content_type': Utils.create_name(), 'bytes': i})
|
||||
|
||||
write_time = time.time()
|
||||
@ -1334,11 +1361,11 @@ class TestFile(Base):
|
||||
f['content_type'])
|
||||
self.assertEquals(int(file['bytes']), f['bytes'])
|
||||
|
||||
d = datetime.strptime(file['last_modified'].\
|
||||
split('.')[0], "%Y-%m-%dT%H:%M:%S")
|
||||
d = datetime.strptime(file['last_modified'].split('.')[0],
|
||||
"%Y-%m-%dT%H:%M:%S")
|
||||
lm = time.mktime(d.timetuple())
|
||||
|
||||
if f.has_key('last_modified'):
|
||||
if 'last_modified' in f:
|
||||
self.assertEquals(f['last_modified'], lm)
|
||||
else:
|
||||
f['last_modified'] = lm
|
||||
@ -1346,7 +1373,7 @@ class TestFile(Base):
|
||||
f[format] = True
|
||||
found = True
|
||||
|
||||
self.assert_(found, 'Unexpected file %s found in ' \
|
||||
self.assert_(found, 'Unexpected file %s found in '
|
||||
'%s listing' % (file['name'], format))
|
||||
|
||||
headers = dict(self.env.conn.response.getheaders())
|
||||
@ -1359,12 +1386,12 @@ class TestFile(Base):
|
||||
|
||||
lm_diff = max([f['last_modified'] for f in files]) -\
|
||||
min([f['last_modified'] for f in files])
|
||||
self.assert_(lm_diff < write_time + 1, 'Diff in last ' + \
|
||||
self.assert_(lm_diff < write_time + 1, 'Diff in last '
|
||||
'modified times should be less than time to write files')
|
||||
|
||||
for f in files:
|
||||
for format in ['json', 'xml']:
|
||||
self.assert_(f[format], 'File %s not found in %s listing' \
|
||||
self.assert_(f[format], 'File %s not found in %s listing'
|
||||
% (f['name'], format))
|
||||
|
||||
def testStackedOverwrite(self):
|
||||
@ -1416,9 +1443,11 @@ class TestFile(Base):
|
||||
info = file.info()
|
||||
self.assertEquals(etag, info['etag'])
|
||||
|
||||
|
||||
class TestFileUTF8(Base2, TestFile):
|
||||
set_up = False
|
||||
|
||||
|
||||
class TestFileComparisonEnv:
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@ -1444,6 +1473,7 @@ class TestFileComparisonEnv:
|
||||
cls.time_old = time.asctime(time.localtime(time.time() - 86400))
|
||||
cls.time_new = time.asctime(time.localtime(time.time() + 86400))
|
||||
|
||||
|
||||
class TestFileComparison(Base):
|
||||
env = TestFileComparisonEnv
|
||||
set_up = False
|
||||
@ -1486,20 +1516,21 @@ class TestFileComparison(Base):
|
||||
|
||||
def testIfMatchAndUnmodified(self):
|
||||
for file in self.env.files:
|
||||
hdrs = {'If-Match': file.md5, 'If-Unmodified-Since': \
|
||||
self.env.time_new}
|
||||
hdrs = {'If-Match': file.md5,
|
||||
'If-Unmodified-Since': self.env.time_new}
|
||||
self.assert_(file.read(hdrs=hdrs))
|
||||
|
||||
hdrs = {'If-Match': 'bogus', 'If-Unmodified-Since': \
|
||||
self.env.time_new}
|
||||
hdrs = {'If-Match': 'bogus',
|
||||
'If-Unmodified-Since': self.env.time_new}
|
||||
self.assertRaises(ResponseError, file.read, hdrs=hdrs)
|
||||
self.assert_status(412)
|
||||
|
||||
hdrs = {'If-Match': file.md5, 'If-Unmodified-Since': \
|
||||
self.env.time_old}
|
||||
hdrs = {'If-Match': file.md5,
|
||||
'If-Unmodified-Since': self.env.time_old}
|
||||
self.assertRaises(ResponseError, file.read, hdrs=hdrs)
|
||||
self.assert_status(412)
|
||||
|
||||
|
||||
class TestFileComparisonUTF8(Base2, TestFileComparison):
|
||||
set_up = False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user