def test_can_initialize_with_search_paths(self):
     loader = Loader(extra_search_paths=['foo', 'bar'])
     # Note that the extra search paths are before
     # the customer/builtin data paths.
     self.assertEqual(loader.search_paths, [
         'foo', 'bar', loader.CUSTOMER_DATA_PATH, loader.BUILTIN_DATA_PATH
     ])
    def setup_client(self):
        with open(self.example_model_file, 'w') as f:
            json.dump(self.example_json_model, f)

        with open(self.waiter_model_file, 'w') as f:
            json.dump(self.waiter_json_model, f)

        with open(self.paginator_model_file, 'w') as f:
            json.dump(self.paginator_json_model, f)

        with open(self.model_file, 'w') as f:
            json.dump(self.json_model, f)

        self.loader = Loader(extra_search_paths=[self.root_dir])

        endpoint_resolver = mock.Mock()
        endpoint_resolver.construct_endpoint.return_value = {
            'hostname': 'foo.us-east-1',
            'partition': 'aws',
            'endpointName': 'us-east-1',
            'signatureVersions': ['v4']
        }

        self.creator = ClientCreator(loader=self.loader,
                                     endpoint_resolver=endpoint_resolver,
                                     user_agent='user-agent',
                                     event_emitter=self.events,
                                     retry_handler_factory=mock.Mock(),
                                     retry_config_translator=mock.Mock(),
                                     exceptions_factory=mock.Mock())

        self.client = self.creator.create_client('myservice', 'us-east-1')
def test_paginators_and_waiters_are_not_lost_in_new_version():
    for service_name in Session().get_available_services():
        versions = Loader().list_api_versions(service_name, 'service-2')
        if len(versions) > 1:
            for type_name in ['paginators-1', 'waiters-2']:
                yield (_test_model_is_not_lost, service_name, type_name,
                       versions[-2], versions[-1])
Beispiel #4
0
 def setup_client_and_resource(self):
     self._write_models()
     self.loader = Loader(extra_search_paths=[self.root_dir])
     self.botocore_session = ibm_botocore.session.get_session()
     self.botocore_session.register_component('data_loader', self.loader)
     self.session = Session(botocore_session=self.botocore_session,
                            region_name='us-east-1')
     self.client = self.session.client('myservice', 'us-east-1')
     self.resource = self.session.resource('myservice', 'us-east-1')
    def test_data_not_found_raises_exception(self):
        class FakeLoader(object):
            def load_file(self, name):
                # Returning None indicates that the
                # loader couldn't find anything.
                return None

        loader = Loader(file_loader=FakeLoader())
        with self.assertRaises(DataNotFoundError):
            loader.load_data('baz')
 def loader_with_fake_dirs(self):
     mock_file_loader = mock.Mock()
     mock_file_loader.exists = self.fake_exists
     search_paths = list(self.fake_directories)
     loader = Loader(extra_search_paths=search_paths,
                     include_default_search_paths=False,
                     file_loader=mock_file_loader)
     with mock.patch('os.listdir', self.fake_listdir):
         with mock.patch('os.path.isdir', mock.Mock(return_value=True)):
             yield loader
 def test_default_search_paths(self):
     loader = Loader()
     self.assertEqual(len(loader.search_paths), 2)
     # We should also have ~/.aws/models added to
     # the search path.  To deal with cross platform
     # issues we'll just check for a path that ends
     # with .aws/models.
     home_dir_path = os.path.join('.aws', 'models')
     self.assertTrue(
         any(p.endswith(home_dir_path) for p in loader.search_paths))
    def test_load_data_uses_loader(self):
        search_paths = ['foo', 'bar', 'baz']

        class FakeLoader(object):
            def load_file(self, name):
                expected_ending = os.path.join('bar', 'baz')
                if name.endswith(expected_ending):
                    return ['loaded data']

        loader = Loader(extra_search_paths=search_paths,
                        file_loader=FakeLoader())
        loaded = loader.load_data('baz')
        self.assertEqual(loaded, ['loaded data'])
    def test_load_service_model(self):
        class FakeLoader(object):
            def load_file(self, name):
                return ['loaded data']

        loader = Loader(extra_search_paths=['foo'],
                        file_loader=FakeLoader(),
                        include_default_search_paths=False,
                        include_default_extras=False)
        loader.determine_latest_version = mock.Mock(return_value='2015-03-01')
        loader.list_available_services = mock.Mock(return_value=['baz'])
        loaded = loader.load_service_model('baz', type_name='service-2')
        self.assertEqual(loaded, ['loaded data'])
    def setUp(self):
        super(TestMergeExtras, self).setUp()
        self.file_loader = mock.Mock()
        self.data_loader = Loader(extra_search_paths=['datapath'],
                                  file_loader=self.file_loader,
                                  include_default_search_paths=False)
        self.data_loader.determine_latest_version = mock.Mock(
            return_value='2015-03-01')
        self.data_loader.list_available_services = mock.Mock(
            return_value=['myservice'])

        isdir_mock = mock.Mock(return_value=True)
        self.isdir_patch = mock.patch('os.path.isdir', isdir_mock)
        self.isdir_patch.start()
    def test_load_service_model_uses_provided_type_name(self):
        loader = Loader(extra_search_paths=['foo'],
                        file_loader=mock.Mock(),
                        include_default_search_paths=False)
        loader.list_available_services = mock.Mock(return_value=['baz'])

        # Should have a) the unknown service name and b) list of valid
        # service names.
        provided_type_name = 'not-service-2'
        with self.assertRaisesRegexp(UnknownServiceError,
                                     'Unknown service.*BAZ.*baz'):
            loader.load_service_model('BAZ', type_name=provided_type_name)

        loader.list_available_services.assert_called_with(provided_type_name)
def test_paginators_and_waiters_are_not_lost_in_new_version(
        service_name, type_name, previous_version, latest_version):
    # Make sure if a paginator and/or waiter exists in previous version,
    # there will be a successor existing in latest version.
    loader = Loader()
    try:
        loader.load_service_model(service_name, type_name, previous_version)
    except DataNotFoundError:
        pass
    else:
        try:
            loader.load_service_model(service_name, type_name, latest_version)
        except DataNotFoundError as e:
            raise AssertionError(
                f"{type_name} must exist for {service_name}: {e}")
    def test_load_service_model_enforces_case(self):
        class FakeLoader(object):
            def load_file(self, name):
                return ['loaded data']

        loader = Loader(extra_search_paths=['foo'],
                        file_loader=FakeLoader(),
                        include_default_search_paths=False)
        loader.determine_latest_version = mock.Mock(return_value='2015-03-01')
        loader.list_available_services = mock.Mock(return_value=['baz'])

        # Should have a) the unknown service name and b) list of valid
        # service names.
        with self.assertRaisesRegexp(UnknownServiceError,
                                     'Unknown service.*BAZ.*baz'):
            loader.load_service_model('BAZ', type_name='service-2')
    def test_include_default_extras(self):
        self.data_loader = Loader(extra_search_paths=['datapath'],
                                  file_loader=self.file_loader,
                                  include_default_search_paths=False,
                                  include_default_extras=False)
        self.data_loader.determine_latest_version = mock.Mock(
            return_value='2015-03-01')
        self.data_loader.list_available_services = mock.Mock(
            return_value=['myservice'])

        service_data = {'foo': 'service', 'bar': 'service'}
        service_data_copy = copy.copy(service_data)
        sdk_extras = {'merge': {'foo': 'sdk'}}
        self.file_loader.load_file.side_effect = [service_data, sdk_extras]

        loaded = self.data_loader.load_service_model('myservice', 'service-2')
        self.assertEqual(loaded, service_data_copy)
def _test_model_is_not_lost(service_name, type_name, previous_version,
                            latest_version):
    # Make sure if a paginator and/or waiter exists in previous version,
    # there will be a successor existing in latest version.
    loader = Loader()
    try:
        previous = loader.load_service_model(service_name, type_name,
                                             previous_version)
    except DataNotFoundError:
        pass
    else:
        try:
            latest = loader.load_service_model(service_name, type_name,
                                               latest_version)
        except DataNotFoundError as e:
            raise AssertionError("%s must exist for %s: %s" %
                                 (type_name, service_name, e))
 def test_error_raised_if_service_does_not_exist(self):
     loader = Loader(extra_search_paths=[],
                     include_default_search_paths=False)
     with self.assertRaises(DataNotFoundError):
         loader.determine_latest_version('unknownservice', 'service-2')
 def test_can_add_to_search_path(self):
     loader = Loader()
     loader.search_paths.append('mypath')
     self.assertIn('mypath', loader.search_paths)
 def setUp(self):
     super(ServiceWaiterFunctionalTest, self).setUp()
     self.data_path = os.path.join(
         os.path.dirname(ibm_botocore.__file__), 'data')
     self.environ['AWS_DATA_PATH'] = self.data_path
     self.loader = Loader([self.data_path])
def _paginators_and_waiters_test_cases():
    for service_name in Session().get_available_services():
        versions = Loader().list_api_versions(service_name, 'service-2')
        if len(versions) > 1:
            for type_name in ['paginators-1', 'waiters-2']:
                yield service_name, type_name, versions[-2], versions[-1]