Questions tagged [moto]

Moto is a Python library that allows you to easily mock out tests based on AWS infrastructure and the Boto library (an AWS SDK for python).

Moto is a Python library that allows you to easily mock out tests based on AWS infrastructure and the Boto library (an AWS SDK for python).

Related tags:

Links:

193 questions
5
votes
1 answer

How to prevent moto test throwing NoSuchBucketError?

I'm trying to write a test that verifies that register_extracts_by_location is able to read from an s3 bucket and grab the files. When writing the moto mock test, I get an error stating that the bucket doesn't exist. Here's the…
OpenDataAlex
  • 1,375
  • 5
  • 19
  • 39
4
votes
2 answers

Python AWS SQS mocking with MOTO

I am trying to mock an AWS SQS with moto, below is my code from myClass import get_msg_from_sqs from moto import mock_sqs #from moto.sqs import mock_sqs @mock_sqs def test_get_all_msg_from_queue(): #from myClass import get_msg_from_sqs …
Abhishek Patil
  • 1,373
  • 3
  • 30
  • 62
4
votes
1 answer

'TypeError: catching classes that do not inherit from BaseException is not allowed' when trying to mock an exception

I am trying to test a block of code which interacts with the Amazon Forecast service, which looks very similar to the example provided at…
ratiugo
  • 53
  • 1
  • 4
4
votes
2 answers

using moto on a global boto resource

I have my_module something like this: import boto3 S3_RESOURCE = boto3.resource('s3') def some_func(): local_file='local_file.txt' S3_RESOURCE.Object(bucket, key).download_file(Filename=local_file) i am trying to test this method with…
Pratik Roy
  • 724
  • 1
  • 5
  • 21
4
votes
1 answer

How do you mock an aws service that's not mocked by moto?

I'm using moto to mock out aws services to write my test cases and supported use cases is fine: @mock_sts def test_check_aws_profile(self): session = boto3.Session(profile_name='foo') client = session.client('sts') …
Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
4
votes
1 answer

Mocking DynamoDB using moto + serverless

I am trying to write tests for a serverless application using the AWS serverless framework. I am facing a weird issue. Whenever I try to mock S3 or DynamoDB using moto, it does not work. Instead of mocking, the boto3 call actually goes to my AWS…
3
votes
1 answer

Augmenting moto with mock patch where method is not yet implemented

I am writing a lambda function that takes a list of CW Log Groups and runs an "export to s3" task on each of them. I am writing automated tests using pytest and I'm using moto.mock_logs (among others), but create_export_tasks() is not yet…
Felipe Alvarez
  • 3,720
  • 2
  • 33
  • 42
3
votes
1 answer

s3 Mock in lambda_handler test returning botocore.exceptions.ClientError

I'm trying to write a test for my lambda handler, which uses boto3 to download a file from a bucket and store it locally: s3_resource = boto3.resource('s3') TEMP_FILE = '/tmp/file.csv' def lambda_handler(event, context): bucket_name =…
sam_ur_ai
  • 107
  • 10
3
votes
2 answers

Mocking a lambda response with moto

Somewhere in my code, a lambda is called to return a true/false response. I am trying to mock this lambda in my unit tests with no success. This is my code: def _test_update_allowed(): old = ... new = ... assert(is_update_allowed(old,…
user
  • 352
  • 3
  • 13
3
votes
1 answer

How can you simulate DynamoDB pagination using moto?

I'm testing some dynamodb access code. In the past incorrect handling of pagination has caused bugs (developers tend to manually test with small amounts of data, so it's easy to make incorrect assumptions about how pagination works that only come to…
chrisbunney
  • 5,819
  • 7
  • 48
  • 67
3
votes
3 answers

SNS mocking with moto is not working correctly

In my unit test: def test_my_function_that_publishes_to_sns(): conn = boto3.client("sns", region_name="us-east-1") mock_topic = conn.create_topic(Name="mock-topic") topic_arn = mock_topic.get("TopicArn") os.environ["SNS_TOPIC"] =…
red888
  • 27,709
  • 55
  • 204
  • 392
3
votes
1 answer

aws boto3 unittest function that invokes a Lambda function

I have a python function that invokes an AWS Lambda function. #lambda.py import boto3 import os client = boto3.client('lambda') MY_LAMBDA = os.environ['MY_LAMBDA'] def invoke_function(input): response = client.invoke( …
3
votes
1 answer

NoSuchBucket error when trying to mock s3 with moto

I'm trying to mock a s3 connection using moto. My class function looks something like this def do_something(self): conn = boto3.client('s3') objects_dict = client.list_objects(Bucket='some-bucket', Prefix='test') do something with…
Oliver Robie
  • 818
  • 2
  • 11
  • 30
3
votes
1 answer

Mocking multiple AWS services with moto

I'm trying to mock the creation of a compute environment, which requires some other resources, namely an IAM instance profile and service role. However, when I create those IAM resources and then attempt to use them in the compute environment…
Chris F.
  • 773
  • 6
  • 15
3
votes
2 answers

How to run multiple AWS services with moto_server

I am trying to run integration tests against AWS services, to do this I choose moto. Because I am doing this under Java, I wanted to run moto_server, and execute these tests against this mock. The problem I have is that moto_server allows only one…
jpalka
  • 41
  • 1
  • 2
1
2
3
12 13