跳转到主要内容

未提供项目描述

项目描述

Moto - 模拟AWS服务

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

Build Status Coverage Status Docs PyPI PyPI - Python Version PyPI - Downloads Code style: Ruff Financial Contributors

安装

$ pip install 'moto[ec2,s3,all]'

简而言之

Moto是一个库,允许您的测试轻松模拟AWS服务。

想象一下,您有以下Python代码需要测试:

import boto3


class MyModel:
    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)

花点时间想想您过去是如何测试它的。

现在看看您如何使用Moto来测试它

import boto3
from moto import mock_aws
from mymodule import MyModel


@mock_aws
def 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"

使用装饰器包装测试,所有对s3的调用都会自动模拟。模拟会跟踪存储桶和密钥的状态。

有关涵盖哪些服务和功能的完整列表,请参阅我们的实现覆盖率

文档

完整文档可以在这里找到

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

财务贡献

通过赞助我们支持此项目及其持续发展!

点击页面顶部的赞助按钮获取更多信息。

我们的财务由OpenCollective管理,这意味着您可以看到我们所有的贡献和支出:https://opencollective.com/moto

安全联系信息

要报告安全漏洞,请使用Tidelift安全联系。Tidelift将协调修复和披露。

项目详情


发布历史 发布通知 | RSS源

下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

moto-5.0.16.tar.gz (5.5 MB 查看哈希值)

上传时间

构建分发

moto-5.0.16-py2.py3-none-any.whl (3.7 MB 查看哈希值)

上传时间 Python 2 Python 3

由以下提供支持