desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test to make sure that we correctly set the proxy info on Windows'
def test_set_http_proxy_windows(self):
with patch.dict(proxy.__grains__, {'os': 'Windows'}): mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_http_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com']) calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'http=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com')] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
'Test to make sure that we correctly set the proxy info on Windows'
def test_set_https_proxy_windows(self):
with patch.dict(proxy.__grains__, {'os': 'Windows'}): mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_https_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com']) calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'https=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com')] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
'Test to make sure that we correctly set the proxy info on Windows'
def test_set_ftp_proxy_windows(self):
with patch.dict(proxy.__grains__, {'os': 'Windows'}): mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_ftp_proxy('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com']) calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'ftp=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com')] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
'Test to make sure that we correctly set the proxy info on Windows'
def test_set_proxy_windows(self):
with patch.dict(proxy.__grains__, {'os': 'Windows'}): mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_proxy_win('192.168.0.1', 3128, bypass_hosts=['.moo.com', '.salt.com']) calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'http=192.168.0.1:3128;https=192.168.0.1:3128;ftp=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com')] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
'Test to make sure that we correctly set the proxy info on Windows'
def test_set_proxy_windows_no_ftp(self):
with patch.dict(proxy.__grains__, {'os': 'Windows'}): mock_reg = MagicMock() mock_cmd = MagicMock() with patch.dict(proxy.__salt__, {'reg.set_value': mock_reg, 'cmd.run': mock_cmd}): out = proxy.set_proxy_win('192.168.0.1', 3128, types=['http', 'https'], bypass_hosts=['.moo.com', '.salt.com']) calls = [call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyServer', 'http=192.168.0.1:3128;https=192.168.0.1:3128;'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyEnable', 1, vtype='REG_DWORD'), call('HKEY_CURRENT_USER', 'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings', 'ProxyOverride', '<local>;.moo.com;.salt.com')] mock_reg.assert_has_calls(calls) mock_cmd.assert_called_once_with('netsh winhttp import proxy source=ie') self.assertTrue(out)
'Test if it runs one or more named munin plugins'
def test_run(self):
mock = MagicMock(return_value='uptime.value 0.01') with patch.dict(munin.__salt__, {'cmd.run': mock}): with patch('salt.modules.munin.list_plugins', MagicMock(return_value=['uptime'])): self.assertDictEqual(munin.run('uptime'), {'uptime': {'uptime': 0.01}})
'Test if it runs all the munin plugins'
def test_run_all(self):
mock = MagicMock(return_value='uptime.value 0.01') with patch.dict(munin.__salt__, {'cmd.run': mock}): with patch('salt.modules.munin.list_plugins', MagicMock(return_value=['uptime'])): self.assertDictEqual(munin.run_all(), {'uptime': {'uptime': 0.01}})
'Test if it list all the munin plugins'
def test_list_plugins(self):
with patch('salt.modules.munin.list_plugins', MagicMock(return_value=['uptime'])): self.assertListEqual(munin.list_plugins(), ['uptime'])
'Tests checking lambda function existence when the lambda function already exists'
def test_that_when_checking_if_a_function_exists_and_a_function_exists_the_function_exists_method_returns_true(self):
self.conn.list_functions.return_value = {'Functions': [function_ret]} func_exists_result = boto_lambda.function_exists(FunctionName=function_ret['FunctionName'], **conn_parameters) self.assertTrue(func_exists_result['exists'])
'Tests checking lambda function existence when the lambda function does not exist'
def test_that_when_checking_if_a_function_exists_and_a_function_does_not_exist_the_function_exists_method_returns_false(self):
self.conn.list_functions.return_value = {'Functions': [function_ret]} func_exists_result = boto_lambda.function_exists(FunctionName='myfunc', **conn_parameters) self.assertFalse(func_exists_result['exists'])
'Tests checking lambda function existence when boto returns an error'
def test_that_when_checking_if_a_function_exists_and_boto3_returns_an_error_the_function_exists_method_returns_error(self):
self.conn.list_functions.side_effect = ClientError(error_content, 'list_functions') func_exists_result = boto_lambda.function_exists(FunctionName='myfunc', **conn_parameters) self.assertEqual(func_exists_result.get('error', {}).get('message'), error_message.format('list_functions'))
'tests True function created.'
def test_that_when_creating_a_function_from_zipfile_succeeds_the_create_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): with TempZipFile() as zipfile: self.conn.create_function.return_value = function_ret lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction', Runtime='python2.7', Role='myrole', Handler='file.method', ZipFile=zipfile, **conn_parameters) self.assertTrue(lambda_creation_result['created'])
'tests True function created.'
def test_that_when_creating_a_function_from_s3_succeeds_the_create_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.create_function.return_value = function_ret lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction', Runtime='python2.7', Role='myrole', Handler='file.method', S3Bucket='bucket', S3Key='key', **conn_parameters) self.assertTrue(lambda_creation_result['created'])
'tests Creating a function without code'
def test_that_when_creating_a_function_without_code_raises_a_salt_invocation_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): with self.assertRaisesRegex(SaltInvocationError, 'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.'): lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction', Runtime='python2.7', Role='myrole', Handler='file.method', **conn_parameters)
'tests Creating a function without code'
def test_that_when_creating_a_function_with_zipfile_and_s3_raises_a_salt_invocation_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): with self.assertRaisesRegex(SaltInvocationError, 'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.'): with TempZipFile() as zipfile: lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction', Runtime='python2.7', Role='myrole', Handler='file.method', ZipFile=zipfile, S3Bucket='bucket', S3Key='key', **conn_parameters)
'tests False function not created.'
def test_that_when_creating_a_function_fails_the_create_function_method_returns_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.create_function.side_effect = ClientError(error_content, 'create_function') with TempZipFile() as zipfile: lambda_creation_result = boto_lambda.create_function(FunctionName='testfunction', Runtime='python2.7', Role='myrole', Handler='file.method', ZipFile=zipfile, **conn_parameters) self.assertEqual(lambda_creation_result.get('error', {}).get('message'), error_message.format('create_function'))
'tests True function deleted.'
def test_that_when_deleting_a_function_succeeds_the_delete_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): result = boto_lambda.delete_function(FunctionName='testfunction', Qualifier=1, **conn_parameters) self.assertTrue(result['deleted'])
'tests False function not deleted.'
def test_that_when_deleting_a_function_fails_the_delete_function_method_returns_false(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.delete_function.side_effect = ClientError(error_content, 'delete_function') result = boto_lambda.delete_function(FunctionName='testfunction', **conn_parameters) self.assertFalse(result['deleted'])
'Tests describing parameters if function exists'
def test_that_when_describing_function_it_returns_the_dict_of_properties_returns_true(self):
self.conn.list_functions.return_value = {'Functions': [function_ret]} with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): result = boto_lambda.describe_function(FunctionName=function_ret['FunctionName'], **conn_parameters) self.assertEqual(result, {'function': function_ret})
'Tests describing parameters if function does not exist'
def test_that_when_describing_function_it_returns_the_dict_of_properties_returns_false(self):
self.conn.list_functions.return_value = {'Functions': []} with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): result = boto_lambda.describe_function(FunctionName='testfunction', **conn_parameters) self.assertFalse(result['function'])
'Tests describing parameters failure'
def test_that_when_describing_lambda_on_client_error_it_returns_error(self):
self.conn.list_functions.side_effect = ClientError(error_content, 'list_functions') result = boto_lambda.describe_function(FunctionName='testfunction', **conn_parameters) self.assertTrue(('error' in result))
'tests True function updated.'
def test_that_when_updating_a_function_succeeds_the_update_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.update_function_config.return_value = function_ret result = boto_lambda.update_function_config(FunctionName=function_ret['FunctionName'], Role='myrole', **conn_parameters) self.assertTrue(result['updated'])
'tests False function not updated.'
def test_that_when_updating_a_function_fails_the_update_function_method_returns_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.update_function_configuration.side_effect = ClientError(error_content, 'update_function') result = boto_lambda.update_function_config(FunctionName='testfunction', Role='myrole', **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_function'))
'tests True function updated.'
def test_that_when_updating_function_code_from_zipfile_succeeds_the_update_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): with TempZipFile() as zipfile: self.conn.update_function_code.return_value = function_ret result = boto_lambda.update_function_code(FunctionName=function_ret['FunctionName'], ZipFile=zipfile, **conn_parameters) self.assertTrue(result['updated'])
'tests True function updated.'
def test_that_when_updating_function_code_from_s3_succeeds_the_update_function_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.update_function_code.return_value = function_ret result = boto_lambda.update_function_code(FunctionName='testfunction', S3Bucket='bucket', S3Key='key', **conn_parameters) self.assertTrue(result['updated'])
'tests Creating a function without code'
def test_that_when_updating_function_code_without_code_raises_a_salt_invocation_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): with self.assertRaisesRegex(SaltInvocationError, 'Either ZipFile must be specified, or S3Bucket and S3Key must be provided.'): result = boto_lambda.update_function_code(FunctionName='testfunction', **conn_parameters)
'tests False function not updated.'
def test_that_when_updating_function_code_fails_the_update_function_method_returns_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.update_function_code.side_effect = ClientError(error_content, 'update_function_code') result = boto_lambda.update_function_code(FunctionName='testfunction', S3Bucket='bucket', S3Key='key', **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_function_code'))
'tests True function versions listed.'
def test_that_when_listing_function_versions_succeeds_the_list_function_versions_method_returns_true(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.list_versions_by_function.return_value = {'Versions': [function_ret]} result = boto_lambda.list_function_versions(FunctionName='testfunction', **conn_parameters) self.assertTrue(result['Versions'])
'tests False no function versions listed.'
def test_that_when_listing_function_versions_fails_the_list_function_versions_method_returns_false(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.list_versions_by_function.return_value = {'Versions': []} result = boto_lambda.list_function_versions(FunctionName='testfunction', **conn_parameters) self.assertFalse(result['Versions'])
'tests False function versions error.'
def test_that_when_listing_function_versions_fails_the_list_function_versions_method_returns_error(self):
with patch.dict(boto_lambda.__salt__, {'boto_iam.get_account_id': MagicMock(return_value='1234')}): self.conn.list_versions_by_function.side_effect = ClientError(error_content, 'list_versions_by_function') result = boto_lambda.list_function_versions(FunctionName='testfunction', **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_versions_by_function'))
'tests True alias created.'
def test_that_when_creating_an_alias_succeeds_the_create_alias_method_returns_true(self):
self.conn.create_alias.return_value = alias_ret result = boto_lambda.create_alias(FunctionName='testfunction', Name=alias_ret['Name'], FunctionVersion=alias_ret['FunctionVersion'], **conn_parameters) self.assertTrue(result['created'])
'tests False alias not created.'
def test_that_when_creating_an_alias_fails_the_create_alias_method_returns_error(self):
self.conn.create_alias.side_effect = ClientError(error_content, 'create_alias') result = boto_lambda.create_alias(FunctionName='testfunction', Name=alias_ret['Name'], FunctionVersion=alias_ret['FunctionVersion'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('create_alias'))
'tests True alias deleted.'
def test_that_when_deleting_an_alias_succeeds_the_delete_alias_method_returns_true(self):
result = boto_lambda.delete_alias(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertTrue(result['deleted'])
'tests False alias not deleted.'
def test_that_when_deleting_an_alias_fails_the_delete_alias_method_returns_false(self):
self.conn.delete_alias.side_effect = ClientError(error_content, 'delete_alias') result = boto_lambda.delete_alias(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertFalse(result['deleted'])
'Tests checking lambda alias existence when the lambda alias already exists'
def test_that_when_checking_if_an_alias_exists_and_the_alias_exists_the_alias_exists_method_returns_true(self):
self.conn.list_aliases.return_value = {'Aliases': [alias_ret]} result = boto_lambda.alias_exists(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertTrue(result['exists'])
'Tests checking lambda alias existence when the lambda alias does not exist'
def test_that_when_checking_if_an_alias_exists_and_the_alias_does_not_exist_the_alias_exists_method_returns_false(self):
self.conn.list_aliases.return_value = {'Aliases': [alias_ret]} result = boto_lambda.alias_exists(FunctionName='testfunction', Name='otheralias', **conn_parameters) self.assertFalse(result['exists'])
'Tests checking lambda alias existence when boto returns an error'
def test_that_when_checking_if_an_alias_exists_and_boto3_returns_an_error_the_alias_exists_method_returns_error(self):
self.conn.list_aliases.side_effect = ClientError(error_content, 'list_aliases') result = boto_lambda.alias_exists(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_aliases'))
'Tests describing parameters if alias exists'
def test_that_when_describing_alias_it_returns_the_dict_of_properties_returns_true(self):
self.conn.list_aliases.return_value = {'Aliases': [alias_ret]} result = boto_lambda.describe_alias(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertEqual(result, {'alias': alias_ret})
'Tests describing parameters if alias does not exist'
def test_that_when_describing_alias_it_returns_the_dict_of_properties_returns_false(self):
self.conn.list_aliases.return_value = {'Aliases': [alias_ret]} result = boto_lambda.describe_alias(FunctionName='testfunction', Name='othername', **conn_parameters) self.assertFalse(result['alias'])
'Tests describing parameters failure'
def test_that_when_describing_lambda_on_client_error_it_returns_error(self):
self.conn.list_aliases.side_effect = ClientError(error_content, 'list_aliases') result = boto_lambda.describe_alias(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertTrue(('error' in result))
'tests True alias updated.'
def test_that_when_updating_an_alias_succeeds_the_update_alias_method_returns_true(self):
self.conn.update_alias.return_value = alias_ret result = boto_lambda.update_alias(FunctionName='testfunctoin', Name=alias_ret['Name'], Description=alias_ret['Description'], **conn_parameters) self.assertTrue(result['updated'])
'tests False alias not updated.'
def test_that_when_updating_an_alias_fails_the_update_alias_method_returns_error(self):
self.conn.update_alias.side_effect = ClientError(error_content, 'update_alias') result = boto_lambda.update_alias(FunctionName='testfunction', Name=alias_ret['Name'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_alias'))
'tests True mapping created.'
def test_that_when_creating_a_mapping_succeeds_the_create_event_source_mapping_method_returns_true(self):
self.conn.create_event_source_mapping.return_value = event_source_mapping_ret result = boto_lambda.create_event_source_mapping(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], StartingPosition='LATEST', **conn_parameters) self.assertTrue(result['created'])
'tests False mapping not created.'
def test_that_when_creating_an_event_source_mapping_fails_the_create_event_source_mapping_method_returns_error(self):
self.conn.create_event_source_mapping.side_effect = ClientError(error_content, 'create_event_source_mapping') result = boto_lambda.create_event_source_mapping(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], StartingPosition='LATEST', **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('create_event_source_mapping'))
'tests True mapping ids listed.'
def test_that_when_listing_mapping_ids_succeeds_the_get_event_source_mapping_ids_method_returns_true(self):
self.conn.list_event_source_mappings.return_value = {'EventSourceMappings': [event_source_mapping_ret]} result = boto_lambda.get_event_source_mapping_ids(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertTrue(result)
'tests False no mapping ids listed.'
def test_that_when_listing_event_source_mapping_ids_fails_the_get_event_source_mapping_ids_versions_method_returns_false(self):
self.conn.list_event_source_mappings.return_value = {'EventSourceMappings': []} result = boto_lambda.get_event_source_mapping_ids(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertFalse(result)
'tests False mapping ids error.'
def test_that_when_listing_event_source_mapping_ids_fails_the_get_event_source_mapping_ids_method_returns_error(self):
self.conn.list_event_source_mappings.side_effect = ClientError(error_content, 'list_event_source_mappings') result = boto_lambda.get_event_source_mapping_ids(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_event_source_mappings'))
'tests True mapping deleted.'
def test_that_when_deleting_an_event_source_mapping_by_UUID_succeeds_the_delete_event_source_mapping_method_returns_true(self):
result = boto_lambda.delete_event_source_mapping(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertTrue(result['deleted'])
'tests True mapping deleted.'
@skipIf(True, 'This appears to leak memory and crash the unit test suite') def test_that_when_deleting_an_event_source_mapping_by_name_succeeds_the_delete_event_source_mapping_method_returns_true(self):
self.conn.list_event_source_mappings.return_value = {'EventSourceMappings': [event_source_mapping_ret]} result = boto_lambda.delete_event_source_mapping(EventSourceArn=event_source_mapping_ret['EventSourceArn'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertTrue(result['deleted'])
'tests Deleting a mapping without identifier'
def test_that_when_deleting_an_event_source_mapping_without_identifier_the_delete_event_source_mapping_method_raises_saltinvocationexception(self):
with self.assertRaisesRegex(SaltInvocationError, 'Either UUID must be specified, or EventSourceArn and FunctionName must be provided.'): result = boto_lambda.delete_event_source_mapping(**conn_parameters)
'tests False mapping not deleted.'
def test_that_when_deleting_an_event_source_mapping_fails_the_delete_event_source_mapping_method_returns_false(self):
self.conn.delete_event_source_mapping.side_effect = ClientError(error_content, 'delete_event_source_mapping') result = boto_lambda.delete_event_source_mapping(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertFalse(result['deleted'])
'Tests checking lambda event_source_mapping existence when the lambda event_source_mapping already exists'
def test_that_when_checking_if_an_event_source_mapping_exists_and_the_event_source_mapping_exists_the_event_source_mapping_exists_method_returns_true(self):
self.conn.get_event_source_mapping.return_value = event_source_mapping_ret result = boto_lambda.event_source_mapping_exists(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertTrue(result['exists'])
'Tests checking lambda event_source_mapping existence when the lambda event_source_mapping does not exist'
def test_that_when_checking_if_an_event_source_mapping_exists_and_the_event_source_mapping_does_not_exist_the_event_source_mapping_exists_method_returns_false(self):
self.conn.get_event_source_mapping.return_value = None result = boto_lambda.event_source_mapping_exists(UUID='other_UUID', **conn_parameters) self.assertFalse(result['exists'])
'Tests checking lambda event_source_mapping existence when boto returns an error'
def test_that_when_checking_if_an_event_source_mapping_exists_and_boto3_returns_an_error_the_event_source_mapping_exists_method_returns_error(self):
self.conn.get_event_source_mapping.side_effect = ClientError(error_content, 'list_event_source_mappings') result = boto_lambda.event_source_mapping_exists(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_event_source_mappings'))
'Tests describing parameters if event_source_mapping exists'
def test_that_when_describing_event_source_mapping_it_returns_the_dict_of_properties_returns_true(self):
self.conn.get_event_source_mapping.return_value = event_source_mapping_ret result = boto_lambda.describe_event_source_mapping(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertEqual(result, {'event_source_mapping': event_source_mapping_ret})
'Tests describing parameters if event_source_mapping does not exist'
def test_that_when_describing_event_source_mapping_it_returns_the_dict_of_properties_returns_false(self):
self.conn.get_event_source_mapping.return_value = None result = boto_lambda.describe_event_source_mapping(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertFalse(result['event_source_mapping'])
'Tests describing parameters failure'
def test_that_when_describing_event_source_mapping_on_client_error_it_returns_error(self):
self.conn.get_event_source_mapping.side_effect = ClientError(error_content, 'get_event_source_mapping') result = boto_lambda.describe_event_source_mapping(UUID=event_source_mapping_ret['UUID'], **conn_parameters) self.assertTrue(('error' in result))
'tests True event_source_mapping updated.'
def test_that_when_updating_an_event_source_mapping_succeeds_the_update_event_source_mapping_method_returns_true(self):
self.conn.update_event_source_mapping.return_value = event_source_mapping_ret result = boto_lambda.update_event_source_mapping(UUID=event_source_mapping_ret['UUID'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertTrue(result['updated'])
'tests False event_source_mapping not updated.'
def test_that_when_updating_an_event_source_mapping_fails_the_update_event_source_mapping_method_returns_error(self):
self.conn.update_event_source_mapping.side_effect = ClientError(error_content, 'update_event_source_mapping') result = boto_lambda.update_event_source_mapping(UUID=event_source_mapping_ret['UUID'], FunctionName=event_source_mapping_ret['FunctionArn'], **conn_parameters) self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_event_source_mapping'))
'Tests the return of a file containing one alias'
def test_list_aliases(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias)): ret = {'foo': '[email protected]'} self.assertEqual(aliases.list_aliases(), ret)
'Tests the return of a file containing multiple aliases'
def test_list_aliases_mult(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = {'foo': '[email protected]', 'hello': '[email protected], [email protected]'} self.assertEqual(aliases.list_aliases(), ret)
'Tests the target returned by an alias with one target'
def test_get_target(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias)): ret = '[email protected]' self.assertEqual(aliases.get_target('foo'), ret)
'Tests the target returned by an alias with multiple targets'
def test_get_target_mult(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = '[email protected], [email protected]' self.assertEqual(aliases.get_target('hello'), ret)
'Tests return of an alias doesn\'t exist'
def test_get_target_no_alias(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias)): self.assertEqual(aliases.get_target('pizza'), '')
'Tests simple return known alias and target'
def test_has_target(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias)): ret = aliases.has_target('foo', '[email protected]') self.assertTrue(ret)
'Tests return of empty alias and known target'
def test_has_target_no_alias(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias)): ret = aliases.has_target('', '[email protected]') self.assertFalse(ret)
'Tests return of known alias and empty target'
def test_has_target_no_target(self):
self.assertRaises(SaltInvocationError, aliases.has_target, 'foo', '')
'Tests return of multiple targets to one alias'
def test_has_target_mult(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = aliases.has_target('hello', '[email protected], [email protected]') self.assertTrue(ret)
'Tests return of multiple targets to one alias in opposite order'
def test_has_target_mult_differs(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = aliases.has_target('hello', '[email protected], [email protected]') self.assertFalse(ret)
'Tests return of target as same list to know alias'
def test_has_target_list_mult(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = aliases.has_target('hello', ['[email protected]', '[email protected]']) self.assertTrue(ret)
'Tests return of target as differing list to known alias'
def test_has_target_list_mult_differs(self):
with patch('salt.modules.aliases.__parse_aliases', MagicMock(return_value=self.mock_alias_mult)): ret = aliases.has_target('hello', ['[email protected]', '[email protected]']) self.assertFalse(ret)
'Tests return when target is already present'
def test_set_target_equal(self):
with patch('salt.modules.aliases.get_target', MagicMock(return_value='[email protected]')): alias = 'foo' target = '[email protected]' ret = aliases.set_target(alias, target) self.assertTrue(ret)
'Tests return of empty alias'
def test_set_target_empty_alias(self):
self.assertRaises(SaltInvocationError, aliases.set_target, '', 'foo')
'Tests return of known alias and empty target'
def test_set_target_empty_target(self):
self.assertRaises(SaltInvocationError, aliases.set_target, 'foo', '')
'Tests return when alias is not present'
def test_rm_alias_absent(self):
with patch('salt.modules.aliases.get_target', MagicMock(return_value='')): ret = aliases.rm_alias('foo') self.assertTrue(ret)
'Test if it starts service via s6-svc.'
def test_start(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertTrue(s6.start('ssh'))
'Test if it stops service via s6.'
def test_stop(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertTrue(s6.stop('ssh'))
'Test if it send a TERM to service via s6.'
def test_term(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertTrue(s6.term('ssh'))
'Test if it send a HUP to service via s6.'
def test_reload(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertTrue(s6.reload_('ssh'))
'Test if it restart service via s6. This will stop/start service.'
def test_restart(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertTrue(s6.restart('ssh'))
'Test if it calls s6.restart() function.'
def test_full_restart(self):
mock_ret = MagicMock(return_value=False) with patch.dict(s6.__salt__, {'cmd.retcode': mock_ret}): self.assertIsNone(s6.full_restart('ssh'))
'Test if it return the status for a service via s6, return pid if running.'
def test_status(self):
mock_run = MagicMock(return_value='salt') with patch.dict(s6.__salt__, {'cmd.run_stdout': mock_run}): self.assertEqual(s6.status('ssh'), '')
'Test if it returns ``True`` if the specified service is available, otherwise returns ``False``.'
def test_available(self):
with patch.object(os, 'listdir', MagicMock(return_value=['/etc/service'])): self.assertTrue(s6.available('/etc/service'))
'Test if it returns ``True`` if the specified service is not available, otherwise returns ``False``.'
def test_missing(self):
with patch.object(os, 'listdir', MagicMock(return_value=['/etc/service'])): self.assertTrue(s6.missing('foo'))
'Test if it return a list of all available services.'
def test_get_all(self):
with patch.object(os, 'listdir', MagicMock(return_value=['/etc/service'])): self.assertListEqual(s6.get_all(), ['/etc/service'])
'Test if it return True if jail exists False if not.'
def test_is_jail(self):
mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertTrue(poudriere.is_jail('salt')) self.assertFalse(poudriere.is_jail('SALT'))
'Test if it make jail ``jname`` pkgng aware.'
def test_make_pkgng_aware(self):
ret1 = 'Could not create or find required directory /tmp/salt' ret2 = 'Looks like file /tmp/salt/salt-make.conf could not be created' ret3 = {'changes': 'Created /tmp/salt/salt-make.conf'} mock = MagicMock(return_value='/tmp/salt') mock_true = MagicMock(return_value=True) with patch.dict(poudriere.__salt__, {'config.option': mock, 'file.write': mock_true}): with patch.object(os.path, 'isdir', MagicMock(return_value=False)): with patch.object(os, 'makedirs', mock_true): self.assertEqual(poudriere.make_pkgng_aware('salt'), ret1) with patch.object(os.path, 'isdir', mock_true): self.assertEqual(poudriere.make_pkgng_aware('salt'), ret2) with patch.object(os.path, 'isfile', mock_true): self.assertDictEqual(poudriere.make_pkgng_aware('salt'), ret3)
'Test if it returns a dict of poudriere main configuration definitions.'
def test_parse_config(self):
mock = MagicMock(return_value='/tmp/salt') with patch.dict(poudriere.__salt__, {'config.option': mock}): with patch('salt.utils.files.fopen', mock_open()): with patch.object(poudriere, '_check_config_exists', MagicMock(side_effect=[True, False])): self.assertDictEqual(poudriere.parse_config(), {}) self.assertEqual(poudriere.parse_config(), 'Could not find /tmp/salt on file system')
'Test if it return poudriere version.'
def test_version(self):
mock = MagicMock(return_value='9.0-RELEASE') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): self.assertEqual(poudriere.version(), '9.0-RELEASE')
'Test if it return a list of current jails managed by poudriere.'
def test_list_jails(self):
mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertListEqual(poudriere.list_jails(), ['salt stack'])
'Test if it return a list of current port trees managed by poudriere.'
def test_list_ports(self):
mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertListEqual(poudriere.list_ports(), ['salt stack'])
'Test if it creates a new poudriere jail if one does not exist.'
def test_create_jail(self):
mock_stack = MagicMock(return_value='90amd64 stack') mock_true = MagicMock(return_value=True) with patch.dict(poudriere.__salt__, {'cmd.run': mock_stack}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.create_jail('90amd64', 'amd64'), '90amd64 already exists') with patch.object(poudriere, 'make_pkgng_aware', mock_true): self.assertEqual(poudriere.create_jail('80amd64', 'amd64'), 'Issue creating jail 80amd64') with patch.object(poudriere, 'make_pkgng_aware', mock_true): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): with patch.object(poudriere, 'is_jail', MagicMock(side_effect=[False, True])): with patch.dict(poudriere.__salt__, {'cmd.run': mock_stack}): self.assertEqual(poudriere.create_jail('80amd64', 'amd64'), 'Created jail 80amd64')
'Test if it run freebsd-update on `name` poudriere jail.'
def test_update_jail(self):
mock = MagicMock(return_value='90amd64 stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.update_jail('90amd64'), '90amd64 stack') self.assertEqual(poudriere.update_jail('80amd64'), 'Could not find jail 80amd64')
'Test if it deletes poudriere jail with `name`.'
def test_delete_jail(self):
ret = 'Looks like there was an issue deleteing jail 90amd64' mock_stack = MagicMock(return_value='90amd64 stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock_stack}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.delete_jail('90amd64'), ret) self.assertEqual(poudriere.delete_jail('80amd64'), 'Looks like jail 80amd64 has not been created') ret1 = 'Deleted jail "80amd64" but was unable to remove jail make file' with patch.object(poudriere, 'is_jail', MagicMock(side_effect=[True, False, True, False])): with patch.dict(poudriere.__salt__, {'cmd.run': mock_stack}): with patch.object(poudriere, '_config_dir', MagicMock(return_value='/tmp/salt')): self.assertEqual(poudriere.delete_jail('80amd64'), 'Deleted jail 80amd64') with patch.object(os.path, 'isfile', MagicMock(return_value=True)): self.assertEqual(poudriere.delete_jail('80amd64'), ret1)
'Test if it not working need to run portfetch non interactive.'
def test_create_ports_tree(self):
mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.create_ports_tree(), 'salt stack')
'Test if it updates the ports tree, either the default or the `ports_tree` specified.'
def test_update_ports_tree(self):
mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.update_ports_tree('staging'), 'salt stack')
'Test if it run bulk build on poudriere server.'
def test_bulk_build(self):
ret = 'Could not find file /root/pkg_list on filesystem' mock = MagicMock(return_value='salt stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): self.assertEqual(poudriere.bulk_build('90amd64', '/root/pkg_list'), ret) with patch.object(os.path, 'isfile', MagicMock(return_value=True)): self.assertEqual(poudriere.bulk_build('90amd64', '/root/pkg_list'), 'Could not find jail 90amd64') ret = 'There may have been an issue building packages dumping output: 90amd64 stack' with patch.object(os.path, 'isfile', MagicMock(return_value=True)): with patch('salt.modules.poudriere._check_config_exists', MagicMock(return_value=True)): mock = MagicMock(return_value='90amd64 stack packages built') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): self.assertEqual(poudriere.bulk_build('90amd64', '/root/pkg_list'), '90amd64 stack packages built') mock = MagicMock(return_value='90amd64 stack') with patch.dict(poudriere.__salt__, {'cmd.run': mock}): self.assertEqual(poudriere.bulk_build('90amd64', '/root/pkg_list'), ret)
'Test if ping succeeds'
def test_ping(self):
with patch.object(elasticsearch, '_get_instance', self.es_return_true): self.assertTrue(elasticsearch.ping())
'Test if ping fails'
def test_ping_failure(self):
with patch.object(elasticsearch, '_get_instance', self.es_raise_command_execution_error): self.assertFalse(elasticsearch.ping())
'Test if status fetch succeeds'
def test_info(self):
class MockElastic(object, ): '\n Mock of Elasticsearch client\n ' def info(self): '\n Mock of info method\n ' return [{'test': 'key'}] with patch.object(elasticsearch, '_get_instance', MagicMock(return_value=MockElastic())): self.assertListEqual(elasticsearch.info(), [{'test': 'key'}])