Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 31 2019 22:19
    lightsgoout starred spulec/moto
  • Jan 31 2019 15:50
    drmorr0 commented #2030
  • Jan 31 2019 15:50
    drmorr0 commented #2032
  • Jan 31 2019 13:19
    Samir-Elsayed-Hub starred spulec/moto
  • Jan 31 2019 00:17
  • Jan 30 2019 18:19
    Brett55 commented #2035
  • Jan 30 2019 18:03
    dargueta commented #1886
  • Jan 30 2019 17:23
    dgea005 starred spulec/moto
  • Jan 30 2019 16:53
    sturmer opened #2040
  • Jan 30 2019 16:52
    perf123 commented #2038
  • Jan 30 2019 16:52
    perf123 closed #2038
  • Jan 30 2019 15:42
    jakul commented #1558
  • Jan 30 2019 15:40
    jakul commented #1558
  • Jan 30 2019 14:01
    perf123 edited #2038
  • Jan 30 2019 11:25
    craiga commented #2036
  • Jan 30 2019 07:26
    anshitmt edited #2039
  • Jan 30 2019 07:26
    anshitmt opened #2039
  • Jan 29 2019 22:50
    jayhale starred spulec/moto
  • Jan 29 2019 21:22
    mikegrima commented #1912
  • Jan 29 2019 21:19
    mikegrima commented #1886
