问题标签 [moto]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
250 浏览

python - moto 不模拟 ec2.describe_security_groups 函数调用

我有这个测试用例和第一个打印件

看起来不错,似乎是正确模拟的响应。但后来:ec2_client.describe_security_groups(GroupIds=['sg-3e2bcf04'])失败

还有什么我需要模拟的吗?

编辑:似乎它在每次运行时都会生成一个不可预测的随机 GroupID。知道如何锁定它吗?

0 投票
1 回答
441 浏览

python - 如何将 KeyManager 添加到使用 moto 模拟的 kms 密钥中

我想创建一个由 AWS 管理的密钥。到目前为止,这就是我所拥有的

但密钥似乎没有 KeyManager 字段:

我尝试在 create_key 调用期间将 KeyManager 添加为参数,但这也不起作用。

好像 moto 不返回 KeyManager 字段。有没有办法专门模拟该返回值但不改变其余参数的 dictionary.get 方法的行为?

IE

key['KeyMetadata']['AWSAccountId']将返回模拟值,然后 key['KeyMetadata']['KeyManager']返回另一个我可以指定的模拟值。

0 投票
1 回答
888 浏览

python - 模拟摩托车数据库实例未从 EnableIAMDatabaseAuthentication 参数读取

我有这个我正在尝试检查的测试,但似乎 EnableIAMDatabaseAuthentication 没有被传递给 moto

{'DBInstance':{'DBInstanceIdentifier':'db-master-1','DBInstanceClass':'db.m1.small','Engine':'postgres','DBInstanceStatus':'available','MasterUsername': 'root', 'Endpoint': {'Address': 'db-master-1.aaaaaaaaaa.us-east-2.rds.amazonaws.com', 'Port': 1234}, 'AllocatedStorage': 10, 'InstanceCreateTime ': datetime.datetime(2020, 1, 13, 13, 1, 10, 665000, tzinfo=tzutc()), 'PreferredBackupWindow': '03:50-04:20', 'BackupRetentionPeriod': 1, 'DBSecurityGroups' :[],'VpcSecurityGroups':[],'DBParameterGroups':[{'DBParameterGroupName':'default.postgres9.3','ParameterApplyStatus':'同步中'}],'PreferredMaintenanceWindow': 'wed:06:38-wed:07:08', 'MultiAZ': False, 'EngineVersion': '9.3.3', 'AutoMinorVersionUpgrade': False, 'ReadReplicaDBInstanceIdentifiers': [], 'LicenseModel': 'general-public-license', 'OptionGroupMemberships': [{'OptionGroupName': 'default.postgres9.3', 'Status': 'in-sync'}], 'PubliclyAccessible': False, 'StatusInfos': [] , 'StorageType': 'gp2', 'StorageEncrypted': False, 'DbiResourceId': 'db-M5ENSHXFPU6XHZ4G4ZEI5QIO2U', 'CopyTagsToSnapshot': False, 'DBInstanceArn': 'arn:aws:rds:us-east-2:1234567890: db:db-master-1', 'IAMDatabaseAuthenticationEnabled': False}, 'ResponseMetadata': {'RequestId':'523e3218-afc7-11c3-90f5-f90431260ab4', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'amazon.com'}, 'RetryAttempts': 0}}

尝试传递 EnableIAMDatabaseAuthentication 参数时我做错了吗?它应该设置:IAMDatabaseAuthenticationEnabled

0 投票
0 回答
282 浏览

python - 您如何模拟未被 moto 模拟的 aws 服务?

我正在使用 moto 模拟 aws 服务来编写我的测试用例,并且支持的用例很好:

但是有一些像 es 这样的服务根本不受支持。我如何开始嘲笑这个?

我已经尝试过这种替代模拟方法进行测试,但不确定是否有更好的方法

0 投票
2 回答
856 浏览

python - 如何在 python 中存根 S3Transfer

使用 moto 中的 botocore.stub 和 mock_s3 我可以像下面那样对 boto3 S3 客户端进行存根,

然后在测试函数中,我可以像下面一样使用 add_client_error 和 add_response 并根据需要添加断言,

但是在我的 S3 类中,我使用 S3Transfer upload_file 将文件上传到 S3,有没有办法模拟 S3Transfer(self.s3_client).upload_file 方法?

0 投票
1 回答
727 浏览

python - moto for python - 写入 sqs 失败

我的代码中有一个方法可以将消息发送到 sqs。我想使用 moto 并使用 aws sqs 服务。

下面是我的代码

这是我的测试用例

conn.send_message测试用例中的工作,但该方法posttosqs失败

error: when calling the SendMessage operation: The specified queue does not exist for this wsdl version.

我能够使用上述方法成功测试 S3 操作,但不能测试 SQS 操作

0 投票
1 回答
824 浏览

amazon-web-services - 如何使用 moto 模拟 ECS?

我想创建一个模拟 ECS 集群,但它似乎无法正常工作。尽管有些东西被嘲笑(我没有收到凭据错误),但似乎没有“保存”集群。

如何使用 moto 创建模拟集群?

MVCE

foo.py

test_foo.py

怎么了

我所期望的

我希望集群 ARN 列表具有一个元素(不是断言语句中的元素,而是一个 ARN)。但是列表是空的。

0 投票
0 回答
438 浏览

amazon-web-services - 尝试使用 moto 模拟 s3 时出现 NoSuchBucket 错误

我正在尝试使用 moto 模拟 s3 连接。我的类函数看起来像这样

我的测试功能看起来像这样

但我不断收到以下错误 botocore.errorfactory.NoSuchBucket: An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist

0 投票
1 回答
513 浏览

python - Moto sns 客户端无法调用 create_topic AttributeError:“生成器”对象没有属性“create_topic”

我正在尝试按照文档执行此操作:

我得到错误:

0 投票
1 回答
1097 浏览

python - Moto SNS 客户端无法发布工作 AttributeError:“sns.ServiceResource”对象没有属性“发布”

我正在尝试使用 Moto 模拟 SNS,使用 pytest 文档中的示例。

sns.create_topic() 有效,但 sns.publish() 无效。从 boto 文档中,我应该能够像这样调用 publish() :

我收到以下错误:

AttributeError:“sns.ServiceResource”对象没有属性“发布”

Moto 不支持发布吗?我希望它验证对 publish() 的调用对我有效 - 我不想发布猴子补丁。