1 回答
TA贡献1829条经验 获得超7个赞
get_fileobj 转换为“head_object”和“get_object”调用。这是一个对两个调用进行存根的基本代码片段。
bucket_name = 'mybucket'
key = 'mykey'
content = 'This is the content'
expected_params = {
'Bucket': bucket_name,
'Key': key,
}
# Head object
response = {
'ContentLength': 10,
'ContentType': 'utf-8',
'ResponseMetadata': {
'Bucket': bucket_name,
}
}
s3_stub.add_response('head_object', response, expected_params)
# Get object
data = BytesIO()
data.write(content.encode("utf-8")
data.seek(0)
response = {
'ContentLength': len(content),
'ContentType': 'utf-8',
'Body': data,
'ResponseMetadata': {
'Bucket': bucket_name,
}
}
s3_stub.add_response('get_object', response, expected_params)
添加回答
举报