lexxish
@lexxish
Is there a reason to use localstack (https://localstack.cloud/) over just using moto directly?
Alex LordThorsen
@rawrgulmuffins

Hi everyone, I opened this issue a few days ago and I'm interested in writing a patch for it.

spulec/moto#2662

Would it be sufficient to copy this test but add dimensions and then do a retrieval?

https://github.com/spulec/moto/blob/master/tests/test_cloudwatch/test_cloudwatch_boto3.py#L143

Or are there other features of metric dimensions that would need to be added that aren't covered by my ticket?

John Corrales
@corrjo
Was wondering when we might expect a release? Releases seem a bit sporadic, would love a release schedule, or cd on master would be amazing.
Franz Allan Valencia See
@franz-see

how do i run moto server in debug mode?

I tried running this via my vscode

        {
            "name": "moto_server cognito-idp",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/moto/server.py",
            "console": "integratedTerminal",
            "args": [
                "cognito-idp"
            ],
            "justMyCode": false
        },

and then i tried hitting admin_initiate_auth. The server responds but my breakpoint does not stop in any of the admin_initiate_auth methods.

Any tips?

Franz Allan Valencia See
@franz-see
Looks like my breakpoints on admin_initiate_auth does not work because it loads moto inside the site-packages instead of in the source. To fix that, I added this in server.py after from __future__ import unicode_literalsand before moto is imported
import os, sys
additional_path = os.path.join(os.path.dirname(__file__), "..")
print('additional_path %s' % os.path.abspath(additional_path))
sys.path.append(additional_path)
Franz Allan Valencia See
@franz-see
Hi all, i filed two tickets and have fixes for both. hoping a maintainer can review them:
Franz Allan Valencia See
@franz-see
And this one as well spulec/moto#2672
Stijn Seghers
@Procrat
Hi all! We're looking at using moto at our company and we're pretty excited by it. We noticed that import moto takes ~3s (on my laptop) and it looks like all backends are being loaded at that point -- correct me if I'm wrong. Would you be interested in a PR that loads the backends only when they're being used?
Patrick Delaney
@ptdel
Hello, I have a fork with a WIP branch adding EFS to moto. Is it preferable to submit a PR for each implemented method with tests, or just the final addition of the service with all methods implemented.
John Corrales
@corrjo
@ptdel Not sure what the maintainers preference is, but for resource types i've added I made 1 PR with all methods and tests.
Patrick Delaney
@ptdel
thanks @corrjo I'll probably take that route, didn't want to surprise anybody with a large PR :-p
Ciaran Evans
@ciaranevans
Hi folks, I'm trying to write a helper function that checks for the completion of a list of Step Function executions. In my unit tests I would like a way to give a list of responses for describe_execution() to return. For example, if I call the method two times, I want them both to return with a status of RUNNING but the third and fourth calls return SUCCEEDED. Is there a way to do this with moto/mock?
Ciaran Evans
@ciaranevans
^ Cheated and just extracted that one method call into a wrapper.
Steve Pulec
@spulec
@ptdel feel free to submit all as one PR
Edwin Caldon
@edycop

Hi, I have a lambda function in a folder and it just put an item in DynamoDB:

import boto3
from botocore.exceptions import ClientError

REQUESTS_TABLE = os.getenv('REQUESTS_TABLE')

def handler(request: dict, _context) -> dict:
    item = request['body']
        response = save_data(item)

def save_data(item: dict, table) -> bool:
    row = {}
    row.update({'email': item['email']})
    row.update({'product_id': item['product_id']})
    print(f'item: {item}')
    try:
        dynamodb = boto3.resource("dynamodb")
        table = dynamodb.Table(REQUESTS_TABLE)
        table.put_item(TableName=REQUESTS_TABLE, Item=row)
    except ClientError as err:
        return False
    return True

But when I try to test it, this code is into other file and other folder:

import resources.requests.sfn_src.save_data as save_data
import unittest
import os

from moto import mock_dynamodb2
class SavedataTestMethods(unittest.TestCase):

    def setUp(self):
        print(f'setUp')

@mock_dynamodb2
    def test_handler_whithout_error(self):
        expected_event = {"statusCode": 200, "body": "ok"}
        input_event = {
            'code': 200,
            'body': {
                'email': 'test@mail.com',
                'product_id': '1',
            },
            'message': 'SUCCEEDED'
        }
        output_event = save_data.handler(input_event, {"table": self.table})

        self.assertEqual(expected_event, output_event)
        pass

if __name__ == "__main__":
    unittest.main()

I got this error:

An error occurred (ResourceNotFoundException) when calling the PutItem operation: Requested resource not found

But if in save_data function I printed "table" variable it shows the table that I need. So I don't know why it doesn't find the resource.

Edwin Caldon
@edycop

I figured out, in the same test function I must create the DynamoDB Table :

import resources.requests.sfn_src.save_data as save_data
import unittest
import os

from moto import mock_dynamodb2
import boto3

REQUESTS_TABLE = os.getenv('REQUESTS_TABLE')

class SavedataTestMethods(unittest.TestCase):

   @mock_dynamodb2
    def test_handler_whithout_error(self):
        dynamodb = boto3.resource("dynamodb")

        # Create the DynamoDB table.
        table = dynamodb.create_table(
            TableName=REQUESTS_TABLE,
            KeySchema=[
                {
                    'AttributeName': 'id',
                    'KeyType': 'HASH'
                }
            ],
            AttributeDefinitions=[
                {
                    'AttributeName': 'id',
                    'AttributeType': 'S'
                }
            ],
            ProvisionedThroughput={
                'ReadCapacityUnits': 5,
                'WriteCapacityUnits': 5
            }
        )

        table = dynamodb.Table(REQUESTS_TABLE)

        expected_event = {"statusCode": 200, "body": "ok"}
        input_event = {
            'code': 200,
            'body': {
                'email': 'test@mail.com',
                'product_id': '1',
                'url': 'https://url',
                'first_request': True
            },
            'message': 'SUCCEEDED'
        }

        output_event = save_data.handler(input_event, {})

        self.assertEqual(expected_event, output_event)

SOLVED :+1:

drewmullen
@drewmullen
does anyone have examples of how to use assert_called_with() against resources created by moto?
John Corrales
@corrjo
using assert_called_with() is just testing that you passed the right arguments to a function. you wouldn't necessarily use it to check created resources.
drewmullen
@drewmullen

so i decided this SPECIFIC test was not actually useful (scrapped it) so ignore the uselessness of the test. i guess my confusion is regarding fixtures in general. when i call client.attach_volume.assert_called_with() against my moto client fixture i get error: AttributeError: 'function' object has no attribute 'assert_called_with'

conftest.py

@pytest.fixture(scope='function')
def client(aws_credentials):
    with mock_ec2():
        yield boto3.client('ec2', region_name=REGION)

lambda_function.py

def attach_ebs_volume(client, instance_id, region):
    while utils.get_instance_state(client, instance_id) != "running":
        print("waiting for instance to start")
        time.sleep(5)
        #TODO: timeout

    for tag in utils.get_instance_tags(client, instance_id):
        if tag['Key'] == "volume":
            vol_tag = tag['Value']

    volume_id = utils.get_ebs_by_name_tag(client, vol_tag)
    client.attach_volume(
        Device="/dev/xvdz",
        InstanceId=instance_id,
        VolumeId=volume_id
    )

output from pytest:

    @mock.patch('utils.get_instance_state')
    @mock.patch('utils.get_instance_tags')
    def test_attach_ebs_volume(mock_get_instance_tags, mock_get_instance_state, client):
        volume_id = client.create_volume(Size=7, AvailabilityZone=REGION, TagSpecifications=VOLUME_TAGS)['VolumeId']
        instance_id = client.run_instances(ImageId='ami-123', MinCount=1, MaxCount=1, TagSpecifications=INSTANCE_TAGS)['Instances'][0]['InstanceId']

        mock_get_instance_state.return_value = 'running'
        mock_get_instance_tags.return_value = RETURN_TAGS

        r = lambda_function.attach_ebs_volume(client,
                                                instance_id=instance_id,
                                                region=REGION
                                                )

>       client.attach_volume.assert_called_with(Device="/dev/xvdz",
                                                InstanceId=instance_id,
                                                VolumeId=volume_id)
E       AttributeError: 'function' object has no attribute 'assert_called_with'

i was trying to test that client.attach_volume gets the right values. again, this is not actually that useful of a test but the functionality probably will in future tests

sunjiajing0815
@sunjiajing0815
Hi I am trying to mock lambda with moto, but keep getting this error when invoking a lambda: requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
Tomer Shalev
@tomers
Hi, is there an official Docker Hub release for moto?
Leo Shklovskii
@leos
Hi - what's the timeline for the next release? We'd love to see this fix released to clean up our CI logs: spulec/moto@882dfce
Asher Foa
@asherf
@leos moto automatically releases a version on every commit to master. it is a pre-release, but if you are blocked by a fix that was merged, you can always pin the pre-release in your requirements file.
When the team eventually releases a new version of moto, it will basically be turning whatever the latest pre-releases available to be a regular release.
Having said that, I think it is time to do a moto release ;-)
Leo Shklovskii
@leos
Thanks @asherf ! it's not a blocker and you're right we can definitely target a github commit but we feel way more warm and fuzzy when it's a tagged version - and yes we'd love to see the team do an actual moto release :-)
Marcus Guimaraes
@mzguimaraes
hey y'all, I need to mock an Organization that contains an account with a specific AWS ID, not the randomized value moto creates with orgs.create_account(). Are any of the following solutions feasible:
  1. call orgs.create_account(), then overwrite the ID of the account generated to match spec
  2. call orgs.create_account() in a way that forces the generated ID to be set to the spec ID
  3. mock an account join handshake procedure
    Thanks!
