desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Test to send a message via SMTP'
| def test_send_msg(self):
| name = 'This is a salt states module'
comt = 'Need to send message to admin@example.com: This is a salt states module'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': comt}
with patch.dict(smtp.__opts__, {'test': True}):
self.assertD... |
'Tests exceptions when checking rule existence'
| def test_present_when_failing_to_describe_rule(self):
| self.conn.list_rules.side_effect = ClientError(error_content, 'error on list rules')
result = self.salt_states['boto_cloudwatch_event.present'](name='test present', Name=rule_name, Description=rule_desc, ScheduleExpression=rule_sched, Targets=[{'Id': 'target1', 'Arn': 'arn::::::*'}], **conn_paramete... |
'Tests present on a rule name that doesn\'t exist and
an error is thrown on creation.'
| def test_present_when_failing_to_create_a_new_rule(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.side_effect = ClientError(error_content, 'put_rule')
result = self.salt_states['boto_cloudwatch_event.present'](name='test present', Name=rule_name, Description=rule_desc, ScheduleExpression=rule_sched, Targets=[{'Id': 'target1', 'Arn':... |
'Tests present on a rule name that doesn\'t exist and
an error is thrown when adding targets.'
| def test_present_when_failing_to_describe_the_new_rule(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.side_effect = ClientError(error_content, 'describe_rule')
result = self.salt_states['boto_cloudwatch_event.present'](name='test present', Name=rule_name, Description=rule_desc, Schedul... |
'Tests present on a rule name that doesn\'t exist and
an error is thrown when adding targets.'
| def test_present_when_failing_to_create_a_new_rules_targets(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.put_targets.side_effect = ClientError(error_content, 'put_targets')
result = self.salt_states['boto_cloudwatch_event.present'](name='test present'... |
'Tests the successful case of creating a new rule, and updating its
targets'
| def test_present_when_rule_does_not_exist(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.put_targets.return_value = {'FailedEntryCount': 0}
result = self.salt_states['boto_cloudwatch_event.present'](name='test present', Name=rule_name,... |
'Tests present on an existing rule where an error is thrown on updating the pool properties.'
| def test_present_when_failing_to_update_an_existing_rule(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.describe_rule.side_effect = ClientError(error_content, 'describe_rule')
result = self.salt_states['boto_cloudwatch_event.present'](name='test present', Name=rule_name, Description=rule_desc, ScheduleExpression=rule_sched, Targets=[{'Id':... |
'Tests present on an existing rule where put_rule succeeded, but an error
is thrown on getting targets'
| def test_present_when_failing_to_get_targets(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.list_targets_by_rule.side_effect = ClientError(error_content, 'list_targets')
result = self.salt_states['boto_cloudwatch_event.present'](name... |
'Tests present on an existing rule where put_rule succeeded, but an error
is thrown on putting targets'
| def test_present_when_failing_to_put_targets(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.list_targets.return_value = {'Targets': []}
self.conn.put_targets.side_effect = ClientError(error_content, 'put_targets')
result = self.salt_stat... |
'Tests present on an existing rule where put_rule succeeded, and targets
must be added'
| def test_present_when_putting_targets(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.list_targets.return_value = {'Targets': []}
self.conn.put_targets.return_value = {'FailedEntryCount': 0}
result = self.salt_states['boto_cloudwat... |
'Tests present on an existing rule where put_rule succeeded, and targets
must be removed'
| def test_present_when_removing_targets(self):
| self.conn.list_rules.return_value = {'Rules': []}
self.conn.put_rule.return_value = rule_ret
self.conn.describe_rule.return_value = rule_ret
self.conn.list_targets.return_value = {'Targets': [{'Id': 'target1'}, {'Id': 'target2'}]}
self.conn.put_targets.return_value = {'FailedEntryCount': 0}
resu... |
'Tests exceptions when checking rule existence'
| def test_absent_when_failing_to_describe_rule(self):
| self.conn.list_rules.side_effect = ClientError(error_content, 'error on list rules')
result = self.salt_states['boto_cloudwatch_event.absent'](name='test present', Name=rule_name, **conn_parameters)
self.assertEqual(result.get('result'), False)
self.assertTrue(('error on list rules'... |
'Tests absent on an non-existing rule'
| def test_absent_when_rule_does_not_exist(self):
| self.conn.list_rules.return_value = {'Rules': []}
result = self.salt_states['boto_cloudwatch_event.absent'](name='test absent', Name=rule_name, **conn_parameters)
self.assertEqual(result.get('result'), True)
self.assertEqual(result['changes'], {})
|
'Tests absent on an rule when the list_targets call fails'
| def test_absent_when_failing_to_list_targets(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.list_targets_by_rule.side_effect = ClientError(error_content, 'list_targets')
result = self.salt_states['boto_cloudwatch_event.absent'](name='test absent', Name=rule_name, **conn_parameters)
self.assertEqual(result.get('result'), Fal... |
'Tests absent on an rule when the remove_targets call fails'
| def test_absent_when_failing_to_remove_targets_exception(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.list_targets_by_rule.return_value = {'Targets': [{'Id': 'target1'}]}
self.conn.remove_targets.side_effect = ClientError(error_content, 'remove_targets')
result = self.salt_states['boto_cloudwatch_event.absent'](name='test absent', Na... |
'Tests absent on an rule when the remove_targets call fails'
| def test_absent_when_failing_to_remove_targets_nonexception(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.list_targets_by_rule.return_value = {'Targets': [{'Id': 'target1'}]}
self.conn.remove_targets.return_value = {'FailedEntryCount': 1}
result = self.salt_states['boto_cloudwatch_event.absent'](name='test absent', Name=rule_name, **conn... |
'Tests absent on an rule when the delete_rule call fails'
| def test_absent_when_failing_to_delete_rule(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.list_targets_by_rule.return_value = {'Targets': [{'Id': 'target1'}]}
self.conn.remove_targets.return_value = {'FailedEntryCount': 0}
self.conn.delete_rule.side_effect = ClientError(error_content, 'delete_rule')
result = self.salt_st... |
'Tests absent on an rule'
| def test_absent(self):
| self.conn.list_rules.return_value = {'Rules': [rule_ret]}
self.conn.list_targets_by_rule.return_value = {'Targets': [{'Id': 'target1'}]}
self.conn.remove_targets.return_value = {'FailedEntryCount': 0}
result = self.salt_states['boto_cloudwatch_event.absent'](name='test absent', Name=rule_name, **conn... |
'Test to add a job to queue.'
| def test_present(self):
| name = 'jboss'
timespec = '9:09 11/04/15'
tag = 'love'
user = 'jam'
mock_atat = {'jobs': [{'date': '2015-11-04', 'job': '1476031633.a', 'queue': 'a', 'tag': tag, 'time': '09:09:00', 'user': user}]}
ret = {'name': name, 'result': True, 'changes': {'date': '2015-11-04', 'job': '1476031633.a', '... |
'Test to remove a job from queue'
| def test_absent(self):
| name = 'jboss'
tag = 'rose'
user = 'jam'
mock_atatrm = {'jobs': {'removed': ['1476033859.a', '1476033855.a'], 'tag': None}}
mock_atjobcheck = {'jobs': [{'date': '2015-11-04', 'job': '1476031633.a', 'queue': 'a', 'tag': tag, 'time': '09:09:00', 'user': user}]}
ret = {'name': name, 'result': True,... |
'Test to ensure a search is present.'
| def test_present(self):
| name = 'API Error Search'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
mock = MagicMock(side_effect=[True, False, False, True])
with patch.dict(splunk_search.__salt__, {'splunk_search.get': mock, 'splunk_search.create': mock}):
with patch.dict(splunk_search.__opts__, ... |
'Test to ensure a search is absent.'
| def test_absent(self):
| name = 'API Error Search'
ret = {'name': name, 'result': None, 'comment': ''}
mock = MagicMock(side_effect=[True, False])
with patch.dict(splunk_search.__salt__, {'splunk_search.get': mock}):
with patch.dict(splunk_search.__opts__, {'test': True}):
comt = 'Would delete {0... |
'Test to verify that the given package is installed
and is at the correct version.'
| def test_installed(self):
| name = 'coffee-script'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_err = MagicMock(side_effect=CommandExecutionError)
mock_dict = MagicMock(return_value={name: {'version': '1.2'}})
with patch.dict(npm.__salt__, {'npm.list': mock_err}):
comt = "Error looking ... |
'Test to verify that the given package is not installed.'
| def test_removed(self):
| name = 'coffee-script'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_err = MagicMock(side_effect=[CommandExecutionError, {}, {name: ''}, {name: ''}])
mock_t = MagicMock(return_value=True)
with patch.dict(npm.__salt__, {'npm.list': mock_err, 'npm.uninstall': mock_t}):
... |
'Test to bootstraps a node.js application.'
| def test_bootstrap(self):
| name = 'coffee-script'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_err = MagicMock(side_effect=[CommandExecutionError, False, True])
with patch.dict(npm.__salt__, {'npm.install': mock_err}):
comt = "Error Bootstrapping 'coffee-script': "
ret.update({... |
'Test to verify that the npm cache is cleaned.'
| def test_cache_cleaned(self):
| name = 'coffee-script'
pkg_ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
ret = {'name': None, 'result': False, 'comment': '', 'changes': {}}
mock_list = MagicMock(return_value=['~/.npm', '~/.npm/{0}/'.format(name)])
mock_cache_clean_success = MagicMock(return_value=True)
mo... |
'Mock interface method'
| @staticmethod
def interfaces():
| return {'salt': {'up': 1}}
|
'Mock grains method'
| @staticmethod
def grains(lis, bol):
| return {'A': 'B'}
|
'Test to ensure that the named interface is configured properly'
| def test_managed(self):
| with patch('salt.states.network.salt.utils.network', MockNetwork()):
with patch('salt.states.network.salt.loader', MockGrains()):
ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
change = {'interface': '--- \n+++ \n@@ -1 +1 @@\n-A\n+B', 'status': '... |
'Test to manage network interface static routes.'
| def test_routes(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
mock = MagicMock(side_effect=[AttributeError, False, False, 'True', False, False])
with patch.dict(network.__salt__, {'ip.get_routes': mock}):
self.assertDictEqual(network.routes('salt'), ret)
mock = MagicMock(side_effect=... |
'Test to ensure that global network settings
are configured properly'
| def test_system(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
with patch.dict(network.__opts__, {'test': True}):
mock = MagicMock(side_effect=[AttributeError, False, False, 'As'])
with patch.dict(network.__salt__, {'ip.get_network_settings': mock}):
self.assertDictEqual(netwo... |
'Test if it returns True when user already exists in htpasswd file'
| def test_user_exists_already(self):
| mock = MagicMock(return_value={'retcode': 0})
with patch.dict(htpasswd.__salt__, {'file.grep': mock}):
ret = htpasswd.user_exists('larry', 'badpass', '/etc/httpd/htpasswd')
expected = {'name': 'larry', 'result': True, 'comment': 'User already known', 'changes': {}}
self.assertEqual... |
'Test if it returns True when new user is added to htpasswd file'
| def test_new_user_success(self):
| mock_grep = MagicMock(return_value={'retcode': 1})
mock_useradd = MagicMock(return_value={'retcode': 0, 'stderr': 'Success'})
with patch.dict(htpasswd.__salt__, {'file.grep': mock_grep, 'webutil.useradd': mock_useradd}):
ret = htpasswd.user_exists('larry', 'badpass', '/etc/httpd/htpasswd')
e... |
'Test if it returns False when adding user to htpasswd failed'
| def test_new_user_error(self):
| mock_grep = MagicMock(return_value={'retcode': 1})
mock_useradd = MagicMock(return_value={'retcode': 1, 'stderr': 'Error'})
with patch.dict(htpasswd.__salt__, {'file.grep': mock_grep, 'webutil.useradd': mock_useradd}):
ret = htpasswd.user_exists('larry', 'badpass', '/etc/httpd/htpasswd')
exp... |
'Test to ensure the RabbitMQ policy exists.'
| def test_present(self):
| name = 'HA'
pattern = '.*'
definition = '{"ha-mode":"all"}'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[{'/': {name: {'pattern': pattern, 'definition': definition, 'priority': 0}}}, {}])
with patch.dict(rabbitmq_policy.__salt__, {'rabbitmq.lis... |
'Test to ensure the named policy is absent.'
| def test_absent(self):
| name = 'HA'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[False, True])
with patch.dict(rabbitmq_policy.__salt__, {'rabbitmq.policy_exists': mock}):
comment = "Policy '/ HA' is not present."
ret.update({'comment': comment}... |
'Test to manage a memcached key.'
| def test_managed(self):
| name = 'foo'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_t = MagicMock(side_effect=[CommandExecutionError, 'salt', True, True, True])
with patch.dict(memcached.__salt__, {'memcached.get': mock_t, 'memcached.set': mock_t}):
self.assertDictEqual(memcached.managed(name)... |
'Test to ensure that a memcached key is not present.'
| def test_absent(self):
| name = 'foo'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_t = MagicMock(side_effect=[CommandExecutionError, 'salt', None, True, True, True])
with patch.dict(memcached.__salt__, {'memcached.get': mock_t, 'memcached.delete': mock_t}):
self.assertDictEqual(memcached.abse... |
'Test to create a symlink.'
| def test_symlink(self):
| name = '/tmp/testfile.txt'
target = salt.utils.files.mkstemp()
test_dir = '/tmp'
user = 'salt'
if salt.utils.platform.is_windows():
group = 'salt'
else:
group = 'saltstack'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value... |
'Test to make sure that the named file or directory is absent.'
| def test_absent(self):
| name = '/fake/file.conf'
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
mock_file = MagicMock(side_effect=[True, CommandExecutionError])
mock_tree = MagicMock(side_effect=[True, OSEr... |
'Test to verify that the named file or directory is present or exists.'
| def test_exists(self):
| name = '/etc/grub.conf'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}, 'pchanges': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
comt = 'Must provide name to file.exists'
ret.update({'comment': comt, 'name': ''})
self.assert... |
'Test to verify that the named file or directory is missing.'
| def test_missing(self):
| name = '/etc/grub.conf'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(return_value=False)
comt = 'Must provide name to file.missing'
ret.update({'comment': comt, 'name': '', 'pchanges': {}})
self.asser... |
'Test to manage a given file, this function allows for a file to be
downloaded from the salt master and potentially run through a templating
system.'
| def test_managed(self):
| with patch('salt.states.file._load_accumulators', MagicMock(return_value=([], []))):
name = '/etc/grub.conf'
user = 'salt'
group = 'saltstack'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value=True)
mock_f = MagicMock(... |
'Test to ensure that a named directory is present and has the right perms'
| def test_directory(self):
| name = '/etc/grub.conf'
user = 'salt'
group = 'saltstack'
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
comt = 'Must provide name to file.directory'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate.directory(''), ret)
... |
'Test to recurse through a subdirectory on the master
and copy said subdirectory over to the specified path.'
| def test_recurse(self):
| name = '/opt/code/flask'
source = 'salt://code/flask'
user = 'salt'
group = 'saltstack'
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
comt = "'mode' is not allowed in 'file.recurse'. Please use 'file_mode' and 'dir_mode'."
r... |
'Test to maintain an edit in a file.'
| def test_replace(self):
| name = '/etc/grub.conf'
pattern = 'CentOS +'
repl = 'salt'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.replace'
ret.update({'comment': comt, 'name': '', 'pchanges': {}})
self.assertDictEqual(filestate.replace('', patter... |
'Test to maintain an edit in a file in a zone
delimited by two line markers.'
| def test_blockreplace(self):
| with patch('salt.states.file._load_accumulators', MagicMock(return_value=([], []))):
name = '/etc/hosts'
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
comt = 'Must provide name to file.blockreplace'
ret.update({'comment': comt, 'name'... |
'Test to comment out specified lines in a file.'
| def test_comment(self):
| with patch.object(os.path, 'exists', MagicMock(return_value=True)):
name = ('/etc/aliases' if salt.utils.platform.is_darwin() else '/etc/fstab')
regex = 'bind 127.0.0.1'
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
comt = 'Must provide ... |
'Test to uncomment specified commented lines in a file'
| def test_uncomment(self):
| with patch.object(os.path, 'exists', MagicMock(return_value=True)):
name = ('/etc/aliases' if salt.utils.platform.is_darwin() else '/etc/fstab')
regex = 'bind 127.0.0.1'
ret = {'name': name, 'pchanges': {}, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide ... |
'Test to ensure that some text appears at the beginning of a file.'
| def test_prepend(self):
| name = '/etc/motd'
source = ['salt://motd/hr-messages.tmpl']
sources = ['salt://motd/devops-messages.tmpl']
text = ['Trust no one unless you have eaten much salt with him.']
ret = {'name': name, 'result': False, 'comment': '', 'pchanges': {}, 'changes': {}}
comt = '... |
'Test to apply a patch to a file.'
| def test_patch(self):
| name = '/opt/file.txt'
source = 'salt://file.patch'
ha_sh = 'md5=e138491e9d5b97023cea823fe17bac22'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.patch'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate... |
'Test to replicate the \'nix "touch" command to create a new empty
file or update the atime and mtime of an existing file.'
| def test_touch(self):
| name = '/var/log/httpd/logrotate.empty'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.touch'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate.touch(''), ret)
mock_t = MagicMock(return_value=True)
mock... |
'Test if the source file exists on the system, copy it to the named file.'
| def test_copy(self):
| name = '/tmp/salt'
source = '/tmp/salt/salt'
user = 'salt'
group = 'saltstack'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.copy'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate.copy('', source)... |
'Test if the source file exists on the system,
rename it to the named file.'
| def test_rename(self):
| name = '/tmp/salt'
source = '/tmp/salt/salt'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.rename'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate.rename('', source), ret)
mock_t = MagicMock(return_v... |
'Test to prepare accumulator which can be used in template in file.'
| def test_accumulated(self):
| with patch('salt.states.file._load_accumulators', MagicMock(return_value=({}, {}))):
with patch('salt.states.file._persist_accummulators', MagicMock(return_value=True)):
name = 'animals_doing_things'
filename = '/tmp/animal_file.txt'
text = ' jumps over the la... |
'Test to create a special file similar to the \'nix mknod command.'
| def test_mknod(self):
| name = '/dev/AA'
ntype = 'a'
ret = {'name': name, 'result': False, 'comment': '', 'changes': {}}
comt = 'Must provide name to file.mknod'
ret.update({'comment': comt, 'name': ''})
self.assertDictEqual(filestate.mknod('', ntype), ret)
comt = "Node type unavailable: 'a'. ... |
'Test to execute the check_cmd logic.'
| def test_mod_run_check_cmd(self):
| cmd = 'A'
filename = 'B'
ret = {'comment': 'check_cmd execution failed', 'result': False, 'skip_watch': True}
mock = MagicMock(side_effect=[{'retcode': 1}, {'retcode': 0}])
with patch.dict(filestate.__salt__, {'cmd.run_all': mock}):
self.assertDictEqual(filestate.mod_run_check_cmd(cmd,... |
'Test to execute the retention_schedule logic.
This test takes advantage of knowing which files it is generating,
which means it can easily generate list of which files it should keep.'
| @skipIf((not HAS_DATEUTIL), NO_DATEUTIL_REASON)
def test_retention_schedule(self):
| def generate_fake_files(format='example_name_%Y%m%dT%H%M%S.tar.bz2', starting=datetime(2016, 2, 8, 9), every=relativedelta(minutes=30), ending=datetime(2015, 12, 25), maxfiles=None):
"\n For starting, make sure that it's over a week f... |
'tests a condition with no rules in present or desired group'
| def test__get_rule_changes_no_rules_no_change(self):
| present_rules = []
desired_rules = []
self.assertEqual(boto_secgroup._get_rule_changes(desired_rules, present_rules), ([], []))
|
'tests a condition where a rule must be created'
| def test__get_rule_changes_create_rules(self):
| present_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')])]
desired_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')]), OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('c... |
'tests a condition where a rule must be deleted'
| def test__get_rule_changes_delete_rules(self):
| present_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('cidr_ip', '0.0.0.0/0')]), OrderedDict([('ip_protocol', 'tcp'), ('from_port', 80), ('to_port', 80), ('cidr_ip', '0.0.0.0/0')])]
desired_rules = [OrderedDict([('ip_protocol', 'tcp'), ('from_port', 22), ('to_port', 22), ('c... |
'Test to verify that the variable is in the ``make.conf``
and has the provided settings.'
| def test_present(self):
| name = 'makeopts'
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
mock_t = MagicMock(return_value=True)
with patch.dict(makeconf.__salt__, {'makeconf.get_var': mock_t}):
comt = 'Variable {0} is already present in make.conf'.format(name)
ret.update({'c... |
'Test to verify that the variable is not in the ``make.conf``.'
| def test_absent(self):
| name = 'makeopts'
ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
mock = MagicMock(return_value=None)
with patch.dict(makeconf.__salt__, {'makeconf.get_var': mock}):
comt = 'Variable {0} is already absent from make.conf'.format(name)
ret.update({'comm... |
'Test to ensure the SQS queue exists.'
| def test_present(self):
| name = 'mysqs'
attributes = {'DelaySeconds': 20}
base_ret = {'name': name, 'changes': {}}
mock = MagicMock(side_effect=[{'result': b} for b in [False, False, True, True]])
mock_bool = MagicMock(return_value={'error': 'create error'})
mock_attr = MagicMock(return_value={'result': {}})
with... |
'Test to ensure the named sqs queue is deleted.'
| def test_absent(self):
| name = 'test.example.com.'
base_ret = {'name': name, 'changes': {}}
mock = MagicMock(side_effect=[{'result': False}, {'result': True}])
with patch.dict(boto_sqs.__salt__, {'boto_sqs.exists': mock}):
comt = 'SQS queue {0} does not exist in None.'.format(name)
ret = ba... |
'Test to verify that the specified ruby is installed with rbenv.'
| def test_installed(self):
| name = 'rbenv-deps'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock_t = MagicMock(side_effect=[False, True, True])
mock_f = MagicMock(return_value=False)
mock_def = MagicMock(return_value='2.7')
mock_ver = MagicMock(return_value=['2.7'])
with patch.dict(rbenv.__salt__... |
'Test to verify that the specified ruby is not installed with rbenv.'
| def test_absent(self):
| name = 'myqueue'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(side_effect=[False, True])
mock_def = MagicMock(return_value='2.7')
mock_ver = MagicMock(return_value=['2.7'])
with patch.dict(rbenv.__salt__, {'rbenv.is_installed': mock, 'rbenv.default': mock_d... |
'Test to install rbenv if not installed.'
| def test_install_rbenv(self):
| name = 'myqueue'
ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
with patch.dict(rbenv.__opts__, {'test': True}):
comt = 'Rbenv is set to be installed'
ret.update({'comment': comt, 'result': None})
self.assertDictEqual(rbenv.install_rbenv(name), ret)... |
'Test to ensures that the named command is not running.'
| def test_absent(self):
| name = 'apache2'
ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''}
mock = MagicMock(return_value='')
with patch.dict(process.__salt__, {'ps.pgrep': mock, 'ps.pkill': mock}):
with patch.dict(process.__opts__, {'test': True}):
comt = 'No matching processes run... |
'Test to perform an HTTP query and statefully return the result'
| def test_query(self):
| ret = [{'changes': {}, 'comment': ' Either match text (match) or a status code (status) is required.', 'data': {}, 'name': 'salt', 'result': False}, {'changes': {}, 'comment': ' (TEST MODE)', 'data': True, 'name': 'salt', 'result': None}]
self.assertDictEqual(http.query('s... |
'Test to ensure that the named schema is present in the database.'
| def test_present(self):
| name = 'myname'
dbname = 'mydb'
ret = {'name': name, 'dbname': dbname, 'changes': {}, 'result': True, 'comment': ''}
mock = MagicMock(return_value=name)
with patch.dict(postgres_schema.__salt__, {'postgres.schema_get': mock}):
with patch.dict(postgres_schema.__opts__, {'test': False}):
... |
'Test to ensure that the named schema is absent.'
| def test_absent(self):
| name = 'myname'
dbname = 'mydb'
ret = {'name': name, 'dbname': dbname, 'changes': {}, 'result': True, 'comment': ''}
mock_t = MagicMock(side_effect=[True, False])
mock = MagicMock(side_effect=[True, True, True, False])
with patch.dict(postgres_schema.__salt__, {'postgres.schema_exists': mock, 'p... |
'Test to send a message to a Hipchat room.'
| def test_send_message(self):
| name = 'salt'
room_id = '123456'
from_name = 'SuperAdmin'
message = 'This state was executed successfully.'
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
with patch.dict(hipchat.__opts__, {'test': True}):
comt = 'The following message is to ... |
'Test - Manage the SNMP sysContact, sysLocation, and sysServices settings.'
| def test_agent_settings(self):
| kwargs = {'name': 'agent-settings', 'contact': 'TestContact', 'location': 'TestLocation', 'services': ['Internet']}
ret = {'name': kwargs['name'], 'changes': {}, 'comment': 'Agent settings already contain the provided values.', 'result': True}
get_ret = dict(((key, value) for (key, value) ... |
'Test - Manage the sending of authentication traps.'
| def test_auth_traps_enabled(self):
| kwargs = {'name': 'auth-traps', 'status': True}
ret = {'name': kwargs['name'], 'changes': {'old': False, 'new': True}, 'comment': 'Set EnableAuthenticationTraps to contain the provided value.', 'result': True}
mock_value_get = MagicMock(return_value=False)
mock_value_set = MagicMock(re... |
'Test - Manage the SNMP accepted community names and their permissions.'
| def test_community_names(self):
| kwargs = {'name': 'community-names', 'communities': {'TestCommunity': 'Read Create'}}
ret = {'name': kwargs['name'], 'changes': {}, 'comment': 'Communities already contain the provided values.', 'result': True}
mock_value_get = MagicMock(return_value=kwargs['communities'])
mock_value_s... |
'Test to create a virtualenv and optionally manage it with pip'
| def test_managed(self):
| ret = {'name': 'salt', 'changes': {}, 'result': False, 'comment': ''}
ret.update({'comment': 'Virtualenv was not detected on this system'})
self.assertDictEqual(virtualenv_mod.managed('salt'), ret)
mock1 = MagicMock(return_value='True')
mock = MagicMock(return_value=False)
mock... |
'Test adding a certificate to specified certificate store'
| def test_add_serial(self):
| expected = {'changes': {'added': '/path/to/cert.cer'}, 'comment': '', 'name': '/path/to/cert.cer', 'result': True}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456'])
add_mock = Magic... |
'Test adding a certificate to specified certificate store when the file doesn\'t exist'
| def test_add_serial_missing(self):
| expected = {'changes': {}, 'comment': 'Certificate file not found.', 'name': '/path/to/cert.cer', 'result': False}
cache_mock = MagicMock(return_value=False)
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456'])
add_mock = MagicM... |
'Test adding a certificate to specified certificate store when the cert already exists'
| def test_add_serial_exists(self):
| expected = {'changes': {}, 'comment': '/path/to/cert.cer already stored.', 'name': '/path/to/cert.cer', 'result': True}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456', 'ABCDEF'])... |
'Test adding a certificate when the add fails'
| def test_add_serial_fail(self):
| expected = {'changes': {}, 'comment': 'Failed to store certificate /path/to/cert.cer', 'name': '/path/to/cert.cer', 'result': False}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['... |
'Test deleting a certificate from a specified certificate store'
| def test_del_serial(self):
| expected = {'changes': {'removed': '/path/to/cert.cer'}, 'comment': '', 'name': '/path/to/cert.cer', 'result': True}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456', 'ABCDEF'])
del_... |
'Test deleting a certificate to specified certificate store when the file doesn\'t exist'
| def test_del_serial_missing(self):
| expected = {'changes': {}, 'comment': 'Certificate file not found.', 'name': '/path/to/cert.cer', 'result': False}
cache_mock = MagicMock(return_value=False)
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456'])
del_mock = MagicM... |
'Test deleting a certificate to specified certificate store when the cert doesn\'t exists'
| def test_del_serial_doesnt_exists(self):
| expected = {'changes': {}, 'comment': '/path/to/cert.cer already removed.', 'name': '/path/to/cert.cer', 'result': True}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_value=['123456'])
del_... |
'Test deleting a certificate from the store when the delete fails'
| def test_del_serial_fail(self):
| expected = {'changes': {}, 'comment': 'Failed to remove the certificate /path/to/cert.cer', 'name': '/path/to/cert.cer', 'result': False}
cache_mock = MagicMock(return_value='/tmp/cert.cer')
get_cert_serial_mock = MagicMock(return_value='ABCDEF')
get_store_serials_mock = MagicMock(return_... |
'Test to ensure that the named database is absent.'
| def test_absent(self):
| name = 'mydb'
ret = {'name': name, 'result': None, 'comment': '', 'changes': {}}
mock = MagicMock(side_effect=[True, True, False])
mock_t = MagicMock(return_value=True)
with patch.dict(mongodb_database.__salt__, {'mongodb.db_exists': mock, 'mongodb.db_remove': mock_t}):
with patch.dict(mongo... |
'Setup data for the tests'
| def setUp(self):
| self.name = 'plpgsql'
self.ret = {'name': self.name, 'changes': {}, 'result': False, 'comment': ''}
self.mock_true = MagicMock(return_value=True)
self.mock_false = MagicMock(return_value=False)
self.mock_empty_language_list = MagicMock(return_value={})
self.mock_language_list = MagicMock(return_... |
'Test present, language is already present in database'
| def test_present_existing(self):
| with patch.dict(postgres_language.__salt__, {'postgres.language_list': self.mock_language_list}):
comt = 'Language {0} is already installed'.format(self.name)
self.ret.update({'comment': comt, 'result': True})
self.assertDictEqual(postgres_language.present(self.name, 'testdb'), s... |
'Test present, language not present in database - pass'
| def test_present_non_existing_pass(self):
| with patch.dict(postgres_language.__salt__, {'postgres.language_list': self.mock_empty_language_list, 'postgres.language_create': self.mock_true}):
with patch.dict(postgres_language.__opts__, {'test': True}):
comt = 'Language {0} is set to be installed'.format(self.name)
... |
'Test present, language not present in database - fail'
| def test_present_non_existing_fail(self):
| with patch.dict(postgres_language.__salt__, {'postgres.language_list': self.mock_empty_language_list, 'postgres.language_create': self.mock_false}):
with patch.dict(postgres_language.__opts__, {'test': True}):
comt = 'Language {0} is set to be installed'.format(self.name)
... |
'Test absent, language present in database'
| def test_absent_existing(self):
| with patch.dict(postgres_language.__salt__, {'postgres.language_exists': self.mock_true, 'postgres.language_remove': self.mock_true}):
with patch.dict(postgres_language.__opts__, {'test': True}):
comt = 'Language {0} is set to be removed'.format(self.name)
self.ret.... |
'Test absent, language not present in database'
| def test_absent_non_existing(self):
| with patch.dict(postgres_language.__salt__, {'postgres.language_exists': self.mock_false}):
with patch.dict(postgres_language.__opts__, {'test': True}):
comt = 'Language {0} is not present so it cannot be removed'.format(self.name)
self.ret.update({'comment... |
'Test to ensure key pair is present.'
| def test_key_present(self):
| name = 'mykeypair'
upublic = 'salt://mybase/public_key.pub'
ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[True, False, False])
mock_bool = MagicMock(side_effect=[IOError, True])
with patch.dict(boto_ec2.__salt__, {'boto_ec2.get_key': mock, 'cp.g... |
'Test to deletes a key pair'
| def test_key_absent(self):
| name = 'new_table'
ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''}
mock = MagicMock(side_effect=[False, True])
with patch.dict(boto_ec2.__salt__, {'boto_ec2.get_key': mock}):
comt = 'The key name {0} does not exist'.format(name)
ret.update({'comment':... |
'Test to ensure that the named user is present
with the specified privileges.'
| def test_present(self):
| name = 'frank'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_t = MagicMock(return_value=True)
mock = MagicMock(return_value=None)
with patch.dict(postgres_user.__salt__, {'postgres.role_get': mock, 'postgres.user_create': mock_t}):
with patch.dict(postgres_user.__o... |
'Test to ensure that the named user is absent.'
| def test_absent(self):
| name = 'frank'
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
mock_t = MagicMock(return_value=True)
mock = MagicMock(side_effect=[True, True, False])
with patch.dict(postgres_user.__salt__, {'postgres.user_exists': mock, 'postgres.user_remove': mock_t}):
with patch.dict(... |
'scenario of creating upgrading extensions with possible schema and
version specifications'
| def test_present_failed(self):
| with patch.dict(postgres_extension.__salt__, {'postgres.create_metadata': Mock(side_effect=[[postgresmod._EXTENSION_NOT_INSTALLED], [postgresmod._EXTENSION_TO_MOVE, postgresmod._EXTENSION_INSTALLED]]), 'postgres.create_extension': Mock(side_effect=[False, False])}):
ret = postgres_extension.present('foo')
... |
'scenario of creating upgrading extensions with possible schema and
version specifications'
| def test_present(self):
| with patch.dict(postgres_extension.__salt__, {'postgres.create_metadata': Mock(side_effect=[[postgresmod._EXTENSION_NOT_INSTALLED], [postgresmod._EXTENSION_INSTALLED], [postgresmod._EXTENSION_TO_MOVE, postgresmod._EXTENSION_INSTALLED]]), 'postgres.create_extension': Mock(side_effect=[True, True, True])}):
r... |
'scenario of creating upgrading extensions with possible schema and
version specifications'
| def test_presenttest(self):
| with patch.dict(postgres_extension.__salt__, {'postgres.create_metadata': Mock(side_effect=[[postgresmod._EXTENSION_NOT_INSTALLED], [postgresmod._EXTENSION_INSTALLED], [postgresmod._EXTENSION_TO_MOVE, postgresmod._EXTENSION_INSTALLED]]), 'postgres.create_extension': Mock(side_effect=[True, True, True])}):
w... |
'scenario of creating upgrading extensions with possible schema and
version specifications'
| def test_absent(self):
| with patch.dict(postgres_extension.__salt__, {'postgres.is_installed_extension': Mock(side_effect=[True, False]), 'postgres.drop_extension': Mock(side_effect=[True, True])}):
ret = postgres_extension.absent('foo')
self.assertEqual(ret, {'comment': 'Extension foo has been removed', 'chang... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.