def test_part_iterator(self): for key in [random_string(16), '中文+_)(*&^%$#@!前缀', u'中文+_)(*&^%$#@!前缀']: upload_id = self.bucket.init_multipart_upload(key).upload_id # 准备分片 part_list = [] for part_number in [1, 3, 6, 7, 9, 10]: content = random_string(128 * 1024) etag = hashlib.md5(oss2.to_bytes(content)).hexdigest().upper() part_list.append(oss2.models.PartInfo(part_number, etag, len(content))) self.bucket.upload_part(key, upload_id, part_number, content) # 验证 parts_got = [] for part_info in oss2.PartIterator(self.bucket, key, upload_id): parts_got.append(part_info) self.assertEqual(len(part_list), len(parts_got)) for i in range(len(part_list)): self.assertEqual(part_list[i].part_number, parts_got[i].part_number) self.assertEqual(part_list[i].etag, parts_got[i].etag) self.assertEqual(part_list[i].size, parts_got[i].size) self.bucket.abort_multipart_upload(key, upload_id)
def test_part_iterator(self): key = 'requestpayment-test-object-upload-iterator' upload_id = self.bucket.init_multipart_upload(key).upload_id # PartIterator without payer setting, should be failed. access_err_flag = False try: up_iter = oss2.PartIterator(self.payer_bucket, key, upload_id) for up in up_iter: pass except oss2.exceptions.AccessDenied: access_err_flag = True self.assertEqual(access_err_flag, True) # PartIterator with payer setting, should be successful. headers = dict() headers[OSS_REQUEST_PAYER] = "requester" up_iter = oss2.PartIterator(self.payer_bucket, key, upload_id, headers=headers) for up in up_iter: pass