#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')
k.update_metadata( {'name': 'chuang'} ) k.set_contents_from_string('key0 cont2') val = k.get_metadata('name') test_util.assert_eq( val, 'chuang', 'test update_metadata' ) #test read k.open() cont = k.read() k.close() test_util.assert_eq( cont, 'key0 cont2', 'test read') #test delete k.delete() res = k.exists() test_util.assert_false( res, 'test delete') #test set_contents_from_file k = Key(b, 'key_1') create_file('file_w1', '1'*1024) with open('file_w1', 'r') as fp: k.set_contents_from_file(fp, rewind=True) cont = k.get_contents_as_string() test_util.assert_eq( '1'*1024, cont, 'test set_contents_from_file') #test md5 md5 = hashlib.md5('1'*1024).hexdigest() test_util.assert_eq( md5, k.md5, 'test k.md5') os.remove("file_w1")
#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')