存根boto3客户端以避免在测试中碰到真正的aws端点

stuboto的Python项目详细描述


斯塔博托

存根boto3客户端,以避免在测试中碰到真正的aws端点。

用法

您可以使用Stuboto实例,就好像它们是botocore.stub.Stubber

importboto3fromstubotoimportStubotodeftest_create_bucket():s3=boto3.client("s3")stubber=Stuboto(s3)stubber.activate()response={"Location":"my-bucket"}expected_params={"Bucket":"my-bucket","ACL":"private"}stubber.add_response("create_bucket",response,expected_params)service_response=s3.create_bucket(Bucket="my-bucket",ACL="private")assertservice_response==response

Stuboto实例使用与原始客户机相同的所有方法进行修饰,因此您还可以使用更具可读性的存根响应:

importboto3fromstubotoimportStubotodeftest_create_bucket():s3=boto3.client("s3")stubber=Stuboto(s3)stubber.activate()response=stubber.create_bucket(Bucket="my-bucket",ACL="private").add_response(Location="my-bucket")service_response=s3.create_bucket(Bucket="my-bucket",ACL="private")assertservice_response==response

botocore.stub.Stubber文档建议:

It should be noted, however, that while missing attributes are often considered correct, your code may not function properly if you leave them out. Therefore you should always fill in every value you see in a typical response for your particular request.

但是如果你为了编写更可读的测试而遗漏了一些值,我不会告诉任何人。

安装

pip install stuboto

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何通过位移位将Android的AudioRecord创建的16位音频转换为12位音频?   处理方程优化反应扩散java   java Change spring应用程序。詹金斯的物业环境   java在求解布尔表达式时如何思考?   java循环引用和垃圾收集的性能   java复制构造函数创建依赖副本   Java数组的字母顺序排序   网站上的java登录到外部门户   java如何使用正则表达式模式匹配   java JTEXTEXTAREA圆角   JBoss Narayana事务与Tomcat中Spring数据JPA的java集成   java Android XmlPullParser返回null+属性检索查询   java JavaFX:当我按enter键时,在tableview中启用编辑列