• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

moto: Moto 是一个允许你轻松模拟出基于 AWS 基础设施的测试的库 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

Moto - Mock AWS Services

Join the chat at https://gitter.im/awsmoto/Lobby

Build StatusCoverage StatusDocsPyPIPyPI - Python VersionPyPI - DownloadsCode style: black

Install

$ pip install moto[ec2,s3,all]

In a nutshell

Moto is a library that allows your tests to easily mock out AWS Services.

Imagine you have the following python code that you want to test:

import boto3class MyModel(object):    def __init__(self, name, value):        self.name = name        self.value = value    def save(self):        s3 = boto3.client('s3', region_name='us-east-1')        s3.put_object(Bucket='mybucket', Key=self.name, Body=self.value)

Take a minute to think how you would have tested that in the past.

Now see how you could test it with Moto:

import boto3from moto import mock_s3from mymodule import MyModel@mock_s3def test_my_model_save():    conn = boto3.resource('s3', region_name='us-east-1')    # We need to create the bucket since this is all in Moto's 'virtual' AWS account    conn.create_bucket(Bucket='mybucket')    model_instance = MyModel('steve', 'is awesome')    model_instance.save()    body = conn.Object('mybucket', 'steve').get()['Body'].read().decode("utf-8")    assert body == 'is awesome'

With the decorator wrapping the test, all the calls to s3 are automatically mocked out. The mock keeps the state of the buckets and keys.

For a full list of which services and features are covered, please see our implementation coverage.

Documentation

The full documentation can be found here:

http://docs.getmoto.org/en/latest/


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap