How to use the botocore.stub.Stubber function in botocore

To help you get started, we’ve selected a few botocore 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 aws-cloudformation / cloudformation-cli / tests / test_packager.py View on Github external
def test_stack_wait(packager):
    stubber = Stubber(packager.client)
    response = {
        "Stacks": [
            {
                "StackName": EXPECTED_STACK_NAME,
                "StackStatus": "CREATE_COMPLETE",
                "CreationTime": FAKE_DATETIME,
            }
        ]
    }
    stubber.add_response("describe_stacks", response)
    with stubber:
        packager.stack_wait(EXPECTED_STACK_NAME, "stack_create_complete")
    stubber.assert_no_pending_responses()
github aws / chalice / tests / unit / deploy / test_deployer.py View on Github external
def stubbed_client(service_name):
    global _SESSION
    if _SESSION is None:
        _SESSION = botocore.session.get_session()
    client = _SESSION.create_client(service_name,
                                    region_name='us-west-2')
    stubber = Stubber(client)
    return client, stubber
github onicagroup / runway / tests / cfngin / test_context.py View on Github external
def test_lock_persistent_graph_locked(self):
        """Error raised when when object is locked."""
        code = '0000'
        context = Context(config=self.persist_graph_config)
        context._s3_bucket_verified = True
        context._persistent_graph = Graph()
        stubber = Stubber(context.s3_conn)
        expected_params = {'Tagging': {
            'TagSet': gen_tagset({context._persistent_graph_lock_tag: code})
        }}
        expected_params.update(context.persistent_graph_location)

        stubber.add_response('get_object_tagging',
                             {'TagSet': gen_tagset(
                                 {context._persistent_graph_lock_tag: '1111'}
                             )},
                             context.persistent_graph_location)

        with stubber:
            with self.assertRaises(PersistentGraphLocked):
                context.lock_persistent_graph(code)
            stubber.assert_no_pending_responses()
github mozilla / telemetry-analysis-service / tests / jobs / test_provisioners.py View on Github external
def test_spark_job_run(mocker, is_public, spark_job_provisioner, user):
    identifier = "test-flow"
    notebook_key = "notebook.ipynb"
    emr_release = "1.0"
    job_timeout = 60
    size = 1

    stubber = Stubber(spark_job_provisioner.emr)
    response = {"JobFlowId": "12345"}
    expected_params = {
        "Applications": [{"Name": "Spark"}, {"Name": "Hive"}, {"Name": "Zeppelin"}],
        "BootstrapActions": [
            {
                "Name": "setup-telemetry-spark-job",
                "ScriptBootstrapAction": {
                    "Args": ["--timeout", str(job_timeout * 60)],
                    "Path": spark_job_provisioner.script_uri,
                },
            }
        ],
        "Configurations": [
            {
                "Classification": "atmo-tests",
                "Properties": {"covering": "everything", "passing": "of-course"},
github aws / aws-secretsmanager-caching-python / test / unit / test_decorators.py View on Github external
def get_client(self, response={}, versions=None, version_response=None):
        client = botocore.session.get_session().create_client('secretsmanager', region_name='us-west-2')
        stubber = Stubber(client)
        expected_params = {'SecretId': 'test'}
        if versions:
            response['VersionIdsToStages'] = versions
        stubber.add_response('describe_secret', response, expected_params)
        if version_response is not None:
            stubber.add_response('get_secret_value', version_response)
        stubber.activate()
        return client
github boto / botocore / tests / unit / test_client.py View on Github external
def test_error_with_empty_code(self):
        creator = self.create_client_creator()
        client = creator.create_client(
            'myservice', 'us-west-2', credentials=self.credentials)

        with Stubber(client) as stub:
            stub.add_client_error('test_operation')
            try:
                client.test_operation(Foo='one', Bar='two')
            except client.exceptions.ClientError as e:
                # This is needed becasue the error could be a subclass of
                # ClientError.
                # We explicitly want it to be a generic ClientError though
                self.assertEqual(e.__class__, exceptions.ClientError)
github awslabs / aws-sam-cli / tests / unit / lib / bootstrap / test_bootstrap.py View on Github external
def _stubbed_cf_client(self):
        cf = botocore.session.get_session().create_client("cloudformation", region_name="us-west-2")
        return [cf, Stubber(cf)]
github boto / botocore / tests / unit / test_client.py View on Github external
def test_error_with_no_wire_code(self):
        creator = self.create_client_creator()
        client = creator.create_client(
            'myservice', 'us-west-2', credentials=self.credentials)

        with Stubber(client) as stub:
            stub.add_client_error('test_operation', '404', 'Not Found')
            try:
                client.test_operation(Foo='one', Bar='two')
            except client.exceptions.ClientError as e:
                # This is needed becasue the error could be a subclass of
                # ClientError.
                # We explicitly want it to be a generic ClientError though
                self.assertEqual(e.__class__, exceptions.ClientError)
github mozilla-iam / cis / python-modules / cis_identity_vault / cis_identity_vault / vault.py View on Github external
def _session(self):
        if self.boto_session is None:
            region = self.config("region_name", namespace="cis", default="us-west-2")
            if self._get_cis_environment() == "local":
                self.boto_session = Stubber(boto3.session.Session(region_name=region)).client
            else:
                self.boto_session = boto3.session.Session(region_name=region)
            return self.boto_session