How to use moto - 10 common examples

To help you get started, we’ve selected a few moto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spulec / moto / tests / test_ec2 / test_elastic_network_interfaces.py View on Github external
@mock_ec2
def test_elastic_network_interfaces_get_by_vpc_id():
    ec2 = boto3.resource("ec2", region_name="us-west-2")
    ec2_client = boto3.client("ec2", region_name="us-west-2")

    vpc = ec2.create_vpc(CidrBlock="10.0.0.0/16")
    subnet = ec2.create_subnet(
        VpcId=vpc.id, CidrBlock="10.0.0.0/24", AvailabilityZone="us-west-2a"
    )

    eni1 = ec2.create_network_interface(
        SubnetId=subnet.id, PrivateIpAddress="10.0.10.5"
    )

    # The status of the new interface should be 'available'
    waiter = ec2_client.get_waiter("network_interface_available")
    waiter.wait(NetworkInterfaceIds=[eni1.id])
github alphagov / notify-api / tests / app / scheduled_jobs / test_sms.py View on Github external
@moto.mock_sqs
def test_should_send_sms_all_notifications(notify_api, notify_db, notify_db_session, notify_config, mocker):
    mocker.patch('app.sms_wrapper.send', return_value=("1234", "twilio"))
    create_notification = Notification(
        id=1000,
        to="to",
        message="message",
        created_at=datetime.utcnow(),
        status='created',
        method='sms',
        job_id=1234
    )
    db.session.add(create_notification)
    db.session.commit()

    read_notification_2 = Notification.query.get(1234)
github Scout24 / afp-core / src / unittest / python / api_endpoint_tests.py View on Github external
    @mock_sts
    @patch("aws_federation_proxy.aws_federation_proxy.requests.get")
    def test_get_credentials_and_consoleurl(self, mock_get):
        token = "abcdefg123"
        callbackurl = ""
        mock_get.return_value = Mock(text=u'{"SigninToken": "%s"}' % token,
                                     status_code=200,
                                     reason="Ok")
        url_template = (u"https://signin.aws.amazon.com/federation?"
                        u"Action=login&"
                        u"Issuer={callbackurl}&"
                        u"Destination=https%3A%2F%2Fconsole.aws.amazon.com%2F&"
                        u"SigninToken={token}")
        expected_url = url_template.format(callbackurl=callbackurl,
                                           token=token)
        expected_credentials = dict(CREDENTIALS)
        expected_credentials['ConsoleUrl'] = expected_url
github onicagroup / runway / tests / cfngin / hooks / test_aws_lambda.py View on Github external
    @mock_s3
    def test_follow_symlink_omitted(self):
        """Same as test_follow_symlink_false, but default behavior."""
        with self.temp_directory_with_files() as temp_dir1:
            root1 = temp_dir1.path
            with self.temp_directory_with_files() as temp_dir2:
                root2 = temp_dir2.path
                os.symlink(root1 + "/f1", root2 + "/f3")
                results = self.run_hook(functions={
                    'MyFunction': {
                        'path': root2}
                })
            self.assertIsNotNone(results)

            code = results.get('MyFunction')
            self.assertIsInstance(code, Code)
            self.assert_s3_zip_file_list(code.S3Bucket, code.S3Key, [
github kyocum / disdat / tests / functional / test_managed.py View on Github external
@moto.mock_s3
def test_remote_no_push_managed_s3():
    api.delete_context(TEST_CONTEXT)
    api.context(context_name=TEST_CONTEXT)

    # Setup moto s3 resources
    s3_client = boto3.client('s3')
    s3_resource = boto3.resource('s3')
    s3_resource.create_bucket(Bucket=TEST_BUCKET)

    # Make sure bucket is empty
    objects = s3_client.list_objects(Bucket=TEST_BUCKET)
    assert 'Contents' not in objects, 'Bucket should be empty'

    # Bind remote context
    api.remote(TEST_CONTEXT, TEST_REMOTE, TEST_BUCKET_URL)
github MartinThoma / cfg_load / tests / test_remote.py View on Github external
@mock_s3
def test_load_aws_s3_error():
    source = "s3://ryft-public-sample-data/"
    sink = "ignore.deb"
    with pytest.raises(ValueError):
        cfg_load.remote.load(source, sink)
github onicagroup / runway / tests / cfngin / hooks / test_aws_lambda.py View on Github external
    @mock_s3
    def test_path_missing(self):
        """Test path missing."""
        msg = "missing required property 'path' in function 'MyFunction'"
        with ShouldRaise(ValueError(msg)):
            self.run_hook(functions={
                'MyFunction': {
                }
github mozilla / build-relengapi / relengapi / blueprints / tooltool / test_tooltool.py View on Github external
@moto.mock_s3
@test_context
def test_get_batch_found(client):
    batch = mkbatch()
    batch['files']['two'] = {
        'algorithm': 'sha512',
        'size': len(TWO),
        'digest': TWO_DIGEST,
        'visibility': 'public',
    }
    with set_time():
        resp = upload_batch(client, batch)
        eq_(resp.status_code, 200, resp.data)
    resp = client.get('/tooltool/upload/1')
    eq_(resp.status_code, 200, resp.data)
    eq_(json.loads(resp.data)['result'], {
        "author": "me",
github spulec / moto / tests / test_s3 / test_s3.py View on Github external
@mock_s3
@mock_s3_deprecated
def test_post_to_bucket():
    conn = boto.connect_s3("the_key", "the_secret")
    bucket = conn.create_bucket("foobar")

    requests.post(
        "https://foobar.s3.amazonaws.com/", {"key": "the-key", "file": "nothing"}
    )

    bucket.get_key("the-key").get_contents_as_string().should.equal(b"nothing")
github Clever / ARCHIVED-ebs-snapshots / test / test_s3_backup_config.py View on Github external
    @mock_s3
    def test_can_initialize(self):
        # if key doesn't exist, initialization should still succeed in case key
        # is written after daemon is started
        b = S3BackupConfig(
            "s3://fake-bucket/fake-backup-conf.yml")