Niraj Bhatt
@nirajvbhatt
Any update on next release? Need organization tags usage. Thanks.
Niraj Bhatt
@nirajvbhatt

hey y'all, I need to mock an Organization that contains an account with a specific AWS ID, not the randomized value moto creates with orgs.create_account(). Are any of the following solutions feasible:

  1. call orgs.create_account(), then overwrite the ID of the account generated to match spec
  2. call orgs.create_account() in a way that forces the generated ID to be set to the spec ID
  3. mock an account join handshake procedure
    Thanks!

I think option 1 should work. I don't think option 2 is possible. No idea about option 3

Arcadiy Ivanov
@arcivanov
Hello folks
There are a few things in S3 error handling that make no sense to me
I was wondering if someone could chime in before I start filing bugs
Here it seems a wrong template is used
Arcadiy Ivanov
@arcivanov
And then I'm getting these weird failures where moto server is disregarding the exception and returns the code straight up: https://github.com/spulec/moto/pull/3021#issuecomment-633273171
Dawn James
@dawngerpony

hello! This is my first time here :wave:

Has anyone else noticed that test_streaming_upload_from_file_to_presigned_url is generating an error when it was fine yesterday? I can't find any existing open issues related to it, so I have raised an issue (spulec/moto#3080) and fixed it in a draft PR.

Advice would be appreciated :pray:

Dawn James
@dawngerpony
NB. the above PR is ready for review, and fixes two issues: the one mentioned above, and another issue that has been open for a while. Comments welcomed!
Leo Shklovskii
@leos
@spulec any updates on doing a release? If trunk is in good shape then a release should really be a no-op - would be great to have a new one
Anything I can do to help with making a release happen?
Dawn James
@dawngerpony
@leos maybe a release can happen after I finish spulec/moto#3082 which will add basic support for ApplicationAutoscaling
Vish Upadhyay
@vupadhyay
@spulec wondering why moto library depends on idna [required: >=2.5,<2.9]? I'm being forced to use idna-2.8 which was released on Dec4, 2018. My pipenv package manager fails for DependencyConflict as I have some other package in my environment that is installing idna-2.9.
Leon Mika
@lmika

Hello. First time caller here.

I'm using moto to mock out SES and I want to verify that I've made a call to "send_raw_email". Poking around the code I've noticed that I can get the send messages from the "ses_backends". This solves my problem, but I'm just wondering if this is considered "best practice". How did others do this?

Dawn James
@dawngerpony
hi @vupadhyay - I've noticed this problem too, perhaps you would like to raise an issue? https://github.com/spulec/moto/issues/new
Craig
@Tecktron
Since the lastest patch release breaks all our builds, when will the documentation be updated? I've raised issue here about the new requirement of the docker package: spulec/moto#3297
Mickey Pashov
@mickeypash
Hey folks,
I haven't used Moto in anger in about 2 and a bit years
I recently joined a company where they have decided to move away from Moto as they say it's not compatible with the latest version of boto
I cursory search didn't yield any results
Is it true that moto doesn't support the more recent versions of boto?
Steve Pulec
@spulec
Moto supports the latest version of boto3 and shouldn't have any problems with boto today. That being said, boto is a deprecated library so we will drop support at some point for boto directly. Boto would still work in server-based mode as would any client in any language.
Rob Reus
@RobReus
Hi all, currently implementing moto to test custom config rules. Running into the issue that the method "get_compliance_details_by_config_rule" is not implemented. What would be the easiest way to work around this? I dont care about the data returned by that method, an empty list is fine. Just want the test to succeed and not fail on a NotImplementedError. I have been able to get it to work by just adding a method to the models.py and responses.py files within the moto site-package, but of course this is not the way to go. Does anyone have an example on how to "hack" an extra method into a moto service mock?