Jor*_*kie 6 amazon-s3 botocore aws-sdk boto3 python-3.7
目前正在编写测试并尝试利用Stubber
botocore 提供的功能。
我想:
client = boto3.client("s3")
response = {'Body': 'content'}
expected_params = {'Bucket': 'a_bucket_name', 'Key': 'a_path', 'Filename': 'a_target'}
with Stubber(client) as stubber:
stubber.add_response('download_file', response, expected_params)
download_file(client, "a_bucket_name", "a_path", "a_target")
Run Code Online (Sandbox Code Playgroud)
该下载文件是我自己的函数,仅包装客户端 download_file 调用。它在实践中有效。
stubber.add_response
但是,由于“OperationNotFound”错误,测试失败。我使用调试器逐步完成,问题出现在存根 API 中:
if not hasattr(self.client, method):
raise ValueError(
"Client %s does not have method: %s"
% (self.client.meta.service_model.service_name, method))
# Create a successful http response
http_response = AWSResponse(None, 200, {}, None)
operation_name = self.client.meta.method_to_api_mapping.get(method) <------- Error here
self._validate_response(operation_name, service_response)
Run Code Online (Sandbox Code Playgroud)
字典中似乎没有两者之间的映射,这是存根 API 的失败还是我遗漏了什么?
我刚刚发现这个问题,所以看起来这一次确实是图书馆而不是我:
https://github.com/boto/botocore/issues/974
这是因为 download_file 和 upload_file 是 boto3 中的自定义项。他们在幕后发出一个或多个请求。目前,除了记录他们使用的底层命令并将其添加到存根之外,还没有一个很好的故事来支持自定义。有一个外部库可以为您处理这个问题,尽管我们自己不支持它。
归档时间: |
|
查看次数: |
2064 次 |
最近记录: |