desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test to clean the version string removing extra data.'
def test_version_clean(self):
with patch.dict(pkg_resource.__salt__, {'pkg.version_clean': MagicMock(return_value='A')}): self.assertEqual(pkg_resource.version_clean('version'), 'A') self.assertEqual(pkg_resource.version_clean('v'), 'v')
'Test to check if the installed package already has the given requirements.'
def test_check_extra_requirements(self):
with patch.dict(pkg_resource.__salt__, {'pkg.check_extra_requirements': MagicMock(return_value='A')}): self.assertEqual(pkg_resource.check_extra_requirements('a', 'b'), 'A') self.assertTrue(pkg_resource.check_extra_requirements('a', False))
'Tests return the hosts found in the hosts file'
def test_list_hosts(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value={'10.10.10.10': ['Salt1', 'Salt2']})): self.assertDictEqual({'10.10.10.10': ['Salt1', 'Salt2']}, hosts.list_hosts())
'Tests return ip associated with the named host'
def test_get_ip(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value={'10.10.10.10': ['Salt1', 'Salt2']})): self.assertEqual('10.10.10.10', hosts.get_ip('Salt1')) self.assertEqual('', hosts.get_ip('Salt3'))
'Tests return ip associated with the named host'
def test_get_ip_none(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value='')): self.assertEqual('', hosts.get_ip('Salt1'))
'Tests return the list of aliases associated with an ip'
def test_get_alias(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value={'10.10.10.10': ['Salt1', 'Salt2']})): self.assertListEqual(['Salt1', 'Salt2'], hosts.get_alias('10.10.10.10'))
'Tests return the list of aliases associated with an ip'
def test_get_alias_none(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value={'10.10.10.10': ['Salt1', 'Salt2']})): self.assertListEqual([], hosts.get_alias('10.10.10.11'))
'Tests return True / False if the alias is set'
def test_has_pair(self):
with patch('salt.modules.hosts._list_hosts', MagicMock(return_value={'10.10.10.10': ['Salt1', 'Salt2']})): self.assertTrue(hosts.has_pair('10.10.10.10', 'Salt1')) self.assertFalse(hosts.has_pair('10.10.10.10', 'Salt3'))
'Tests true if the alias is set'
def test_set_host(self):
with patch('salt.modules.hosts.__get_hosts_filename', MagicMock(return_value='/etc/hosts')): with patch('os.path.isfile', MagicMock(return_value=False)): with patch.dict(hosts.__salt__, {'config.option': MagicMock(return_value=None)}): self.assertFalse(hosts.set_host('10.10.10.10', 'Salt1'))
'Tests true if the alias is set'
def test_set_host_true(self):
with patch('salt.modules.hosts.__get_hosts_filename', MagicMock(return_value='/etc/hosts')): with patch('os.path.isfile', MagicMock(return_value=True)): with patch('salt.utils.files.fopen', mock_open()): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertTrue(hosts.set_host('10.10.10.10', 'Salt1'))
'Test if an empty hosts value removes existing entries'
def test_set_host_true_remove(self):
with patch('salt.modules.hosts.__get_hosts_filename', MagicMock(return_value='/etc/hosts')): with patch('os.path.isfile', MagicMock(return_value=True)): data = ['\n'.join(('1.1.1.1 foo.foofoo foo', '2.2.2.2 bar.barbar bar', '3.3.3.3 asdf.asdfadsf asdf', '1.1.1.1 foofoo.foofoo foofoo'))] class TmpStringIO(StringIO, ): def __init__(self, fn, mode='r'): initial_value = data[0] if ('w' in mode): initial_value = '' StringIO.__init__(self, initial_value) def __enter__(self): return self def __exit__(self, exc_type, exc_value, traceback): self.close() def close(self): data[0] = self.getvalue() StringIO.close(self) expected = ('\n'.join(('2.2.2.2 bar.barbar bar', '3.3.3.3 asdf.asdfadsf asdf')) + '\n') with patch('salt.utils.files.fopen', TmpStringIO): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertTrue(hosts.set_host('1.1.1.1', ' ')) self.assertEqual(data[0], expected)
'Tests if specified host entry gets removed from the hosts file'
def test_rm_host(self):
with patch('salt.utils.files.fopen', mock_open()): with patch('salt.modules.hosts.__get_hosts_filename', MagicMock(return_value='/etc/hosts')): with patch('salt.modules.hosts.has_pair', MagicMock(return_value=True)): with patch('os.path.isfile', MagicMock(return_value=True)): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertTrue(hosts.rm_host('10.10.10.10', 'Salt1'))
'Tests if specified host entry gets removed from the hosts file'
def test_rm_host_false(self):
with patch('salt.modules.hosts.has_pair', MagicMock(return_value=False)): self.assertTrue(hosts.rm_host('10.10.10.10', 'Salt1'))
'Tests if specified host entry gets added from the hosts file'
def test_add_host(self):
with patch('salt.utils.files.fopen', mock_open()): with patch('salt.modules.hosts.__get_hosts_filename', MagicMock(return_value='/etc/hosts')): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertTrue(hosts.add_host('10.10.10.10', 'Salt1'))
'Tests if specified host entry gets added from the hosts file'
def test_add_host_no_file(self):
with patch('salt.utils.files.fopen', mock_open()): with patch('os.path.isfile', MagicMock(return_value=False)): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertFalse(hosts.add_host('10.10.10.10', 'Salt1'))
'Tests if specified host entry gets added from the hosts file'
def test_add_host_create_entry(self):
with patch('salt.utils.files.fopen', mock_open()): with patch('os.path.isfile', MagicMock(return_value=True)): mock_opt = MagicMock(return_value=None) with patch.dict(hosts.__salt__, {'config.option': mock_opt}): self.assertTrue(hosts.add_host('10.10.10.10', 'Salt1'))
'Test if it purge all the jobs currently scheduled on the minion.'
def test_purge(self):
with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.purge(), {'comment': ['Deleted job: schedule from schedule.'], 'result': True})
'Test if it delete a job from the minion\'s schedule.'
def test_delete(self):
with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.delete('job1'), {'comment': 'Job job1 does not exist.', 'result': False})
'Test if it build a schedule job.'
def test_build_schedule_item(self):
comment = 'Unable to use "seconds", "minutes", "hours", or "days" with "when" or "cron" options.' comment1 = 'Unable to use "when" and "cron" options together. Ignoring.' with patch.dict(schedule.__opts__, {'job1': {}}): self.assertDictEqual(schedule.build_schedule_item(''), {'comment': 'Job name is required.', 'result': False}) self.assertDictEqual(schedule.build_schedule_item('job1', function='test.ping'), {'function': 'test.ping', 'maxrunning': 1, 'name': 'job1', 'jid_include': True, 'enabled': True}) self.assertDictEqual(schedule.build_schedule_item('job1', function='test.ping', seconds=3600, when='2400'), {'comment': comment, 'result': False}) self.assertDictEqual(schedule.build_schedule_item('job1', function='test.ping', when='2400', cron='2'), {'comment': comment1, 'result': False})
'Test if it add a job to the schedule.'
def test_add(self):
comm1 = 'Job job1 already exists in schedule.' comm2 = 'Error: Unable to use "seconds", "minutes", "hours", or "days" with "when" or "cron" options.' comm3 = 'Unable to use "when" and "cron" options together. Ignoring.' comm4 = 'Job: job2 would be added to schedule.' with patch.dict(schedule.__opts__, {'schedule': {'job1': 'salt'}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': {'salt': 'salt'}}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.add('job1'), {'comment': comm1, 'result': False}) _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.add('job2', function='test.ping', seconds=3600, when='2400'), {'comment': comm2, 'result': False}) _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.add('job2', function='test.ping', when='2400', cron='2'), {'comment': comm3, 'result': False}) _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.add('job2', function='test.ping', test=True), {'comment': comm4, 'result': True})
'Test if it run a scheduled job on the minion immediately.'
def test_run_job(self):
with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.run_job('job1'), {'comment': 'Job job1 does not exist.', 'result': False})
'Test if it enable a job in the minion\'s schedule.'
def test_enable_job(self):
with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.enable_job('job1'), {'comment': 'Job job1 does not exist.', 'result': False})
'Test if it disable a job in the minion\'s schedule.'
def test_disable_job(self):
with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.disable_job('job1'), {'comment': 'Job job1 does not exist.', 'result': False})
'Test if it save all scheduled jobs on the minion.'
def test_save(self):
comm1 = 'Schedule (non-pillar items) saved.' with patch.dict(schedule.__opts__, {'config_dir': '', 'schedule': {}, 'default_include': '/tmp', 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): self.assertDictEqual(schedule.save(), {'comment': comm1, 'result': True})
'Test if it enable all scheduled jobs on the minion.'
def test_enable(self):
self.assertDictEqual(schedule.enable(test=True), {'comment': 'Schedule would be enabled.', 'result': True})
'Test if it disable all scheduled jobs on the minion.'
def test_disable(self):
self.assertDictEqual(schedule.disable(test=True), {'comment': 'Schedule would be disabled.', 'result': True})
'Test if it move scheduled job to another minion or minions.'
def test_move(self):
comm1 = 'no servers answered the published schedule.add command' comm2 = 'the following minions return False' comm3 = 'Moved Job job1 from schedule.' with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': JOB1}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): mock = MagicMock(return_value={}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm1, 'result': True}) mock = MagicMock(return_value={'minion1': ''}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm2, 'minions': ['minion1'], 'result': True}) mock = MagicMock(return_value={'minion1': 'job1'}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm3, 'minions': ['minion1'], 'result': True}) self.assertDictEqual(schedule.move('job3', 'minion1'), {'comment': 'Job job3 does not exist.', 'result': False}) mock = MagicMock(side_effect=[{}, {'job1': {}}]) with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': JOB1}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): with patch.dict(schedule.__pillar__, {'schedule': {'job1': JOB1}}): mock = MagicMock(return_value={}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm1, 'result': True}) mock = MagicMock(return_value={'minion1': ''}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm2, 'minions': ['minion1'], 'result': True}) mock = MagicMock(return_value={'minion1': 'job1'}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): self.assertDictEqual(schedule.move('job1', 'minion1'), {'comment': comm3, 'minions': ['minion1'], 'result': True})
'Test if it copy scheduled job to another minion or minions.'
def test_copy(self):
comm1 = 'no servers answered the published schedule.add command' comm2 = 'the following minions return False' comm3 = 'Copied Job job1 from schedule to minion(s).' with patch.dict(schedule.__opts__, {'schedule': {'job1': JOB1}, 'sock_dir': SOCK_DIR}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': {'job1': JOB1}}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): mock = MagicMock(return_value={}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm1, 'result': True}) mock = MagicMock(return_value={'minion1': ''}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm2, 'minions': ['minion1'], 'result': True}) mock = MagicMock(return_value={'minion1': 'job1'}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm3, 'minions': ['minion1'], 'result': True}) self.assertDictEqual(schedule.copy('job3', 'minion1'), {'comment': 'Job job3 does not exist.', 'result': False}) mock = MagicMock(side_effect=[{}, {'job1': {}}]) with patch.dict(schedule.__opts__, {'schedule': mock, 'sock_dir': SOCK_DIR}): with patch.dict(schedule.__pillar__, {'schedule': {'job1': JOB1}}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): _ret_value = {'complete': True, 'schedule': {'job1': {'job1': JOB1}}} with patch.object(SaltEvent, 'get_event', return_value=_ret_value): mock = MagicMock(return_value={}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm1, 'result': True}) mock = MagicMock(return_value={'minion1': ''}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm2, 'minions': ['minion1'], 'result': True}) mock = MagicMock(return_value={'minion1': 'job1'}) with patch.dict(schedule.__salt__, {'publish.publish': mock}): mock = MagicMock(return_value=True) with patch.dict(schedule.__salt__, {'event.fire': mock}): self.assertDictEqual(schedule.copy('job1', 'minion1'), {'comment': comm3, 'minions': ['minion1'], 'result': True})
'Test if it performs a ping to a host.'
def test_ping(self):
mock = MagicMock(return_value=True) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertTrue(win_network.ping('127.0.0.1'))
'Test if it return information on open ports and states'
def test_netstat(self):
ret = ' Proto Local Address Foreign Address State PID\n TCP 127.0.0.1:1434 0.0.0.0:0 LISTENING 1728\n UDP 127.0.0.1:1900 *:* 4240' mock = MagicMock(return_value=ret) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertListEqual(win_network.netstat(), [{'local-address': '127.0.0.1:1434', 'program': '1728', 'proto': 'TCP', 'remote-address': '0.0.0.0:0', 'state': 'LISTENING'}, {'local-address': '127.0.0.1:1900', 'program': '4240', 'proto': 'UDP', 'remote-address': '*:*', 'state': None}])
'Test if it performs a traceroute to a 3rd party host'
def test_traceroute(self):
ret = ' 1 1 ms <1 ms <1 ms 172.27.104.1\n 2 1 ms <1 ms 1 ms 121.242.35.1.s[121.242.35.1]\n 3 3 ms 2 ms 2 ms 121.242.4.53.s[121.242.4.53]\n' mock = MagicMock(return_value=ret) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertListEqual(win_network.traceroute('google.com'), [{'count': '1', 'hostname': None, 'ip': '172.27.104.1', 'ms1': '1', 'ms2': '<1', 'ms3': '<1'}, {'count': '2', 'hostname': None, 'ip': '121.242.35.1.s[121.242.35.1]', 'ms1': '1', 'ms2': '<1', 'ms3': '1'}, {'count': '3', 'hostname': None, 'ip': '121.242.4.53.s[121.242.4.53]', 'ms1': '3', 'ms2': '2', 'ms3': '2'}])
'Test if it query DNS for information about a domain or ip address'
def test_nslookup(self):
ret = 'Server: ct-dc-3-2.cybage.com\nAddress: 172.27.172.12\nNon-authoritative answer:\nName: google.com\nAddresses: 2404:6800:4007:806::200e\n216.58.196.110\n' mock = MagicMock(return_value=ret) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertListEqual(win_network.nslookup('google.com'), [{'Server': 'ct-dc-3-2.cybage.com'}, {'Address': '172.27.172.12'}, {'Name': 'google.com'}, {'Addresses': ['2404:6800:4007:806::200e', '216.58.196.110']}])
'Test if it performs a DNS lookup with dig'
def test_dig(self):
mock = MagicMock(return_value=True) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertTrue(win_network.dig('google.com'))
'Test if it return a list of all the interfaces names'
def test_interfaces_names(self):
self.WMI.Win32_NetworkAdapter = MagicMock(return_value=Mockwmi) with patch('salt.utils.winapi.Com', MagicMock()): with patch.object(self.WMI, 'Win32_NetworkAdapter', return_value=[Mockwmi()]): with patch('salt.utils', Mockwinapi): self.assertListEqual(win_network.interfaces_names(), ['Ethernet'])
'Test if it return information about all the interfaces on the minion'
def test_interfaces(self):
with patch.object(salt.utils.network, 'win_interfaces', MagicMock(return_value=True)): self.assertTrue(win_network.interfaces())
'Test if it return the hardware address (a.k.a. MAC address) for a given interface'
def test_hw_addr(self):
with patch.object(salt.utils.network, 'hw_addr', MagicMock(return_value='Ethernet')): self.assertEqual(win_network.hw_addr('Ethernet'), 'Ethernet')
'Test if it returns a list of subnets to which the host belongs'
def test_subnets(self):
with patch.object(salt.utils.network, 'subnets', MagicMock(return_value='10.1.1.0/24')): self.assertEqual(win_network.subnets(), '10.1.1.0/24')
'Test if it returns True if host is within specified subnet, otherwise False'
def test_in_subnet(self):
with patch.object(salt.utils.network, 'in_subnet', MagicMock(return_value=True)): self.assertTrue(win_network.in_subnet('10.1.1.0/16'))
'Test if it return information on open ports and states'
def test_get_route(self):
ret = '\n\nIPAddress : 10.0.0.15\nInterfaceIndex : 3\nInterfaceAlias : Wi-Fi\nAddressFamily : IPv4\nType : Unicast\nPrefixLength : 24\nPrefixOrigin : Dhcp\nSuffixOrigin : Dhcp\nAddressState : Preferred\nValidLifetime : 6.17:52:39\nPreferredLifetime : 6.17:52:39\nSkipAsSource : False\nPolicyStore : ActiveStore\n\n\nCaption :\nDescription :\nElementName :\nInstanceID : :8:8:8:9:55=55;:8;8;:8;55;\nAdminDistance :\nDestinationAddress :\nIsStatic :\nRouteMetric : 0\nTypeOfRoute : 3\nAddressFamily : IPv4\nCompartmentId : 1\nDestinationPrefix : 0.0.0.0/0\nInterfaceAlias : Wi-Fi\nInterfaceIndex : 3\nNextHop : 10.0.0.1\nPreferredLifetime : 6.23:14:43\nProtocol : NetMgmt\nPublish : No\nStore : ActiveStore\nValidLifetime : 6.23:14:43\nPSComputerName :\nifIndex : 3' mock = MagicMock(return_value=ret) with patch.dict(win_network.__salt__, {'cmd.run': mock}): self.assertDictEqual(win_network.get_route('192.0.0.8'), {'destination': '192.0.0.8', 'gateway': '10.0.0.1', 'interface': 'Wi-Fi', 'source': '10.0.0.15'})
'Test for Get all mine data for \'docker.ps\' and run an aggregation.'
def test_get_docker(self):
ps_response = {'localhost': {'host': {'interfaces': {'docker0': {'hwaddr': '88:99:00:00:99:99', 'inet': [{'address': '172.17.42.1', 'broadcast': None, 'label': 'docker0', 'netmask': '255.255.0.0'}], 'inet6': [{'address': 'ffff::eeee:aaaa:bbbb:8888', 'prefixlen': '64'}], 'up': True}, 'eth0': {'hwaddr': '88:99:00:99:99:99', 'inet': [{'address': '192.168.0.1', 'broadcast': '192.168.0.255', 'label': 'eth0', 'netmask': '255.255.255.0'}], 'inet6': [{'address': 'ffff::aaaa:aaaa:bbbb:8888', 'prefixlen': '64'}], 'up': True}}}, 'abcdefhjhi1234567899': {'Ports': [{'IP': '0.0.0.0', 'PrivatePort': 80, 'PublicPort': 80, 'Type': 'tcp'}], 'Image': 'image:latest', 'Info': {'Id': 'abcdefhjhi1234567899'}}}} with patch.object(mine, 'get', return_value=ps_response): ret = mine.get_docker() ret['image:latest']['ipv4'][80] = sorted(ret['image:latest']['ipv4'][80]) self.assertEqual(ret, {'image:latest': {'ipv4': {80: sorted(['172.17.42.1:80', '192.168.0.1:80'])}}})
'Test for Get all mine data for \'docker.ps\' and run an aggregation.'
def test_get_docker_with_container_id(self):
ps_response = {'localhost': {'host': {'interfaces': {'docker0': {'hwaddr': '88:99:00:00:99:99', 'inet': [{'address': '172.17.42.1', 'broadcast': None, 'label': 'docker0', 'netmask': '255.255.0.0'}], 'inet6': [{'address': 'ffff::eeee:aaaa:bbbb:8888', 'prefixlen': '64'}], 'up': True}, 'eth0': {'hwaddr': '88:99:00:99:99:99', 'inet': [{'address': '192.168.0.1', 'broadcast': '192.168.0.255', 'label': 'eth0', 'netmask': '255.255.255.0'}], 'inet6': [{'address': 'ffff::aaaa:aaaa:bbbb:8888', 'prefixlen': '64'}], 'up': True}}}, 'abcdefhjhi1234567899': {'Ports': [{'IP': '0.0.0.0', 'PrivatePort': 80, 'PublicPort': 80, 'Type': 'tcp'}], 'Image': 'image:latest', 'Info': {'Id': 'abcdefhjhi1234567899'}}}} with patch.object(mine, 'get', return_value=ps_response): ret = mine.get_docker(with_container_id=True) ret['image:latest']['ipv4'][80] = sorted(ret['image:latest']['ipv4'][80]) self.assertEqual(ret, {'image:latest': {'ipv4': {80: sorted([('172.17.42.1:80', 'abcdefhjhi1234567899'), ('192.168.0.1:80', 'abcdefhjhi1234567899')])}}})
'Test xattr.list'
def test_list(self):
expected = {'spongebob': 'squarepants', 'squidward': 'patrick'} with patch.object(xattr, 'read', MagicMock(side_effect=['squarepants', 'patrick'])): with patch('salt.utils.mac_utils.execute_return_result', MagicMock(return_value='spongebob\nsquidward')): self.assertEqual(xattr.list_('path/to/file'), expected)
'Test listing attributes of a missing file'
def test_list_missing(self):
with patch('salt.utils.mac_utils.execute_return_result', MagicMock(side_effect=CommandExecutionError('No such file'))): self.assertRaises(CommandExecutionError, xattr.list_, '/path/to/file')
'Test reading a specific attribute from a file'
def test_read(self):
with patch('salt.utils.mac_utils.execute_return_result', MagicMock(return_value='expected results')): self.assertEqual(xattr.read('/path/to/file', 'com.attr'), 'expected results')
'Test reading a specific attribute from a file'
def test_read_hex(self):
with patch.object(salt.utils.mac_utils, 'execute_return_result', MagicMock(return_value='expected results')) as mock: self.assertEqual(xattr.read('/path/to/file', 'com.attr', **{'hex': True}), 'expected results') mock.assert_called_once_with(['xattr', '-p', '-x', 'com.attr', '/path/to/file'])
'Test reading a specific attribute from a file'
def test_read_missing(self):
with patch('salt.utils.mac_utils.execute_return_result', MagicMock(side_effect=CommandExecutionError('No such file'))): self.assertRaises(CommandExecutionError, xattr.read, '/path/to/file', 'attribute')
'Test writing a specific attribute to a file'
def test_write(self):
mock_cmd = MagicMock(return_value='squarepants') with patch.object(xattr, 'read', mock_cmd): with patch('salt.utils.mac_utils.execute_return_success', MagicMock(return_value=True)): self.assertTrue(xattr.write('/path/to/file', 'spongebob', 'squarepants'))
'Test writing a specific attribute to a file'
def test_write_missing(self):
with patch('salt.utils.mac_utils.execute_return_success', MagicMock(side_effect=CommandExecutionError('No such file'))): self.assertRaises(CommandExecutionError, xattr.write, '/path/to/file', 'attribute', 'value')
'Test deleting a specific attribute from a file'
def test_delete(self):
mock_cmd = MagicMock(return_value={'spongebob': 'squarepants'}) with patch.object(xattr, 'list_', mock_cmd): with patch('salt.utils.mac_utils.execute_return_success', MagicMock(return_value=True)): self.assertTrue(xattr.delete('/path/to/file', 'attribute'))
'Test deleting a specific attribute from a file'
def test_delete_missing(self):
with patch('salt.utils.mac_utils.execute_return_success', MagicMock(side_effect=CommandExecutionError('No such file'))): self.assertRaises(CommandExecutionError, xattr.delete, '/path/to/file', 'attribute')
'Test clearing all attributes on a file'
def test_clear(self):
mock_cmd = MagicMock(return_value={}) with patch.object(xattr, 'list_', mock_cmd): with patch('salt.utils.mac_utils.execute_return_success', MagicMock(return_value=True)): self.assertTrue(xattr.clear('/path/to/file'))
'Test clearing all attributes on a file'
def test_clear_missing(self):
with patch('salt.utils.mac_utils.execute_return_success', MagicMock(side_effect=CommandExecutionError('No such file'))): self.assertRaises(CommandExecutionError, xattr.clear, '/path/to/file')
'Test if it execute a chef client run and return a dict'
def test_client(self):
self.assertDictEqual(chef.client(), {})
'Test if it execute a chef solo run and return a dict'
def test_solo(self):
self.assertDictEqual(chef.solo('/dev/sda1'), {})
'Test - Return return the latest installed kernel version'
def test_list_installed(self):
PACKAGE_LIST = ['{0}-{1}'.format(kernelpkg._package_prefix(), kernel) for kernel in self.KERNEL_LIST] mock = MagicMock(return_value=PACKAGE_LIST) with patch.dict(self._kernelpkg.__salt__, {'pkg.list_pkgs': mock}): self.assertListEqual(self._kernelpkg.list_installed(), self.KERNEL_LIST)
'Test - Return return the latest installed kernel version'
def test_list_installed_none(self):
mock = MagicMock(return_value=None) with patch.dict(self._kernelpkg.__salt__, {'pkg.list_pkgs': mock}): self.assertListEqual(self._kernelpkg.list_installed(), [])
'Test if it install pyenv systemwide'
def test_install(self):
mock_opt = MagicMock(return_value='salt stack') mock_ret = MagicMock(return_value=0) with patch.dict(pyenv.__salt__, {'config.option': mock_opt, 'cmd.retcode': mock_ret}): self.assertTrue(pyenv.install())
'Test if it updates the current versions of pyenv and python-Build'
def test_update(self):
mock_opt = MagicMock(return_value='salt stack') with patch.dict(pyenv.__salt__, {'config.option': mock_opt}): self.assertFalse(pyenv.update())
'Test if it check if pyenv is installed.'
def test_is_installed(self):
mock_cmd = MagicMock(return_value=True) mock_opt = MagicMock(return_value='salt stack') with patch.dict(pyenv.__salt__, {'config.option': mock_opt, 'cmd.has_exec': mock_cmd}): self.assertTrue(pyenv.is_installed())
'Test if it install a python implementation.'
def test_install_python(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': 0, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__grains__, {'os': 'Linux'}): mock_all = MagicMock(return_value={'retcode': 0, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'config.option': mock_opt, 'cmd.has_exec': mock_cmd, 'cmd.run_all': mock_all}): self.assertEqual(pyenv.install_python('2.0.0-p0'), 'error') mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'config.option': mock_opt, 'cmd.has_exec': mock_cmd, 'cmd.run_all': mock_all}): self.assertFalse(pyenv.install_python('2.0.0-p0'))
'Test if it uninstall a python implementation.'
def test_uninstall_python(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertTrue(pyenv.uninstall_python('2.0.0-p0'))
'Test if it list the installed versions of python.'
def test_versions(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertListEqual(pyenv.versions(), [])
'Test if it returns or sets the currently defined default python.'
def test_default(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertEqual(pyenv.default(), '') self.assertTrue(pyenv.default('2.0.0-p0'))
'Test if it list the installable versions of python.'
def test_list(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertListEqual(pyenv.list_(), [])
'Test if it run pyenv rehash to update the installed shims.'
def test_rehash(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertTrue(pyenv.rehash())
'Test if it execute a python command with pyenv\'s shims from the user or the system.'
def test_do(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertFalse(pyenv.do('gem list bundler')) mock_all = MagicMock(return_value={'retcode': 0, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'config.option': mock_opt, 'cmd.has_exec': mock_cmd, 'cmd.run_all': mock_all}): self.assertEqual(pyenv.do('gem list bundler'), 'salt')
'Test if it execute a python command with pyenv\'s shims using a specific python version.'
def test_do_with_python(self):
mock_opt = MagicMock(return_value='salt stack') mock_cmd = MagicMock(return_value=True) mock_all = MagicMock(return_value={'retcode': True, 'stdout': 'salt', 'stderr': 'error'}) with patch.dict(pyenv.__salt__, {'cmd.has_exec': mock_cmd, 'config.option': mock_opt, 'cmd.run_all': mock_all}): self.assertFalse(pyenv.do_with_python('2.0.0-p0', 'gem list bundler'))
'Test - Return return the active kernel version'
def test_active(self):
self.assertEqual(self._kernelpkg.active(), self.KERNEL_LIST[0])
'Test - Return the latest available kernel version'
def test_latest_available_no_results(self):
mock = MagicMock(return_value='') with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}): with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[(-1)])
'Test - Return the latest available kernel version'
def test_latest_available_at_latest(self):
mock = MagicMock(return_value=self.LATEST) with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}): with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[(-1)]): self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[(-1)])
'Test - Return the latest available kernel version'
def test_latest_available_with_updates(self):
mock = MagicMock(return_value=self.LATEST) with patch.dict(self._kernelpkg.__salt__, {'pkg.latest_version': mock}): with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): self.assertEqual(self._kernelpkg.latest_available(), self.KERNEL_LIST[(-1)])
'Test - Return the latest installed kernel version'
def test_latest_installed_with_updates(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): self.assertEqual(self._kernelpkg.latest_installed(), self.KERNEL_LIST[(-1)])
'Test - Return the latest installed kernel version'
def test_latest_installed_at_latest(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[(-1)]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): self.assertEqual(self._kernelpkg.latest_installed(), self.KERNEL_LIST[(-1)])
'Test - Return True if a new kernel is ready to be booted'
def test_needs_reboot_with_update(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[1]): self.assertTrue(self._kernelpkg.needs_reboot())
'Test - Return True if a new kernel is ready to be booted'
def test_needs_reboot_at_latest(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[1]): self.assertFalse(self._kernelpkg.needs_reboot())
'Test - Return True if a new kernel is ready to be booted'
def test_needs_reboot_order_inverted(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[1]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[0]): self.assertFalse(self._kernelpkg.needs_reboot())
'Test - Upgrade function when no upgrade is available and reboot has been requested'
def test_upgrade_not_needed_with_reboot(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[(-1)]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): result = self._kernelpkg.upgrade(reboot=True) self.assertIn('upgrades', result) self.assertEqual(result['active'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['latest_installed'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['reboot_requested'], True) self.assertEqual(result['reboot_required'], False) self._kernelpkg.__salt__['system.reboot'].assert_not_called()
'Test - Upgrade function when no upgrade is available and no reboot has been requested'
def test_upgrade_not_needed_without_reboot(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[(-1)]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): result = self._kernelpkg.upgrade(reboot=False) self.assertIn('upgrades', result) self.assertEqual(result['active'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['latest_installed'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['reboot_requested'], False) self.assertEqual(result['reboot_required'], False) self._kernelpkg.__salt__['system.reboot'].assert_not_called()
'Test - Upgrade function when an upgrade is available and reboot has been requested'
def test_upgrade_needed_with_reboot(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): result = self._kernelpkg.upgrade(reboot=True) self.assertIn('upgrades', result) self.assertEqual(result['active'], self.KERNEL_LIST[0]) self.assertEqual(result['latest_installed'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['reboot_requested'], True) self.assertEqual(result['reboot_required'], True) self.assert_called_once(self._kernelpkg.__salt__['system.reboot'])
'Test - Upgrade function when an upgrade is available and no reboot has been requested'
def test_upgrade_needed_without_reboot(self):
with patch.object(self._kernelpkg, 'active', return_value=self.KERNEL_LIST[0]): with patch.object(self._kernelpkg, 'list_installed', return_value=self.KERNEL_LIST): result = self._kernelpkg.upgrade(reboot=False) self.assertIn('upgrades', result) self.assertEqual(result['active'], self.KERNEL_LIST[0]) self.assertEqual(result['latest_installed'], self.KERNEL_LIST[(-1)]) self.assertEqual(result['reboot_requested'], False) self.assertEqual(result['reboot_required'], True) self._kernelpkg.__salt__['system.reboot'].assert_not_called()
'Test - upgrade_available'
def test_upgrade_available_true(self):
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[(-1)]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[0]): self.assertTrue(self._kernelpkg.upgrade_available())
'Test - upgrade_available'
def test_upgrade_available_false(self):
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[(-1)]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[(-1)]): self.assertFalse(self._kernelpkg.upgrade_available())
'Test - upgrade_available'
def test_upgrade_available_inverted(self):
with patch.object(self._kernelpkg, 'latest_available', return_value=self.KERNEL_LIST[0]): with patch.object(self._kernelpkg, 'latest_installed', return_value=self.KERNEL_LIST[(-1)]): self.assertFalse(self._kernelpkg.upgrade_available())
'Test to see if mysql module properly forms the MySQL query to see if a user exists Do it before test_user_create_when_user_exists mocks the user_exists call'
def test_user_exists(self):
self._test_call(mysql.user_exists, {'sql': 'SELECT User,Host FROM mysql.user WHERE User = %(user)s AND Host = %(host)s AND Password = PASSWORD(%(password)s)', 'sql_args': {'host': 'localhost', 'password': 'BLUECOW', 'user': 'mytestuser'}}, user='mytestuser', host='localhost', password='BLUECOW') with patch.object(mysql, 'user_exists', MagicMock(return_value=True)): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): ret = mysql.user_create('testuser') self.assertEqual(False, ret)
'Test the creation of a MySQL user in mysql exec module'
def test_user_create(self):
self._test_call(mysql.user_create, {'sql': 'CREATE USER %(user)s@%(host)s IDENTIFIED BY %(password)s', 'sql_args': {'password': 'BLUECOW', 'user': 'testuser', 'host': 'localhost'}}, 'testuser', password='BLUECOW')
'Test changing a MySQL user password in mysql exec module'
def test_user_chpass(self):
connect_mock = MagicMock() with patch.object(mysql, '_connect', connect_mock): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): mysql.user_chpass('testuser', password='BLUECOW') calls = (call().cursor().execute('UPDATE mysql.user SET Password=PASSWORD(%(password)s) WHERE User=%(user)s AND Host = %(host)s;', {'password': 'BLUECOW', 'user': 'testuser', 'host': 'localhost'}), call().cursor().execute('FLUSH PRIVILEGES;')) connect_mock.assert_has_calls(calls, any_order=True)
'Test the removal of a MySQL user in mysql exec module'
def test_user_remove(self):
self._test_call(mysql.user_remove, {'sql': 'DROP USER %(user)s@%(host)s', 'sql_args': {'user': 'testuser', 'host': 'localhost'}}, 'testuser')
'Test MySQL db check function in mysql exec module'
def test_db_check(self):
self._test_call(mysql.db_check, 'CHECK TABLE `test``\'" db`.`my``\'" table`', 'test`\'" db', 'my`\'" table')
'Test MySQL db repair function in mysql exec module'
def test_db_repair(self):
self._test_call(mysql.db_repair, 'REPAIR TABLE `test``\'" db`.`my``\'" table`', 'test`\'" db', 'my`\'" table')
'Test MySQL db optimize function in mysql exec module'
def test_db_optimize(self):
self._test_call(mysql.db_optimize, 'OPTIMIZE TABLE `test``\'" db`.`my``\'" table`', 'test`\'" db', 'my`\'" table')
'Test MySQL db remove function in mysql exec module'
def test_db_remove(self):
with patch.object(mysql, 'db_exists', MagicMock(return_value=True)): self._test_call(mysql.db_remove, 'DROP DATABASE `test``\'" db`;', 'test`\'" db')
'Test MySQL db_tables function in mysql exec module'
def test_db_tables(self):
with patch.object(mysql, 'db_exists', MagicMock(return_value=True)): self._test_call(mysql.db_tables, 'SHOW TABLES IN `test``\'" db`', 'test`\'" db')
'Test MySQL db_exists function in mysql exec module'
def test_db_exists(self):
self._test_call(mysql.db_exists, {'sql': 'SHOW DATABASES LIKE %(dbname)s;', 'sql_args': {'dbname': 'test%_`" db'}}, 'test%_`" db')
'Test MySQL db_create function in mysql exec module'
def test_db_create(self):
self._test_call(mysql.db_create, 'CREATE DATABASE IF NOT EXISTS `test``\'" db`;', 'test`\'" db')
'Test MySQL user_list function in mysql exec module'
def test_user_list(self):
self._test_call(mysql.user_list, 'SELECT User,Host FROM mysql.user')
'Test to see if the mysql execution module correctly forms the SQL for information on a MySQL user.'
def test_user_info(self):
self._test_call(mysql.user_info, {'sql': 'SELECT * FROM mysql.user WHERE User = %(user)s AND Host = %(host)s', 'sql_args': {'host': 'localhost', 'user': 'mytestuser'}}, 'mytestuser')
'Test to ensure the mysql user_grants function returns properly formed SQL for a basic query'
def test_user_grants(self):
with patch.object(mysql, 'user_exists', MagicMock(return_value=True)): self._test_call(mysql.user_grants, {'sql': 'SHOW GRANTS FOR %(user)s@%(host)s', 'sql_args': {'host': 'localhost', 'user': 'testuser'}}, 'testuser')
'Test to ensure that we can find a grant that exists'
def test_grant_exists_true(self):
mock_grants = ["GRANT USAGE ON *.* TO 'testuser'@'%'", "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'", "GRANT SELECT ON `testdb`.`testtabletwo` TO 'testuer'@'%'", "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'"] mock = MagicMock(return_value=mock_grants) with patch.object(mysql, 'user_grants', return_value=mock_grants) as mock_user_grants: ret = mysql.grant_exists('SELECT, INSERT, UPDATE', 'testdb.testtableone', 'testuser', '%') self.assertEqual(ret, True)
'Test to ensure that we don\'t find a grant that doesn\'t exist'
def test_grant_exists_false(self):
mock_grants = ["GRANT USAGE ON *.* TO 'testuser'@'%'", "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'", "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'"] mock = MagicMock(return_value=mock_grants) with patch.object(mysql, 'user_grants', return_value=mock_grants) as mock_user_grants: ret = mysql.grant_exists('SELECT', 'testdb.testtabletwo', 'testuser', '%') self.assertEqual(ret, False)
'Test grant_add function in mysql exec module'
@skipIf(True, 'TODO: Mock up user_grants()') def test_grant_add(self):
self._test_call(mysql.grant_add, '', 'SELECT,INSERT,UPDATE', 'database.*', 'frank', 'localhost')