Skip to content

Commit a9d7015

Browse files
committed
add put/get bucket intelligenttiering
1 parent 09c224d commit a9d7015

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

qcloud_cos/cos_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2847,6 +2847,7 @@ def get_bucket_referer(self, Bucket, **kwargs):
28472847

28482848
def delete_bucket_referer(self, Bucket, **kwargs):
28492849
"""删除bucket防盗链规则
2850+
28502851
:param Bucket(string): 存储桶名称.
28512852
:param kwargs(dict): 设置请求headers.
28522853
:return(dict): None.

ut/test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,35 @@ def test_aes_client():
13561356
if os.path.exists('test_multi_upload_local'):
13571357
os.remove('test_multi_upload_local')
13581358

1359+
client_for_rsa.delete_object(test_bucket, 'test_multi_upload')
1360+
1361+
def test_rsa_client():
1362+
"""测试rsa加密客户端的上传下载操作"""
1363+
content = '123456' * 1024 + '1'
1364+
client_for_rsa.delete_object(test_bucket, 'test_for_rsa')
1365+
client_for_rsa.put_object(test_bucket, content, 'test_for_rsa')
1366+
# 测试整个文件的md5
1367+
response = client_for_rsa.get_object(test_bucket, 'test_for_rsa')
1368+
response['Body'].get_stream_to_file('test_for_rsa_local')
1369+
local_file_md5 = None
1370+
content_md5 = None
1371+
with open('test_for_rsa_local', 'rb') as f:
1372+
local_file_md5 = get_raw_md5(f.read())
1373+
content_md5 = get_raw_md5(content.encode("utf-8"))
1374+
assert local_file_md5 and content_md5 and local_file_md5 == content_md5
1375+
if os.path.exists('test_for_rsa_local'):
1376+
os.remove('test_for_rsa_local')
1377+
1378+
# 测试读取部分数据的md5
1379+
response = client_for_rsa.get_object(test_bucket, 'test_for_rsa', Range='bytes=5-3000')
1380+
response['Body'].get_stream_to_file('test_for_rsa_local')
1381+
with open('test_for_rsa_local', 'rb') as f:
1382+
local_file_md5 = get_raw_md5(f.read())
1383+
content_md5 = get_raw_md5(content[5:3001].encode("utf-8"))
1384+
assert local_file_md5 and content_md5 and local_file_md5 == content_md5
1385+
if os.path.exists('test_for_rsa_local'):
1386+
os.remove('test_for_rsa_local')
1387+
13591388
client_for_rsa.delete_object(test_bucket, 'test_for_rsa')
13601389

13611390
content = '1' * 1024 * 1024
@@ -1375,6 +1404,7 @@ def test_aes_client():
13751404
assert local_file_md5 and content_md5 and local_file_md5 == content_md5
13761405
if os.path.exists('test_multi_upload_local'):
13771406
os.remove('test_multi_upload_local')
1407+
13781408
client_for_rsa.delete_object(test_bucket, 'test_multi_upload')
13791409

13801410

0 commit comments

Comments
 (0)