with open(fn, 'w+') as fp: fp.write(cont) def read_file(fn): with open(fn, 'r') as fp: return fp.read() conn = test_util.get_conn() b = conn.create_bucket('test_bucket_0') #test set_contents_from_string k = Key(b, 'key_0') k.set_contents_from_string('key0 cont0') cont = k.get_contents_as_string() test_util.assert_eq( cont, 'key0 cont0', 'test set_metadata') k.set_contents_from_string('key0 cont1') cont = k.get_contents_as_string() test_util.assert_eq( cont, 'key0 cont1', 'test set_metadata replace') #test set_metadata k.set_metadata('name', 'chen') k.set_contents_from_string('key0 cont1') val = k.get_metadata('name') test_util.assert_eq( val, 'chen', 'test set_metadata' ) #test update_metadata k.update_metadata( {'name': 'chuang'} ) k.set_contents_from_string('key0 cont2')
conn = test_util.get_conn() b = conn.create_bucket('test_bucket_0') #test new_key k0 = b.new_key('key_0') k0.set_contents_from_string('hello key0') k1 = b.new_key('key_1') k1.set_contents_from_string('hello key1') #test get_all_keys keys = b.get_all_keys() i = 0 for k in keys: test_util.assert_eq(k.name, 'key_' + str(i), 'test new_key ' + str(i)) i = i + 1 test_util.assert_eq(i, 2, 'test get_all_keys') #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
import test_util conn = test_util.get_conn() #test create_bucket conn.create_bucket('test_bucket_0') conn.create_bucket('test_bucket_1') conn.create_bucket('test_bucket_2') #test get_all_buckets bs = conn.get_all_buckets() i = 0 for b in bs: if b.name.startswith('test_bucket_'): test_util.assert_eq( b.name, 'test_bucket_'+str(i), 'test create_bucket '+str(i) ) i = i+1 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 = test_util.get_conn() b = conn.create_bucket('test_bucket_0') #test new_key k0 = b.new_key('key_0') k0.set_contents_from_string('hello key0') k1 = b.new_key('key_1') k1.set_contents_from_string('hello key1') #test get_all_keys keys = b.get_all_keys() i = 0 for k in keys: test_util.assert_eq( k.name, 'key_'+str(i), 'test new_key '+str(i) ) i = i + 1 test_util.assert_eq( i, 2, 'test get_all_keys' ) #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
mp = b.initiate_multipart_upload('multipart_key') md5 = hashlib.md5() for i in xrange(0, 4): buf = str(i) * 5 * 1024 * 1024 fp = open(fpath + str(i), 'w+') fp.write(buf) fp.seek(0, 0) fps.append(fp) md5.update(buf) for i in xrange(0, 4): mp.upload_part_from_file(fps[i], part_num=i + 1) mp.complete_upload() for i in xrange(0, 4): os.remove(fpath + str(i)) sum = md5.hexdigest() k = b.get_key('multipart_key') buf = k.get_contents_as_string() test_util.assert_eq(sum, hashlib.md5(buf).hexdigest(), 'test multipart') test_util.clean_bucket(conn, 'test_multipart_bucket')
md5 = hashlib.md5() for i in xrange(0, 4): buf = str(i)*5*1024*1024 fp = open(fpath + str(i), 'w+' ) fp.write(buf) fp.seek(0, 0) fps.append(fp) md5.update(buf) for i in xrange(0, 4): mp.upload_part_from_file(fps[i], part_num=i + 1) mp.complete_upload() for i in xrange(0, 4): os.remove(fpath + str(i)) sum = md5.hexdigest() k = b.get_key('multipart_key') buf = k.get_contents_as_string() test_util.assert_eq( sum, hashlib.md5(buf).hexdigest(), 'test multipart') test_util.clean_bucket(conn, 'test_multipart_bucket')
import test_util conn = test_util.get_conn() #test create_bucket conn.create_bucket('test_bucket_0') conn.create_bucket('test_bucket_1') conn.create_bucket('test_bucket_2') #test get_all_buckets bs = conn.get_all_buckets() i = 0 for b in bs: if b.name.startswith('test_bucket_'): test_util.assert_eq(b.name, 'test_bucket_' + str(i), 'test create_bucket ' + str(i)) i = i + 1 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: