class ServiceWaiterFunctionalTest(BaseEnvVar): """ This class is used as a base class if you want to functionally test the waiters for a specific service. """ def setUp(self): super(ServiceWaiterFunctionalTest, self).setUp() self.data_path = os.path.join(os.path.dirname(botocore.__file__), 'data') self.environ['BOTO_DATA_PATH'] = self.data_path self.loader = Loader(self.data_path) def get_waiter_model(self, service, api_version=None): """ Get the waiter model for the service """ service = os.path.join('aws', service) model_version = self.loader.determine_latest(service, api_version) # Some wierd formatting required to get the name of the model # correct. Right now this is returned: YYYY-MM-DD.api # We need: YYYY-MM-DD model_version = ''.join(model_version.split('.')[:-1]) waiter_model = model_version + '.waiters' return WaiterModel(self.loader.load_data(waiter_model))
class ServiceWaiterFunctionalTest(BaseEnvVar): """ This class is used as a base class if you want to functionally test the waiters for a specific service. """ def setUp(self): super(ServiceWaiterFunctionalTest, self).setUp() self.data_path = os.path.join( os.path.dirname(botocore.__file__), 'data') self.environ['BOTO_DATA_PATH'] = self.data_path self.loader = Loader(self.data_path) def get_waiter_model(self, service, api_version=None): """ Get the waiter model for the service """ service = os.path.join('aws', service) model_version = self.loader.determine_latest(service, api_version) # Some wierd formatting required to get the name of the model # correct. Right now this is returned: YYYY-MM-DD.api # We need: YYYY-MM-DD model_version = ''.join(model_version.split('.')[:-1]) waiter_model = model_version + '.waiters' return WaiterModel(self.loader.load_data(waiter_model))
class LoaderTestCase(BaseEnvVar): def setUp(self): super(LoaderTestCase, self).setUp() self.data_path = os.path.join(os.path.dirname(__file__), 'data') self.environ['BOTO_DATA_PATH'] = self.data_path self.loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) # Make sure the cache is clear. self.loader._cache.clear() def test_data_path_not_required(self): loader = Loader() self.assertEqual(loader.data_path, '') loader.data_path = 'foo:bar' self.assertEqual(loader.data_path, 'foo:bar') def test_get_search_paths(self): paths = self.loader.get_search_paths() self.assertTrue(self.data_path in paths) def test_determine_latest_no_version(self): path = self.loader.determine_latest('someservice') self.assertEqual(path, os.path.join('someservice', '2013-08-21.normal')) def test_determine_latest_with_version(self): path = self.loader.determine_latest( 'someservice', api_version='2012-10-01' ) self.assertEqual(path, os.path.join('someservice', '2012-10-01.normal')) def test_determine_latest_with_version_the_wrong_way(self): with self.assertRaises(ApiVersionNotFoundError): self.loader.determine_latest('someservice/2012-10-01') def test_determine_latest_with_version_not_found(self): with self.assertRaises(ApiVersionNotFoundError): path = self.loader.determine_latest( 'someservice', api_version='2010-02-02' ) def test_load_data_plain_file(self): data = self.loader.load_data('foo') self.assertEqual(data['test_key_1'], 'test_value_1') def test_load_data_plain_file_nonexistant(self): with self.assertRaises(DataNotFoundError): data = self.loader.load_data('i_totally_dont_exist') def test_load_service_model_latest_without_version(self): data = self.loader.load_service_model('someservice') self.assertEqual(data['api_version'], '2013-08-21') def test_load_service_model_with_version(self): data = self.loader.load_service_model( 'someservice', api_version='2012-10-01' ) self.assertEqual(data['api_version'], '2012-10-01') def test_load_service_model_version_not_found(self): with self.assertRaises(ApiVersionNotFoundError): data = self.loader.load_service_model( 'someservice', api_version='2010-02-02' ) def test_load_service_model_data_path_order(self): # There's an s3/ directory both in our custom BOTO_DATA_PATH # directory as well as in the botocore/data/ directory. # Our path should win since the default built in path is always # last. data = self.loader.load_service_model('aws/s3') self.assertTrue(data.get('WAS_OVERRIDEN_VIA_DATA_PATH'), "S3 model was loaded from botocore's default " "data path instead of from the BOTO_DATA_PATH" " directory.") def test_list_available_services(self): avail = self.loader.list_available_services('') self.assertEqual(sorted(avail), [ 'aws', 'aws', 'someservice', 'sub', ]) aws_avail = self.loader.list_available_services('aws') self.assertTrue(len(aws_avail) > 10) self.assertTrue('ec2' in aws_avail) def test_load_data_overridden(self): self.overrides_path = os.path.join( os.path.dirname(__file__), 'data_overrides' ) self.environ['BOTO_DATA_PATH'] = "{0}{1}{2}".format( self.overrides_path, os.pathsep, self.data_path ) loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) # This should load the data the first data it finds. data = loader.load_service_model( 'someservice', api_version='2012-10-01' ) # An overridden key. self.assertEqual(data['api_version'], '2012-10-01') # A key unique to the base. self.assertEqual(data['something-else'], 'another') # Ensure a key present in other variants is not there. self.assertTrue('Purpose' not in data) @mock.patch('os.pathsep', ';') def test_search_path_on_windows(self): # On windows, the search path is separated by ';' chars. self.environ['BOTO_DATA_PATH'] = 'c:\\path1;c:\\path2' # The builtin botocore data path is added as the last element # so we're only interested in checking the two that we've added. loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) paths = loader.get_search_paths()[:-1] self.assertEqual(paths, ['c:\\path1', 'c:\\path2'])
class LoaderTestCase(BaseEnvVar): def setUp(self): super(LoaderTestCase, self).setUp() self.data_path = os.path.join(os.path.dirname(__file__), 'data') self.environ['BOTO_DATA_PATH'] = self.data_path self.loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) # Make sure the cache is clear. self.loader._cache.clear() def test_data_path_not_required(self): loader = Loader() self.assertEqual(loader.data_path, '') loader.data_path = 'foo:bar' self.assertEqual(loader.data_path, 'foo:bar') def test_get_search_paths(self): paths = self.loader.get_search_paths() self.assertTrue(self.data_path in paths) def test_determine_latest_no_version(self): path = self.loader.determine_latest('someservice') self.assertEqual(path, os.path.join('someservice', '2013-08-21.api')) def test_determine_latest_with_version(self): path = self.loader.determine_latest('someservice', api_version='2012-10-01') self.assertEqual(path, os.path.join('someservice', '2012-10-01.api')) def test_determine_latest_with_version_the_wrong_way(self): with self.assertRaises(ApiVersionNotFoundError): self.loader.determine_latest('someservice/2012-10-01') def test_determine_latest_with_version_not_found(self): with self.assertRaises(ApiVersionNotFoundError): path = self.loader.determine_latest('someservice', api_version='2010-02-02') def test_load_data_plain_file(self): data = self.loader.load_data('foo') self.assertEqual(data['test_key_1'], 'test_value_1') def test_load_data_plain_file_nonexistant(self): with self.assertRaises(DataNotFoundError): data = self.loader.load_data('i_totally_dont_exist') def test_load_service_model_latest_without_version(self): data = self.loader.load_service_model('someservice') self.assertEqual(data['api_version'], '2013-08-21') def test_load_service_model_with_version(self): data = self.loader.load_service_model('someservice', api_version='2012-10-01') self.assertEqual(data['api_version'], '2012-10-01') def test_load_service_model_version_not_found(self): with self.assertRaises(ApiVersionNotFoundError): data = self.loader.load_service_model('someservice', api_version='2010-02-02') def test_load_service_model_data_path_order(self): # There's an s3/ directory both in our custom BOTO_DATA_PATH # directory as well as in the botocore/data/ directory. # Our path should win since the default built in path is always # last. data = self.loader.load_service_model('aws/s3') self.assertTrue( data.get('WAS_OVERRIDEN_VIA_DATA_PATH'), "S3 model was loaded from botocore's default " "data path instead of from the BOTO_DATA_PATH" " directory.") def test_list_available_services(self): avail = self.loader.list_available_services('') self.assertEqual(sorted(avail), [ 'aws', 'aws', 'someservice', 'sub', ]) aws_avail = self.loader.list_available_services('aws') self.assertTrue(len(aws_avail) > 10) self.assertTrue('ec2' in aws_avail) def test_load_data_overridden(self): self.overrides_path = os.path.join(os.path.dirname(__file__), 'data_overrides') self.environ['BOTO_DATA_PATH'] = "{0}{1}{2}".format( self.overrides_path, os.pathsep, self.data_path) loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) # This should load the data the first data it finds. data = loader.load_service_model('someservice', api_version='2012-10-01') # An overridden key. self.assertEqual(data['api_version'], '2012-10-01') # A key unique to the base. self.assertEqual(data['something-else'], 'another') # Ensure a key present in other variants is not there. self.assertTrue('Purpose' not in data) @mock.patch('os.pathsep', ';') def test_search_path_on_windows(self): # On windows, the search path is separated by ';' chars. self.environ['BOTO_DATA_PATH'] = 'c:\\path1;c:\\path2' # The builtin botocore data path is added as the last element # so we're only interested in checking the two that we've added. loader = Loader(data_path=self.environ['BOTO_DATA_PATH']) paths = loader.get_search_paths()[:-1] self.assertEqual(paths, ['c:\\path1', 'c:\\path2'])