Ejemplo n.º 1
0
    def test_runtime_error_raised_when_shadowing_client_method(self):
        botocore_session = ibm_botocore.session.get_session()
        session = ibm_boto3.session.Session(region_name='us-west-2',
                                            botocore_session=botocore_session)

        def shadows_put_object(class_attributes, **kwargs):
            utils.inject_attribute(class_attributes, 'put_object', 'invalid')

        botocore_session.register('creating-client-class', shadows_put_object)

        with pytest.raises(RuntimeError):
            # This should raise an exception because we're trying to
            # shadow the put_object client method in the
            # shadows_put_object handler above.
            session.client('s3')
def test_all_collections_have_paginators_if_needed():
    # If a collection relies on an operation that is paginated, it
    # will require a paginator to iterate through all of the resources
    # with the all() method. If there is no paginator, it will only
    # make it through the first page of results. So we need to make sure
    # if a collection looks like it uses a paginated operation then there
    # should be a paginator applied to it.
    botocore_session = ibm_botocore.session.get_session()
    session = Session(botocore_session=botocore_session)
    loader = botocore_session.get_component('data_loader')
    for service_name in session.get_available_resources():
        client = session.client(service_name, region_name='us-east-1')
        json_resource_model = loader.load_service_model(
            service_name, 'resources-1')
        resource_defs = json_resource_model['resources']
        resource_models = []
        # Get the service resource model
        service_resource_model = ResourceModel(service_name,
                                               json_resource_model['service'],
                                               resource_defs)
        resource_models.append(service_resource_model)
        # Generate all of the resource models for a service
        for resource_name, resource_defintion in resource_defs.items():
            resource_models.append(
                ResourceModel(resource_name, resource_defintion,
                              resource_defs))
        for resource_model in resource_models:
            # Iterate over all of the collections for each resource model
            # and ensure that the collection has a paginator if it needs one.
            for collection_model in resource_model.collections:
                yield (_assert_collection_has_paginator_if_needed, client,
                       service_name, resource_name, collection_model)
Ejemplo n.º 3
0
def _collection_test_args():
    ibm_botocore_session = ibm_botocore.session.get_session()
    session = Session(botocore_session=ibm_botocore_session)
    loader = ibm_botocore_session.get_component('data_loader')
    for service_name in session.get_available_resources():
        client = session.client(service_name, region_name='us-east-1')
        json_resource_model = loader.load_service_model(
            service_name, 'resources-1'
        )
        resource_defs = json_resource_model['resources']
        resource_models = []
        # Get the service resource model
        service_resource_model = ResourceModel(
            service_name, json_resource_model['service'], resource_defs
        )
        resource_models.append(service_resource_model)
        # Generate all of the resource models for a service
        for resource_name, resource_defintion in resource_defs.items():
            resource_models.append(
                ResourceModel(resource_name, resource_defintion, resource_defs)
            )
        for resource_model in resource_models:
            # Iterate over all of the collections for each resource model
            # and ensure that the collection has a paginator if it needs one.
            for collection_model in resource_model.collections:
                yield (client, service_name, resource_name, collection_model)
Ejemplo n.º 4
0
def test_can_create_all_clients(client_args):
    """Verify we can create all existing clients."""
    session, service_name = client_args
    client = session.client(service_name)
    assert hasattr(client, 'meta')
Ejemplo n.º 5
0
def _test_create_client(session, service_name):
    client = session.client(service_name)
    assert_true(hasattr(client, 'meta'))