Пример #1
0
#test copy_key
b.copy_key('key_2', 'test_bucket_0', 'key_1')
k2 = b.lookup('key_2')
test_util.assert_neq(k2, None, 'test copy_key')

#test list
ks = b.list()
ret = True
i = 0
for k in ks:
    ret = k.name == 'key_%d' % i
    if ret != True:
        break
    i = i + 1

test_util.assert_true(ret, 'test list')

#test list with prefix
b.copy_key('aa/bb/cc/sub_key_0', 'test_bucket_0', 'key_1')
b.copy_key('aa/bb/cc/sub_key_1', 'test_bucket_0', 'key_1')
b.copy_key('aa/bb/dd/sub_key_3', 'test_bucket_0', 'key_1')

i = 0
ks = b.list(prefix='aa/bb/cc')
for k in ks:
    ret = k.name == 'aa/bb/cc/sub_key_%d' % i
    if ret != True:
        break
    i = i + 1

test_util.assert_true(ret, 'test list with prefix aa/bb/cc')
Пример #2
0
cont =  k.get_contents_as_string()
test_util.assert_eq( cont, '2'*1024,  'test set_contents_from_filename')
os.remove("file_w2")

#test copy
b2 = conn.create_bucket('test_bucket_2')
k2 = k.copy('test_bucket_2', 'key_2')
cont =  k2.get_contents_as_string()
test_util.assert_eq( cont, '2'*1024,  'test copy')

#test exists
res1 = k.exists()
k.delete()
res2 = k.exists()
if res1 == True and res2 == False:
    test_util.assert_true( True, 'test exists')

#test get_contents_to_file
with open('file_r1', 'w+') as fp:
    k2.get_contents_to_file(fp)

cont = read_file('file_r1')
test_util.assert_eq( cont, '2'*1024,  'test get_contents_to_file')
os.remove('file_r1')

k2.get_contents_to_filename('file_r2')
cont = read_file('file_r2')
test_util.assert_eq( cont, '2'*1024,  'test get_contents_to_filename')
os.remove('file_r2')

#test generate_url
Пример #3
0
#test copy_key
b.copy_key('key_2', 'test_bucket_0', 'key_1')
k2 = b.lookup('key_2')
test_util.assert_neq( k2, None, 'test copy_key' )

#test list
ks =  b.list()
ret = True
i = 0
for k in ks:
    ret = k.name == 'key_%d'%i
    if ret != True:
        break
    i = i + 1

test_util.assert_true( ret, 'test list')

#test list with prefix
b.copy_key('aa/bb/cc/sub_key_0', 'test_bucket_0', 'key_1')
b.copy_key('aa/bb/cc/sub_key_1', 'test_bucket_0', 'key_1')
b.copy_key('aa/bb/dd/sub_key_3', 'test_bucket_0', 'key_1')

i = 0
ks =  b.list(prefix = 'aa/bb/cc')
for k in ks:
    ret = k.name == 'aa/bb/cc/sub_key_%d'%i
    if ret != True:
        break
    i = i + 1

test_util.assert_true( ret, 'test list with prefix aa/bb/cc')
Пример #4
0
test_util.assert_eq( i, 3, 'test get_all_buckets' )

#test get_bucket
b1 = conn.get_bucket('test_bucket_1')
test_util.assert_eq( b1.name, 'test_bucket_1', 'test get_bucket' )

#test delete_bucket
conn.delete_bucket(b1)
b1 = conn.lookup('test_bucket_1')
test_util.assert_eq( None, b1, 'test delete_bucket' )

#test head_bucket
try:
    conn.head_bucket('test_bucket_1')
except Exception as e:
    test_util.assert_true(True, 'test head_bucket')

#test get_bucket validate
b2 = conn.get_bucket('test_bucket_2', validate=False)
try:
    conn.delete_bucket(b2)
except Exception as e:
    test_util.assert_true(False, 'test get_bucket validate')
else:
    test_util.assert_true(True, 'test get_bucket validate')

#test bucket in
res =  'test_bucket_2' in conn
test_util.assert_false(res, 'test bucket in')

test_util.clean_bucket(conn, 'test_bucket_0')
Пример #5
0
test_util.assert_eq(i, 3, 'test get_all_buckets')

#test get_bucket
b1 = conn.get_bucket('test_bucket_1')
test_util.assert_eq(b1.name, 'test_bucket_1', 'test get_bucket')

#test delete_bucket
conn.delete_bucket(b1)
b1 = conn.lookup('test_bucket_1')
test_util.assert_eq(None, b1, 'test delete_bucket')

#test head_bucket
try:
    conn.head_bucket('test_bucket_1')
except Exception as e:
    test_util.assert_true(True, 'test head_bucket')

#test get_bucket validate
b2 = conn.get_bucket('test_bucket_2', validate=False)
try:
    conn.delete_bucket(b2)
except Exception as e:
    test_util.assert_true(False, 'test get_bucket validate')
else:
    test_util.assert_true(True, 'test get_bucket validate')

#test bucket in
res = 'test_bucket_2' in conn
test_util.assert_false(res, 'test bucket in')

test_util.clean_bucket(conn, 'test_bucket_0')