desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test Equality of error returned'
def test_that_when_describing_api_deployment_that_does_not_exist_the_describe_api_deployment_method_returns_error(self):
self.conn.get_deployment.side_effect = ClientError(error_content, 'get_deployment') result = boto_apigateway.describe_api_deployment(restApiId='rm06h9oac4', deploymentId='n05smo', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_deployment'))
'Test True for value of \'set\''
def test_that_when_activating_api_deployment_for_stage_and_deployment_that_exist_the_activate_api_deployment_method_returns_true(self):
self.conn.update_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': 'n05smo', u'description': 'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': 'test', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.activate_api_deployment(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo', **conn_parameters) self.assertTrue(result.get('set'))
'Test False for value of \'set\''
def test_that_when_activating_api_deployment_for_stage_that_does_not_exist_the_activate_api_deployment_method_returns_false(self):
self.conn.update_stage.side_effect = ClientError(error_content, 'update_stage') result = boto_apigateway.activate_api_deployment(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo', **conn_parameters) self.assertFalse(result.get('set'))
'tests that we can successfully create an api deployment and the createDate is converted to string'
def test_that_when_creating_an_api_deployment_succeeds_the_create_api_deployment_method_returns_true(self):
now = datetime.datetime.now() self.conn.create_deployment.return_value = {u'description': u'test-lambda-api-key', u'id': 'n05smo', u'createdDate': now, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters) deployment = result.get('deployment') now_str = '{0}'.format(now) self.assertTrue(result.get('created')) self.assertEqual(deployment.get('createdDate'), now_str)
'tests that we properly handle errors when create an api deployment fails.'
def test_that_when_creating_an_deployment_fails_the_create_api_deployment_method_returns_error(self):
self.conn.create_deployment.side_effect = ClientError(error_content, 'create_deployment') result = boto_apigateway.create_api_deployment(restApiId='rm06h9oac4', stageName='test', **conn_parameters) self.assertIs(result.get('created'), False) self.assertEqual(result.get('error').get('message'), error_message.format('create_deployment'))
'test True if the api deployment is successfully deleted.'
def test_that_when_deleting_an_api_deployment_that_exists_the_delete_api_deployment_method_returns_true(self):
self.conn.delete_deployment.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.delete_api_deployment(restApiId='rm06h9oac4', deploymentId='n05smo', **conn_parameters) self.assertTrue(result.get('deleted'))
'Test that the given api deployment doesn\'t exists, and delete_api_deployment should return deleted status of False'
def test_that_when_deleting_an_api_deployment_that_does_not_exist_the_delete_api_deployment_method_returns_false(self):
self.conn.delete_deployment.side_effect = ClientError(error_content, 'delete_deployment') result = boto_apigateway.delete_api_deployment(restApiId='rm06h9oac4', deploymentId='n05smo1', **conn_parameters) self.assertFalse(result.get('deleted'))
'Test Equality for number of stages for the given deployment is 2'
def test_that_when_describing_api_stages_the_describe_api_stages_method_returns_list_of_stages(self):
self.conn.get_stages.return_value = {u'item': [{u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': u'test'}, {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 12, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'dev', u'lastUpdatedDate': datetime.datetime(2015, 12, 17, 16, 33, 50), u'stageName': u'dev'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.describe_api_stages(restApiId='rm06h9oac4', deploymentId='n05smo', **conn_parameters) self.assertEqual(len(result.get('stages', {})), 2)
'Test Equality of error returned'
def test_that_when_describing_api_stages_and_that_the_deployment_does_not_exist_the_describe_api_stages_method_returns_error(self):
self.conn.get_stages.side_effect = ClientError(error_content, 'get_stages') result = boto_apigateway.describe_api_stages(restApiId='rm06h9oac4', deploymentId='n05smo', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_stages'))
'Test True for the returned stage'
def test_that_when_describing_an_api_stage_the_describe_api_stage_method_returns_the_stage(self):
self.conn.get_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': u'test', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.describe_api_stage(restApiId='rm06h9oac4', stageName='test', **conn_parameters) self.assertTrue(result.get('stage'))
'Test Equality of error returned'
def test_that_when_describing_api_stage_that_does_not_exist_the_describe_api_stage_method_returns_error(self):
self.conn.get_stage.side_effect = ClientError(error_content, 'get_stage') result = boto_apigateway.describe_api_stage(restApiId='rm06h9oac4', stageName='no_such_stage', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_stage'))
'Test True for the returned stage'
def test_that_when_overwriting_stage_variables_to_an_existing_stage_the_overwrite_api_stage_variables_method_returns_the_updated_stage(self):
self.conn.get_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': u'test', u'variables': {'key1': 'val1'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} self.conn.update_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': u'test', u'variables': {'key1': 'val2'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.overwrite_api_stage_variables(restApiId='rm06h9oac4', stageName='test', variables=dict(key1='val2'), **conn_parameters) self.assertEqual(result.get('stage').get('variables').get('key1'), 'val2')
'Test Equality of error returned'
def test_that_when_overwriting_stage_variables_to_a_nonexisting_stage_the_overwrite_api_stage_variables_method_returns_error(self):
self.conn.get_stage.side_effect = ClientError(error_content, 'get_stage') result = boto_apigateway.overwrite_api_stage_variables(restApiId='rm06h9oac4', stageName='no_such_stage', variables=dict(key1='val1', key2='val2'), **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_stage'))
'Test Equality of error returned due to update_stage'
def test_that_when_overwriting_stage_variables_to_an_existing_stage_the_overwrite_api_stage_variables_method_returns_error(self):
self.conn.get_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': datetime.datetime(2015, 11, 17, 16, 33, 50), u'stageName': u'test', u'variables': {'key1': 'val1'}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} self.conn.update_stage.side_effect = ClientError(error_content, 'update_stage') result = boto_apigateway.overwrite_api_stage_variables(restApiId='rm06h9oac4', stageName='test', variables=dict(key1='val2'), **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('update_stage'))
'tests that we can successfully create an api stage and the createDate is converted to string'
def test_that_when_creating_an_api_stage_succeeds_the_create_api_stage_method_returns_true(self):
now = datetime.datetime.now() self.conn.create_stage.return_value = {u'cacheClusterEnabled': False, u'cacheClusterStatus': 'NOT_AVAILABLE', u'createdDate': now, u'deploymentId': u'n05smo', u'description': u'test', u'lastUpdatedDate': now, u'stageName': u'test', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.create_api_stage(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo', **conn_parameters) stage = result.get('stage') now_str = '{0}'.format(now) self.assertIs(result.get('created'), True) self.assertEqual(stage.get('createdDate'), now_str) self.assertEqual(stage.get('lastUpdatedDate'), now_str)
'tests that we properly handle errors when create an api stage fails.'
def test_that_when_creating_an_api_stage_fails_the_create_api_stage_method_returns_error(self):
self.conn.create_stage.side_effect = ClientError(error_content, 'create_stage') result = boto_apigateway.create_api_stage(restApiId='rm06h9oac4', stageName='test', deploymentId='n05smo', **conn_parameters) self.assertIs(result.get('created'), False) self.assertEqual(result.get('error').get('message'), error_message.format('create_stage'))
'test True if the api stage is successfully deleted.'
def test_that_when_deleting_an_api_stage_that_exists_the_delete_api_stage_method_returns_true(self):
self.conn.delete_stage.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.delete_api_stage(restApiId='rm06h9oac4', stageName='test', **conn_parameters) self.assertTrue(result.get('deleted'))
'Test that the given api stage doesn\'t exists, and delete_api_stage should return deleted status of False'
def test_that_when_deleting_an_api_stage_that_does_not_exist_the_delete_api_stage_method_returns_false(self):
self.conn.delete_stage.side_effect = ClientError(error_content, 'delete_stage') result = boto_apigateway.delete_api_stage(restApiId='rm06h9oac4', stageName='no_such_stage', **conn_parameters) self.assertFalse(result.get('deleted'))
'Test True for \'flushed\''
def test_that_when_flushing_api_stage_cache_for_an_existing_stage_the_flush_api_stage_cache_method_returns_true(self):
self.conn.flush_stage_cache.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.flush_api_stage_cache(restApiId='rm06h9oac4', stageName='no_such_stage', **conn_parameters) self.assertTrue(result.get('flushed'))
'Test False for \'flushed\''
def test_that_when_flushing_api_stage_cache_and_the_stage_does_not_exist_the_flush_api_stage_cache_method_returns_false(self):
self.conn.flush_stage_cache.side_effect = ClientError(error_content, 'flush_stage_cache') result = boto_apigateway.flush_api_stage_cache(restApiId='rm06h9oac4', stageName='no_such_stage', **conn_parameters) self.assertFalse(result.get('flushed'))
'Test Equality for number of models for the given api is 2'
def test_that_when_describing_api_models_the_describe_api_models_method_returns_list_of_models(self):
self.conn.get_models.return_value = {u'items': [{u'contentType': u'application/json', u'name': u'Error', u'description': u'Error Model', u'id': u'iltqcb', u'schema': u'{"properties":{"code":{"type":"integer","format":"int32"},"message":{"type":"string"},"fields":{"type":"string"}},"definitions":{}}'}, {u'contentType': u'application/json', u'name': u'User', u'description': u'User Model', u'id': u'iltqcc', u'schema': u'{"properties":{"username":{"type":"string","description":"A unique username for the user"},"password":{"type":"string","description":"A password for the new user"}},"definitions":{}}'}], 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.describe_api_models(restApiId='rm06h9oac4', **conn_parameters) self.assertEqual(len(result.get('models', {})), 2)
'Test Equality of error returned'
def test_that_when_describing_api_models_and_that_the_api_does_not_exist_the_describe_api_models_method_returns_error(self):
self.conn.get_models.side_effect = ClientError(error_content, 'get_models') result = boto_apigateway.describe_api_models(restApiId='rm06h9oac4', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_models'))
'Test True for the returned stage'
def test_that_when_describing_api_model_the_describe_api_model_method_returns_the_model(self):
self.conn.get_model.return_value = api_model_ret result = boto_apigateway.describe_api_model(restApiId='rm06h9oac4', modelName='Error', **conn_parameters) self.assertTrue(result.get('model'))
'Test Equality of error returned'
def test_that_when_describing_api_model_and_that_the_model_does_not_exist_the_describe_api_model_method_returns_error(self):
self.conn.get_model.side_effect = ClientError(error_content, 'get_model') result = boto_apigateway.describe_api_model(restApiId='rm06h9oac4', modelName='Error', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_model'))
'Tests True when model exists'
def test_that_model_exists_the_api_model_exists_method_returns_true(self):
self.conn.get_model.return_value = api_model_ret result = boto_apigateway.api_model_exists(restApiId='rm06h9oac4', modelName='Error', **conn_parameters) self.assertTrue(result.get('exists'))
'Tests False when model does not exist'
def test_that_model_does_not_exists_the_api_model_exists_method_returns_false(self):
self.conn.get_model.side_effect = ClientError(error_content, 'get_model') result = boto_apigateway.api_model_exists(restApiId='rm06h9oac4', modelName='Error', **conn_parameters) self.assertFalse(result.get('exists'))
'Tests True when model schema is updated.'
def test_that_updating_model_schema_the_update_api_model_schema_method_returns_true(self):
self.conn.update_model.return_value = api_model_ret result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='Error', schema=api_model_error_schema, **conn_parameters) self.assertTrue(result.get('updated'))
'Tests False when model schema is not upated.'
def test_that_updating_model_schema_when_model_does_not_exist_the_update_api_model_schema_emthod_returns_false(self):
self.conn.update_model.side_effect = ClientError(error_content, 'update_model') result = boto_apigateway.update_api_model_schema(restApiId='rm06h9oac4', modelName='no_such_model', schema=api_model_error_schema, **conn_parameters) self.assertFalse(result.get('updated'))
'tests that we can successfully create an api model'
def test_that_when_creating_an_api_model_succeeds_the_create_api_model_method_returns_true(self):
self.conn.create_model.return_value = api_model_ret result = boto_apigateway.create_api_model(restApiId='rm06h9oac4', modelName='Error', modelDescription='Error Model', schema=api_model_error_schema, **conn_parameters) self.assertTrue(result.get('created'))
'tests that we properly handle errors when create an api model fails.'
def test_that_when_creating_an_api_model_fails_the_create_api_model_method_returns_error(self):
self.conn.create_model.side_effect = ClientError(error_content, 'create_model') result = boto_apigateway.create_api_model(restApiId='rm06h9oac4', modelName='Error', modelDescription='Error Model', schema=api_model_error_schema, **conn_parameters) self.assertFalse(result.get('created'))
'test True if the api model is successfully deleted.'
def test_that_when_deleting_an_api_model_that_exists_the_delete_api_model_method_returns_true(self):
self.conn.delete_model.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.delete_api_model(restApiId='rm06h9oac4', modelName='Error', **conn_parameters) self.assertTrue(result.get('deleted'))
'Test that the given api model doesn\'t exists, and delete_api_model should return deleted status of False'
def test_that_when_deleting_an_api_model_that_does_not_exist_the_delete_api_model_method_returns_false(self):
self.conn.delete_model.side_effect = ClientError(error_content, 'delete_model') result = boto_apigateway.delete_api_model(restApiId='rm06h9oac4', modelName='no_such_model', **conn_parameters) self.assertFalse(result.get('deleted'))
'Test Equality for number of resources for the given api is 3'
def test_that_when_describing_api_resources_the_describe_api_resources_method_returns_list_of_3_resources(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_resources(restApiId='rm06h9oac4', **conn_parameters) self.assertEqual(len(result.get('resources')), len(api_resources_ret.get('items')))
'Test Equality of error returned'
def test_that_when_describing_api_resources_and_that_the_api_does_not_exist_the_describe_api_resources_method_returns_error(self):
self.conn.get_resources.side_effect = ClientError(error_content, 'get_resources') result = boto_apigateway.describe_api_resources(restApiId='rm06h9oac4', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_resources'))
'Test Equality of the resource path returned is /api'
def test_that_when_describing_an_api_resource_that_exists_the_describe_api_resource_method_returns_the_resource(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_resource(restApiId='rm06h9oac4', path='/api', **conn_parameters) self.assertEqual(result.get('resource', {}).get('path'), '/api')
'Test Equality of the \'resource\' is None'
def test_that_when_describing_an_api_resource_that_does_not_exist_the_describe_api_resource_method_returns_the_resource_as_none(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_resource(restApiId='rm06h9oac4', path='/path/does/not/exist', **conn_parameters) self.assertEqual(result.get('resource'), None)
'Test Equality of error returned'
def test_that_when_describing_an_api_resource_and_that_the_api_does_not_exist_the_describe_api_resource_method_returns_error(self):
self.conn.get_resources.side_effect = ClientError(error_content, 'get_resources') result = boto_apigateway.describe_api_resource(restApiId='bad_id', path='/api', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_resources'))
'Tests that a path of \'/api3\' returns 2 resources, named \'/\' and \'/api\'.'
def test_that_when_creating_api_resources_for_a_path_that_creates_one_new_resource_the_create_resources_api_method_returns_all_resources(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.create_resource.return_value = api_create_resource_ret result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api3', **conn_parameters) resources = result.get('resources') self.assertIs(result.get('created'), True) self.assertEqual(len(resources), 2) self.assertEqual(resources[0].get('path'), '/') self.assertEqual(resources[1].get('path'), '/api3')
'Tests that a path of \'/api/users\' as defined in api_resources_ret return resources named \'/\', \'/api\', and \'/api/users\''
def test_that_when_creating_api_resources_for_a_path_whose_resources_exist_the_create_resources_api_method_returns_all_resources(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api/users', **conn_parameters) resources = result.get('resources') self.assertIs(result.get('created'), True) self.assertEqual(len(resources), len(api_resources_ret.get('items'))) self.assertEqual(resources[0].get('path'), '/') self.assertEqual(resources[1].get('path'), '/api') self.assertEqual(resources[2].get('path'), '/api/users')
'Tests False if we failed to create a resource'
def test_that_when_creating_api_resource_fails_the_create_resources_api_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.create_resource.side_effect = ClientError(error_content, 'create_resource') result = boto_apigateway.create_api_resources(restApiId='rm06h9oac4', path='/api4', **conn_parameters) self.assertFalse(result.get('created'))
'Tests True for \'/api\''
def test_that_when_deleting_api_resources_for_a_resource_that_exists_the_delete_api_resources_method_returns_true(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.delete_api_resources(restApiId='rm06h9oac4', path='/api', **conn_parameters) self.assertTrue(result.get('deleted'))
'Tests False for \'/api5\''
def test_that_when_deleting_api_resources_for_a_resource_that_does_not_exist_the_delete_api_resources_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.delete_api_resources(restApiId='rm06h9oac4', path='/api5', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests False for \'/\''
def test_that_when_deleting_the_root_api_resource_the_delete_api_resources_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.delete_api_resources(restApiId='rm06h9oac4', path='/', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests False delete_resource side side_effect'
def test_that_when_deleting_api_resources_and_delete_resource_throws_error_the_delete_api_resources_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.delete_resource.side_effect = ClientError(error_content, 'delete_resource') result = boto_apigateway.delete_api_resources(restApiId='rm06h9oac4', path='/api', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests True for \'/api/users\' and POST'
def test_that_when_describing_an_api_resource_method_that_exists_the_describe_api_resource_method_returns_the_method(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_method.return_value = {u'httpMethod': 'POST', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.describe_api_resource_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', **conn_parameters) self.assertTrue(result.get('method'))
'Tests Equality of returned error for \'/api/users\' and PUT'
def test_that_when_describing_an_api_resource_method_whose_method_does_not_exist_the_describe_api_resource_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_method.side_effect = ClientError(error_content, 'get_method') result = boto_apigateway.describe_api_resource_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='PUT', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_method'))
'Tests True for resource not found error for \'/does/not/exist\' and POST'
def test_that_when_describing_an_api_resource_method_whose_resource_does_not_exist_the_describe_api_resrouce_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_resource_method(restApiId='rm06h9oac4', resourcePath='/does/not/exist', httpMethod='POST', **conn_parameters) self.assertTrue(result.get('error'))
'Tests True on \'created\' for \'/api/users\' and \'GET\''
def test_that_when_creating_an_api_method_the_create_api_method_method_returns_true(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.put_method.return_value = {u'httpMethod': 'GET', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.create_api_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='GET', authorizationType='NONE', **conn_parameters) self.assertTrue(result.get('created'))
'Tests False on \'created\' for \'/api5\', and \'GET\''
def test_that_when_creating_an_api_method_and_resource_does_not_exist_the_create_api_method_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.create_api_method(restApiId='rm06h9oac4', resourcePath='/api5', httpMethod='GET', authorizationType='NONE', **conn_parameters) self.assertFalse(result.get('created'))
'Tests False on \'created\' for \'/api/users\' and \'GET\''
def test_that_when_creating_an_api_method_and_error_thrown_on_put_method_the_create_api_method_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.put_method.side_effect = ClientError(error_content, 'put_method') result = boto_apigateway.create_api_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='GET', authorizationType='NONE', **conn_parameters) self.assertFalse(result.get('created'))
'Tests True for \'/api/users\' and \'POST\''
def test_that_when_deleting_an_api_method_for_a_method_that_exist_the_delete_api_method_method_returns_true(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.delete_method.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.delete_api_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', **conn_parameters) self.assertTrue(result.get('deleted'))
'Tests False for \'/api/users\' and \'GET\''
def test_that_when_deleting_an_api_method_for_a_method_that_does_not_exist_the_delete_api_method_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.delete_method.side_effect = ClientError(error_content, 'delete_method') result = boto_apigateway.delete_api_method(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='GET', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests False for \'/api/users5\' and \'POST\''
def test_that_when_deleting_an_api_method_for_a_resource_that_does_not_exist_the_delete_api_method_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.delete_api_method(restApiId='rm06h9oac4', resourcePath='/api/users5', httpMethod='POST', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests True for \'response\' for \'/api/users\', \'POST\', and 200'
def test_that_when_describing_an_api_method_response_that_exists_the_describe_api_method_respond_method_returns_the_response(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_method_response.return_value = {u'statusCode': 200, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.describe_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode=200, **conn_parameters) self.assertTrue(result.get('response'))
'Tests Equality of error msg thrown from get_method_response for \'/api/users\', \'POST\', and 250'
def test_that_when_describing_an_api_method_response_and_response_code_does_not_exist_the_describe_api_method_response_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_method_response.side_effect = ClientError(error_content, 'get_method_response') result = boto_apigateway.describe_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode=250, **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_method_response'))
'Tests True for existence of \'error\' for \'/api5/users\', \'POST\', and 200'
def test_that_when_describing_an_api_method_response_and_resource_does_not_exist_the_describe_api_method_response_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_method_response(restApiId='rm06h9oac4', resourcePath='/api5/users', httpMethod='POST', statusCode=200, **conn_parameters) self.assertTrue(result.get('error'))
'Tests True on \'created\' for \'/api/users\', \'POST\', 201'
def test_that_when_creating_an_api_method_response_the_create_api_method_response_method_returns_true(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.put_method_response.return_value = {u'statusCode': '201', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.create_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode='201', **conn_parameters) self.assertTrue(result.get('created'))
'Tests False on \'created\' for \'/api5\', \'POST\', 200'
def test_that_when_creating_an_api_method_response_and_resource_does_not_exist_the_create_api_method_response_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.create_api_method_response(restApiId='rm06h9oac4', resourcePath='/api5', httpMethod='POST', statusCode='200', **conn_parameters) self.assertFalse(result.get('created'))
'Tests False on \'created\' for \'/api/users\', \'POST\', 200'
def test_that_when_creating_an_api_method_response_and_error_thrown_on_put_method_response_the_create_api_method_response_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.put_method_response.side_effect = ClientError(error_content, 'put_method_response') result = boto_apigateway.create_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode='200', **conn_parameters) self.assertFalse(result.get('created'))
'Tests True for \'/api/users\', \'POST\', 200'
def test_that_when_deleting_an_api_method_response_for_a_response_that_exist_the_delete_api_method_response_method_returns_true(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.delete_method_response.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '2d31072c-9d15-11e5-9977-6d9fcfda9c0a'}} result = boto_apigateway.delete_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode='200', **conn_parameters) self.assertTrue(result.get('deleted'))
'Tests False for \'/api/users\', \'POST\', 201'
def test_that_when_deleting_an_api_method_response_for_a_response_that_does_not_exist_the_delete_api_method_response_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.delete_method_response.side_effect = ClientError(error_content, 'delete_method_response') result = boto_apigateway.delete_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='GET', statusCode='201', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests False for \'/api/users5\', \'POST\', 200'
def test_that_when_deleting_an_api_method_response_for_a_resource_that_does_not_exist_the_delete_api_method_response_method_returns_false(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.delete_api_method_response(restApiId='rm06h9oac4', resourcePath='/api/users5', httpMethod='POST', statusCode='200', **conn_parameters) self.assertFalse(result.get('deleted'))
'Tests True for \'integration\' for \'/api/users\', \'POST\''
def test_that_when_describing_an_api_integration_that_exists_the_describe_api_integration_method_returns_the_intgration(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_integration.return_value = {u'type': 'AWS', u'uri': 'arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:1234568992820:function:echo_event/invocations', u'credentials': 'testing', u'httpMethod': 'POST', u'intgrationResponses': {'200': {}}, u'requestTemplates': {'application/json': {}}, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.describe_api_integration(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', **conn_parameters) self.assertTrue(result.get('integration'))
'Tests Equality of error msg thrown from get_method_response for \'/api/users\', \'GET\''
def test_that_when_describing_an_api_integration_and_method_does_not_have_integration_defined_the_describe_api_integration_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_integration.side_effect = ClientError(error_content, 'get_integration') result = boto_apigateway.describe_api_integration(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='GET', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_integration'))
'Tests True for existence of \'error\' for \'/api5/users\', \'POST\''
def test_that_when_describing_an_api_integration_and_resource_does_not_exist_the_describe_api_integration_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_integration(restApiId='rm06h9oac4', resourcePath='/api5/users', httpMethod='POST', **conn_parameters) self.assertTrue(result.get('error'))
'Tests True for \'response\' for \'/api/users\', \'POST\', 200'
def test_that_when_describing_an_api_integration_response_that_exists_the_describe_api_integration_response_method_returns_the_intgration(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_integration_response.return_value = {u'responseParameters': {}, u'statusCode': 200, 'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': '7cc233dd-9dc8-11e5-ba47-1b7350cc2757'}} result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode='200', **conn_parameters) self.assertTrue(result.get('response'))
'Tests Equality of error msg thrown from get_method_response for \'/api/users\', \'POST\', 201'
def test_that_when_describing_an_api_integration_response_and_status_code_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret self.conn.get_integration_response.side_effect = ClientError(error_content, 'get_integration_response') result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4', resourcePath='/api/users', httpMethod='POST', statusCode='201', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_integration_response'))
'Tests True for existence of \'error\' for \'/api5/users\', \'POST\', 200'
def test_that_when_describing_an_api_integration_response_and_resource_does_not_exist_the_describe_api_integration_response_method_returns_error(self):
self.conn.get_resources.return_value = api_resources_ret result = boto_apigateway.describe_api_integration_response(restApiId='rm06h9oac4', resourcePath='/api5/users', httpMethod='POST', statusCode='200', **conn_parameters) self.assertTrue(result.get('error'))
'Tests True for existence of \'error\''
def test_that_when_describing_usage_plans_and_an_exception_is_thrown_in_get_usage_plans(self):
self.conn.get_usage_plans.side_effect = ClientError(error_content, 'get_usage_plans_exception') result = boto_apigateway.describe_usage_plans(name='some plan', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('get_usage_plans_exception'))
'Tests for plans equaling empty list'
def test_that_when_describing_usage_plans_and_plan_name_or_id_does_not_exist_that_results_have_empty_plans_list(self):
self.conn.get_usage_plans.return_value = usage_plans_ret result = boto_apigateway.describe_usage_plans(name='does not exist', **conn_parameters) self.assertEqual(result.get('plans'), []) result = boto_apigateway.describe_usage_plans(plan_id='does not exist', **conn_parameters) self.assertEqual(result.get('plans'), []) result = boto_apigateway.describe_usage_plans(name='does not exist', plan_id='does not exist', **conn_parameters) self.assertEqual(result.get('plans'), []) result = boto_apigateway.describe_usage_plans(name='plan1_name', plan_id='does not exist', **conn_parameters) self.assertEqual(result.get('plans'), []) result = boto_apigateway.describe_usage_plans(name='does not exist', plan_id='plan1_id', **conn_parameters) self.assertEqual(result.get('plans'), [])
'Tests for plans filtering properly if they exist'
def test_that_when_describing_usage_plans_for_plans_that_exist_that_the_function_returns_all_matching_plans(self):
self.conn.get_usage_plans.return_value = usage_plans_ret result = boto_apigateway.describe_usage_plans(name=usage_plan1['name'], **conn_parameters) self.assertEqual(len(result.get('plans')), 2) for plan in result['plans']: self.assertTrue((plan in [usage_plan1, usage_plan1b]))
'Tests for TypeError and ValueError in throttle and quota'
def test_that_when_creating_or_updating_a_usage_plan_and_throttle_or_quota_failed_to_validate_that_an_error_is_returned(self):
for (throttle, quota) in (([], None), (None, []), ('abc', None), (None, 'def')): res = boto_apigateway.create_usage_plan('plan1_name', description=None, throttle=throttle, quota=quota, **conn_parameters) self.assertNotEqual(None, res.get('error')) res = boto_apigateway.update_usage_plan('plan1_id', throttle=throttle, quota=quota, **conn_parameters) self.assertNotEqual(None, res.get('error')) for quota in ({'limit': 123}, {'period': 123}, {'period': 'DAY'}): res = boto_apigateway.create_usage_plan('plan1_name', description=None, throttle=None, quota=quota, **conn_parameters) self.assertNotEqual(None, res.get('error')) res = boto_apigateway.update_usage_plan('plan1_id', quota=quota, **conn_parameters) self.assertNotEqual(None, res.get('error')) self.assertTrue((self.conn.get_usage_plans.call_count == 0)) self.assertTrue((self.conn.create_usage_plan.call_count == 0)) self.assertTrue((self.conn.update_usage_plan.call_count == 0))
'tests for ClientError'
def test_that_when_creating_a_usage_plan_and_create_usage_plan_throws_an_exception_that_an_error_is_returned(self):
self.conn.create_usage_plan.side_effect = ClientError(error_content, 'create_usage_plan_exception') result = boto_apigateway.create_usage_plan(name='some plan', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('create_usage_plan_exception'))
'tests for success user plan creation'
def test_that_create_usage_plan_succeeds(self):
res = 'unit test create_usage_plan succeeded' self.conn.create_usage_plan.return_value = res result = boto_apigateway.create_usage_plan(name='some plan', **conn_parameters) self.assertEqual(result.get('created'), True) self.assertEqual(result.get('result'), res)
'tests for ClientError'
def test_that_when_udpating_a_usage_plan_and_update_usage_plan_throws_an_exception_that_an_error_is_returned(self):
self.conn.update_usage_plan.side_effect = ClientError(error_content, 'update_usage_plan_exception') result = boto_apigateway.update_usage_plan(plan_id='plan1_id', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format('update_usage_plan_exception'))
'tests for throttle and quota removal'
def test_that_when_updating_a_usage_plan_and_if_throttle_and_quota_parameters_are_none_update_usage_plan_removes_throttle_and_quota(self):
ret = 'some success status' self.conn.update_usage_plan.return_value = ret result = boto_apigateway.update_usage_plan(plan_id='plan1_id', throttle=None, quota=None, **conn_parameters) self.assertEqual(result.get('updated'), True) self.assertEqual(result.get('result'), ret) self.assertTrue((self.conn.update_usage_plan.call_count >= 1))
'tests for error in describe_usage_plans returns error'
def test_that_when_deleting_usage_plan_and_describe_usage_plans_had_error_that_the_same_error_is_returned(self):
ret = 'get_usage_plans_exception' self.conn.get_usage_plans.side_effect = ClientError(error_content, ret) result = boto_apigateway.delete_usage_plan(plan_id='some plan id', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format(ret)) self.assertTrue((self.conn.delete_usage_plan.call_count == 0))
'tests for ClientError'
def test_that_when_deleting_usage_plan_and_plan_does_not_exist_that_the_functions_returns_deleted_true(self):
self.conn.get_usage_plans.return_value = dict(items=[]) ret = 'delete_usage_plan_retval' self.conn.delete_usage_plan.return_value = ret result = boto_apigateway.delete_usage_plan(plan_id='plan1_id', **conn_parameters) self.assertEqual(result.get('deleted'), True) self.assertEqual(result.get('usagePlanId'), 'plan1_id') self.assertTrue((self.conn.delete_usage_plan.call_count == 0))
'tests for ClientError'
def test_that_when_deleting_usage_plan_and_delete_usage_plan_throws_exception_that_an_error_is_returned(self):
self.conn.get_usage_plans.return_value = usage_plans_ret error_msg = 'delete_usage_plan_exception' self.conn.delete_usage_plan.side_effect = ClientError(error_content, error_msg) result = boto_apigateway.delete_usage_plan(plan_id='plan1_id', **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format(error_msg)) self.assertTrue((self.conn.delete_usage_plan.call_count >= 1))
'tests for border cases when apis is empty list'
def test_that_attach_or_detach_usage_plan_when_apis_is_empty_that_success_is_returned(self):
result = boto_apigateway.attach_usage_plan_to_apis(plan_id='plan1_id', apis=[], **conn_parameters) self.assertEqual(result.get('success'), True) self.assertEqual(result.get('result', 'no result?'), None) self.assertTrue((self.conn.update_usage_plan.call_count == 0)) result = boto_apigateway.detach_usage_plan_from_apis(plan_id='plan1_id', apis=[], **conn_parameters) self.assertEqual(result.get('success'), True) self.assertEqual(result.get('result', 'no result?'), None) self.assertTrue((self.conn.update_usage_plan.call_count == 0))
'tests for invalid key in api object'
def test_that_attach_or_detach_usage_plan_when_api_does_not_contain_apiId_or_stage_that_an_error_is_returned(self):
for api in ({'apiId': 'some Id'}, {'stage': 'some stage'}, {}): result = boto_apigateway.attach_usage_plan_to_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertNotEqual(result.get('error'), None) result = boto_apigateway.detach_usage_plan_from_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertNotEqual(result.get('error'), None) self.assertTrue((self.conn.update_usage_plan.call_count == 0))
'tests for ClientError'
def test_that_attach_or_detach_usage_plan_and_update_usage_plan_throws_exception_that_an_error_is_returned(self):
api = {'apiId': 'some_id', 'stage': 'some_stage'} error_msg = 'update_usage_plan_exception' self.conn.update_usage_plan.side_effect = ClientError(error_content, error_msg) result = boto_apigateway.attach_usage_plan_to_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format(error_msg)) result = boto_apigateway.detach_usage_plan_from_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertEqual(result.get('error').get('message'), error_message.format(error_msg))
'tests for update_usage_plan called'
def test_that_attach_or_detach_usage_plan_updated_successfully(self):
api = {'apiId': 'some_id', 'stage': 'some_stage'} attach_ret = 'update_usage_plan_add_op_succeeded' detach_ret = 'update_usage_plan_remove_op_succeeded' self.conn.update_usage_plan.side_effect = [attach_ret, detach_ret] result = boto_apigateway.attach_usage_plan_to_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertEqual(result.get('success'), True) self.assertEqual(result.get('result'), attach_ret) result = boto_apigateway.detach_usage_plan_from_apis(plan_id='plan1_id', apis=[api], **conn_parameters) self.assertEqual(result.get('success'), True) self.assertEqual(result.get('result'), detach_ret)
'Test for A test to ensure the GNOME module is loaded'
def test_ping(self):
self.assertTrue(gnomedesktop.ping())
'Test for Return the current idle delay setting in seconds'
def test_getidledelay(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.getIdleDelay())
'Test for Set the current idle delay setting in seconds'
def test_setidledelay(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_set', return_value=True): self.assertTrue(gnomedesktop.setIdleDelay(5))
'Test for Return the current clock format, either 12h or 24h format.'
def test_getclockformat(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.getClockFormat())
'Test for Set the clock format, either 12h or 24h format..'
def test_setclockformat(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_set', return_value=True): self.assertTrue(gnomedesktop.setClockFormat('12h')) self.assertFalse(gnomedesktop.setClockFormat('a'))
'Test for Return the current setting, if the date is shown in the clock'
def test_getclockshowdate(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.getClockShowDate())
'Test for Set whether the date is visible in the clock'
def test_setclockshowdate(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: self.assertFalse(gnomedesktop.setClockShowDate('kvalue')) with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.setClockShowDate(True))
'Test for Get whether the idle activation is enabled'
def test_getidleactivation(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.getIdleActivation())
'Test for Set whether the idle activation is enabled'
def test_setidleactivation(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: self.assertFalse(gnomedesktop.setIdleActivation('kvalue')) with patch.object(gsettings_mock, '_set', return_value=True): self.assertTrue(gnomedesktop.setIdleActivation(True))
'Test for Get key in a particular GNOME schema'
def test_get(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.get())
'Test for Set key in a particular GNOME schema.'
def test_set_(self):
with patch('salt.modules.gnomedesktop._GSettings') as gsettings_mock: with patch.object(gsettings_mock, '_get', return_value=True): self.assertTrue(gnomedesktop.set_())
'Test if it returns the info of udev-created node in a dict'
def test_info(self):
cmd_out = {'retcode': 0, 'stdout': 'P: /devices/virtual/vc/vcsa7\nN: vcsa7\nE: DEVNAME=/dev/vcsa7\nE: DEVPATH=/devices/virtual/vc/vcsa7\nE: MAJOR=7\nE: MINOR=135\nE: SUBSYSTEM=vc\n\n', 'stderr': ''} ret = {'E': {'DEVNAME': '/dev/vcsa7', 'DEVPATH': '/devices/virtual/vc/vcsa7', 'MAJOR': 7, 'MINOR': 135, 'SUBSYSTEM': 'vc'}, 'N': 'vcsa7', 'P': '/devices/virtual/vc/vcsa7'} mock = MagicMock(return_value=cmd_out) with patch.dict(udev.__salt__, {'cmd.run_all': mock}): data = udev.info('/dev/vcsa7') assert (ret['P'] == data['P']) assert (ret.get('N') == data.get('N')) for (key, value) in data['E'].items(): assert (ret['E'][key] == value)
'Test if it returns the all the udev database into a dict'
def test_exportdb(self):
udev_data = '\nP: /devices/LNXSYSTM:00/LNXPWRBN:00\nE: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00\nE: DRIVER=button\nE: MODALIAS=acpi:LNXPWRBN:\nE: SUBSYSTEM=acpi\n\nP: /devices/LNXSYSTM:00/LNXPWRBN:00/input/input2\nE: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2\nE: EV=3\nE: ID_FOR_SEAT=input-acpi-LNXPWRBN_00\nE: ID_INPUT=1\nE: ID_INPUT_KEY=1\nE: ID_PATH=acpi-LNXPWRBN:00\nE: ID_PATH_TAG=acpi-LNXPWRBN_00\nE: KEY=10000000000000 0\nE: MODALIAS=input:b0019v0000p0001e0000-e0,1,k74,ramlsfw\nE: NAME="Power Button"\nE: PHYS="LNXPWRBN/button/input0"\nE: PRODUCT=19/0/1/0\nE: PROP=0\nE: SUBSYSTEM=input\nE: TAGS=:seat:\nE: USEC_INITIALIZED=2010022\n\nP: /devices/LNXSYSTM:00/LNXPWRBN:00/input/input2/event2\nN: input/event2\nE: BACKSPACE=guess\nE: DEVNAME=/dev/input/event2\nE: DEVPATH=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2/event2\nE: ID_INPUT=1\nE: ID_INPUT_KEY=1\nE: ID_PATH=acpi-LNXPWRBN:00\nE: ID_PATH_TAG=acpi-LNXPWRBN_00\nE: MAJOR=13\nE: MINOR=66\nE: SUBSYSTEM=input\nE: TAGS=:power-switch:\nE: USEC_INITIALIZED=2076101\nE: XKBLAYOUT=us\nE: XKBMODEL=pc105\n ' out = [{'P': '/devices/LNXSYSTM:00/LNXPWRBN:00', 'E': {'MODALIAS': 'acpi:LNXPWRBN:', 'SUBSYSTEM': 'acpi', 'DRIVER': 'button', 'DEVPATH': '/devices/LNXSYSTM:00/LNXPWRBN:00'}}, {'P': '/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2', 'E': {'SUBSYSTEM': 'input', 'PRODUCT': '19/0/1/0', 'PHYS': '"LNXPWRBN/button/input0"', 'NAME': '"Power Button"', 'ID_INPUT': 1, 'DEVPATH': '/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2', 'MODALIAS': 'input:b0019v0000p0001e0000-e0,1,k74,ramlsfw', 'ID_PATH_TAG': 'acpi-LNXPWRBN_00', 'TAGS': ':seat:', 'PROP': 0, 'ID_FOR_SEAT': 'input-acpi-LNXPWRBN_00', 'KEY': '10000000000000 0', 'USEC_INITIALIZED': 2010022, 'ID_PATH': 'acpi-LNXPWRBN:00', 'EV': 3, 'ID_INPUT_KEY': 1}}, {'P': '/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2/event2', 'E': {'SUBSYSTEM': 'input', 'XKBLAYOUT': 'us', 'MAJOR': 13, 'ID_INPUT': 1, 'DEVPATH': '/devices/LNXSYSTM:00/LNXPWRBN:00/input/input2/event2', 'ID_PATH_TAG': 'acpi-LNXPWRBN_00', 'DEVNAME': '/dev/input/event2', 'TAGS': ':power-switch:', 'BACKSPACE': 'guess', 'MINOR': 66, 'USEC_INITIALIZED': 2076101, 'ID_PATH': 'acpi-LNXPWRBN:00', 'XKBMODEL': 'pc105', 'ID_INPUT_KEY': 1}, 'N': 'input/event2'}] mock = MagicMock(return_value={'retcode': 0, 'stdout': udev_data}) with patch.dict(udev.__salt__, {'cmd.run_all': mock}): data = udev.exportdb() assert (data == [x for x in data if x]) for (d_idx, d_section) in enumerate(data): assert (out[d_idx]['P'] == d_section['P']) assert (out[d_idx].get('N') == d_section.get('N')) for (key, value) in d_section['E'].items(): assert (out[d_idx]['E'][key] == value)
'Test if udevdb._normalize_info does not returns nested lists that contains only one item. :return:'
def test_normalize_info(self):
data = {'key': ['value', 'here'], 'foo': ['bar'], 'some': 'data'} assert (udev._normalize_info(data) == {'foo': 'bar', 'some': 'data', 'key': ['value', 'here']})
'Tests the return of get function'
def test_get(self):
mock_cmd = MagicMock(return_value='foo') with patch.dict(mac_sysctl.__salt__, {'cmd.run': mock_cmd}): self.assertEqual(mac_sysctl.get('kern.ostype'), 'foo')
'Tests if the assignment was successful or not'
def test_assign_cmd_failed(self):
cmd = {'pid': 3548, 'retcode': 1, 'stderr': '', 'stdout': 'net.inet.icmp.icmplim: 250 -> 50'} mock_cmd = MagicMock(return_value=cmd) with patch.dict(mac_sysctl.__salt__, {'cmd.run_all': mock_cmd}): self.assertRaises(CommandExecutionError, mac_sysctl.assign, 'net.inet.icmp.icmplim', 50)
'Tests the return of successful assign function'
def test_assign(self):
cmd = {'pid': 3548, 'retcode': 0, 'stderr': '', 'stdout': 'net.inet.icmp.icmplim: 250 -> 50'} ret = {'net.inet.icmp.icmplim': '50'} mock_cmd = MagicMock(return_value=cmd) with patch.dict(mac_sysctl.__salt__, {'cmd.run_all': mock_cmd}): self.assertEqual(mac_sysctl.assign('net.inet.icmp.icmplim', 50), ret)