desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Mock get method'
| def get(self, key):
| self.key = key
return 'A'
|
'Mock hget method'
| def hget(self, key, field):
| self.key = key
self.field = field
return 'A'
|
'Mock hgetall method'
| def hgetall(self, key):
| self.key = key
return 'A'
|
'Mock info method'
| @staticmethod
def info():
| return 'A'
|
'Mock keys method'
| def keys(self, pattern):
| self.pattern = pattern
return 'A'
|
'Mock type method'
| def type(self, key):
| self.key = key
return 'A'
|
'Mock lastsave method'
| @staticmethod
def lastsave():
| return datetime.now()
|
'Mock llen method'
| def llen(self, key):
| self.key = key
return 'A'
|
'Mock lrange method'
| def lrange(self, key, start, stop):
| self.key = key
self.start = start
self.stop = stop
return 'A'
|
'Mock ping method'
| @staticmethod
def ping():
| MockConnect.counter = (MockConnect.counter + 1)
if (MockConnect.counter == 1):
return 'A'
elif (MockConnect.counter in (2, 3, 5)):
raise Mockredis.ConnectionError('foo')
|
'Mock save method'
| @staticmethod
def save():
| return 'A'
|
'Mock set method'
| def set(self, key, value):
| self.key = key
self.value = value
return 'A'
|
'Mock shutdown method'
| @staticmethod
def shutdown():
| return 'A'
|
'Mock slaveof method'
| def slaveof(self, master_host, master_port):
| self.master_host = master_host
self.master_port = master_port
return 'A'
|
'Mock smembers method'
| def smembers(self, key):
| self.key = key
return 'A'
|
'Mock time method'
| @staticmethod
def time():
| return 'A'
|
'Mock zcard method'
| def zcard(self, key):
| self.key = key
return 'A'
|
'Mock zrange method'
| def zrange(self, key, start, stop):
| self.key = key
self.start = start
self.stop = stop
return 'A'
|
'Test to asynchronously rewrite the append-only file'
| def test_bgrewriteaof(self):
| self.assertEqual(redismod.bgrewriteaof(), 'A')
|
'Test to asynchronously save the dataset to disk'
| def test_bgsave(self):
| self.assertEqual(redismod.bgsave(), 'A')
|
'Test to get redis server configuration values'
| def test_config_get(self):
| self.assertEqual(redismod.config_get('*'), 'A')
|
'Test to set redis server configuration values'
| def test_config_set(self):
| self.assertEqual(redismod.config_set('name', 'value'), 'A')
|
'Test to return the number of keys in the selected database'
| def test_dbsize(self):
| self.assertEqual(redismod.dbsize(), 'A')
|
'Test to deletes the keys from redis, returns number of keys deleted'
| def test_delete(self):
| self.assertEqual(redismod.delete(), 'A')
|
'Test to return true if the key exists in redis'
| def test_exists(self):
| self.assertEqual(redismod.exists('key'), 'A')
|
'Test to set a keys time to live in seconds'
| def test_expire(self):
| self.assertEqual(redismod.expire('key', 'seconds'), 'A')
|
'Test to set a keys expire at given UNIX time'
| def test_expireat(self):
| self.assertEqual(redismod.expireat('key', 'timestamp'), 'A')
|
'Test to remove all keys from all databases'
| def test_flushall(self):
| self.assertEqual(redismod.flushall(), 'A')
|
'Test to remove all keys from the selected database'
| def test_flushdb(self):
| self.assertEqual(redismod.flushdb(), 'A')
|
'Test to get redis key value'
| def test_get_key(self):
| self.assertEqual(redismod.get_key('key'), 'A')
|
'Test to get specific field value from a redis hash, returns dict'
| def test_hget(self):
| self.assertEqual(redismod.hget('key', 'field'), 'A')
|
'Test to get all fields and values from a redis hash, returns dict'
| def test_hgetall(self):
| self.assertEqual(redismod.hgetall('key'), 'A')
|
'Test to get information and statistics about the server'
| def test_info(self):
| self.assertEqual(redismod.info(), 'A')
|
'Test to get redis keys, supports glob style patterns'
| def test_keys(self):
| self.assertEqual(redismod.keys('pattern'), 'A')
|
'Test to get redis key type'
| def test_key_type(self):
| self.assertEqual(redismod.key_type('key'), 'A')
|
'Test to get the UNIX time in seconds of the last successful
save to disk'
| def test_lastsave(self):
| self.assertTrue(redismod.lastsave())
|
'Test to get the length of a list in Redis'
| def test_llen(self):
| self.assertEqual(redismod.llen('key'), 'A')
|
'Test to get a range of values from a list in Redis'
| def test_lrange(self):
| self.assertEqual(redismod.lrange('key', 'start', 'stop'), 'A')
|
'Test to ping the server, returns False on connection errors'
| def test_ping(self):
| self.assertEqual(redismod.ping(), 'A')
self.assertFalse(redismod.ping())
|
'Test to synchronously save the dataset to disk'
| def test_save(self):
| self.assertEqual(redismod.save(), 'A')
|
'Test to set redis key value'
| def test_set_key(self):
| self.assertEqual(redismod.set_key('key', 'value'), 'A')
|
'Test to synchronously save the dataset to disk and then
shut down the server'
| def test_shutdown(self):
| self.assertFalse(redismod.shutdown())
self.assertTrue(redismod.shutdown())
self.assertFalse(redismod.shutdown())
|
'Test to make the server a slave of another instance, or
promote it as master'
| def test_slaveof(self):
| self.assertEqual(redismod.slaveof('master_host', 'master_port'), 'A')
|
'Test to get members in a Redis set'
| def test_smembers(self):
| self.assertListEqual(redismod.smembers('key'), ['A'])
|
'Test to return the current server UNIX time in seconds'
| def test_time(self):
| self.assertEqual(redismod.time(), 'A')
|
'Test to get the length of a sorted set in Redis'
| def test_zcard(self):
| self.assertEqual(redismod.zcard('key'), 'A')
|
'Test to get a range of values from a sorted set in Redis by index'
| def test_zrange(self):
| self.assertEqual(redismod.zrange('key', 'start', 'stop'), 'A')
|
'Test gluster peer status'
| def test_peer_status(self):
| mock_run = MagicMock(return_value=xml_peer_present)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertDictEqual(glusterfs.peer_status(), {'uuid1': {'hostnames': ['node02', 'node02.domain.dom', '10.0.0.2']}})
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertDictEqual(glusterfs.peer_status(), {})
|
'Test if gluster peer call is successful.'
| def test_peer(self):
| mock_run = MagicMock()
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
mock_run.return_value = xml_peer_probe_already_member
self.assertTrue(glusterfs.peer('salt'))
mock_run.return_value = xml_peer_probe_localhost
self.assertTrue(glusterfs.peer('salt'))
mock_run.return_value = xml_peer_probe_fail_cant_connect
self.assertFalse(glusterfs.peer('salt'))
|
'Test if it creates a glusterfs volume.'
| def test_create_volume(self):
| mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertRaises(SaltInvocationError, glusterfs.create_volume, 'newvolume', 'host1:brick')
self.assertRaises(SaltInvocationError, glusterfs.create_volume, 'newvolume', 'host1/brick')
self.assertFalse(mock_run.called)
mock_start_volume = MagicMock(return_value=True)
with patch.object(glusterfs, 'start_volume', mock_start_volume):
self.assertTrue(glusterfs.create_volume('newvolume', 'host1:/brick'))
self.assertFalse(mock_start_volume.called)
self.assertTrue(glusterfs.create_volume('newvolume', 'host1:/brick', start=True))
self.assertTrue(mock_start_volume.called)
mock_start_volume.return_value = False
self.assertFalse(glusterfs.create_volume('newvolume', 'host1:/brick', start=True))
mock_run.return_value = xml_command_fail
self.assertFalse(glusterfs.create_volume('newvolume', 'host1:/brick', True, True, True, 'tcp', True))
|
'Test if it list configured volumes'
| def test_list_volumes(self):
| mock = MagicMock(return_value=xml_volume_absent)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertListEqual(glusterfs.list_volumes(), [])
mock = MagicMock(return_value=xml_volume_present)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertListEqual(glusterfs.list_volumes(), ['Newvolume1', 'Newvolume2'])
|
'Test if it check the status of a gluster volume.'
| def test_status(self):
| mock_run = MagicMock(return_value=xml_command_fail)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertIsNone(glusterfs.status('myvol1'))
res = {'bricks': {'node01:/tmp/foo': {'host': 'node01', 'hostname': 'node01', 'online': True, 'path': '/tmp/foo', 'peerid': '830700d7-0684-497c-a12c-c02e365fb90b', 'pid': '2470', 'port': '49155', 'ports': {'rdma': 'N/A', 'tcp': '49155'}, 'status': '1'}}, 'healers': {}, 'nfs': {'node01': {'host': 'NFS Server', 'hostname': 'NFS Server', 'online': False, 'path': 'localhost', 'peerid': '830700d7-0684-497c-a12c-c02e365fb90b', 'pid': '-1', 'port': 'N/A', 'ports': {'rdma': 'N/A', 'tcp': 'N/A'}, 'status': '0'}}}
mock = MagicMock(return_value=xml_volume_status)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertDictEqual(glusterfs.status('myvol1'), res)
|
'Test if it returns the volume info.'
| def test_volume_info(self):
| res = {'myvol1': {'brickCount': '1', 'bricks': {'brick1': {'hostUuid': '830700d7-0684-497c-a12c-c02e365fb90b', 'path': 'node01:/tmp/foo', 'uuid': '830700d7-0684-497c-a12c-c02e365fb90b'}}, 'disperseCount': '0', 'distCount': '1', 'id': 'f03c2180-cf55-4f77-ae0b-3650f57c82a1', 'name': 'myvol1', 'optCount': '1', 'options': {'performance.readdir-ahead': 'on'}, 'redundancyCount': '0', 'replicaCount': '1', 'status': '1', 'statusStr': 'Started', 'stripeCount': '1', 'transport': '0', 'type': '0', 'typeStr': 'Distribute'}}
mock = MagicMock(return_value=xml_volume_info_running)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock}):
self.assertDictEqual(glusterfs.info('myvol1'), res)
|
'Test if it start a gluster volume.'
| def test_start_volume(self):
| mock_info = MagicMock(return_value={'Newvolume1': {'status': '0'}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.start_volume('Newvolume1'), True)
self.assertEqual(glusterfs.start_volume('nonExisting'), False)
mock_run = MagicMock(return_value=xml_command_fail)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.start_volume('Newvolume1'), False)
mock_info = MagicMock(return_value={'Newvolume1': {'status': '1'}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.start_volume('Newvolume1', force=True), True)
mock_run = MagicMock(return_value=xml_command_fail)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.start_volume('Newvolume1'), True)
self.assertEqual(glusterfs.start_volume('Newvolume1', force=True), False)
|
'Test if it stop a gluster volume.'
| def test_stop_volume(self):
| mock_info = MagicMock(return_value={'Newvolume1': {'status': '0'}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.stop_volume('Newvolume1'), True)
self.assertEqual(glusterfs.stop_volume('nonExisting'), False)
mock_run = MagicMock(return_value=xml_command_fail)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.stop_volume('Newvolume1'), True)
mock_info = MagicMock(return_value={'Newvolume1': {'status': '1'}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.stop_volume('Newvolume1'), True)
self.assertEqual(glusterfs.stop_volume('nonExisting'), False)
mock_run = MagicMock(return_value=xml_command_fail)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertEqual(glusterfs.stop_volume('Newvolume1'), False)
|
'Test if it deletes a gluster volume.'
| def test_delete_volume(self):
| mock_info = MagicMock(return_value={'Newvolume1': {'status': '1'}})
with patch.object(glusterfs, 'info', mock_info):
self.assertFalse(glusterfs.delete_volume('Newvolume3'))
mock_stop_volume = MagicMock(return_value=True)
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
with patch.object(glusterfs, 'stop_volume', mock_stop_volume):
self.assertFalse(glusterfs.delete_volume('Newvolume1', False))
self.assertFalse(mock_run.called)
self.assertFalse(mock_stop_volume.called)
self.assertTrue(glusterfs.delete_volume('Newvolume1'))
self.assertTrue(mock_run.called)
self.assertTrue(mock_stop_volume.called)
mock_info = MagicMock(return_value={'Newvolume1': {'status': '2'}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertTrue(glusterfs.delete_volume('Newvolume1'))
mock_run.return_value = xml_command_fail
self.assertFalse(glusterfs.delete_volume('Newvolume1'))
|
'Test if it add brick(s) to an existing volume'
| def test_add_volume_bricks(self):
| mock_info = MagicMock(return_value={'Newvolume1': {'status': '1', 'bricks': {'brick1': {'path': 'host:/path1'}, 'brick2': {'path': 'host:/path2'}}}})
with patch.object(glusterfs, 'info', mock_info):
mock_run = MagicMock(return_value=xml_command_success)
with patch.dict(glusterfs.__salt__, {'cmd.run': mock_run}):
self.assertFalse(glusterfs.add_volume_bricks('nonExisting', ['bricks']))
self.assertTrue(glusterfs.add_volume_bricks('Newvolume1', ['host:/path2']))
self.assertTrue(glusterfs.add_volume_bricks('Newvolume1', 'host:/path2'))
self.assertFalse(mock_run.called)
self.assertTrue(glusterfs.add_volume_bricks('Newvolume1', ['host:/new1']))
self.assertTrue(mock_run.called)
mock_run.return_value = xml_command_fail
self.assertFalse(glusterfs.add_volume_bricks('Newvolume1', ['new:/path']))
|
'Test - Return the latest installed kernel version'
| def test_list_installed(self):
| mock = MagicMock(return_value=self.KERNEL_LIST)
with patch.dict(self._kernelpkg.__salt__, {'pkg.version': mock}):
self.assertListEqual(self._kernelpkg.list_installed(), self.KERNEL_LIST)
|
'Test - Return the latest installed kernel version'
| def test_list_installed_none(self):
| mock = MagicMock(return_value=None)
with patch.dict(self._kernelpkg.__salt__, {'pkg.version': mock}):
self.assertListEqual(self._kernelpkg.list_installed(), [])
|
'Test for return a dict of active config values'
| def test_show_master(self):
| with patch.object(postfix, '_parse_master', return_value=({'A': 'a'}, ['b'])):
self.assertDictEqual(postfix.show_master('path'), {'A': 'a'})
|
'Test for set a single config value in the master.cf file'
| def test_set_master(self):
| with patch.object(postfix, '_parse_master', return_value=({'A': 'a'}, ['b'])):
with patch.object(postfix, '_write_conf', return_value=None):
self.assertTrue(postfix.set_master('a', 'b'))
|
'Test for return a dict of active config values'
| def test_show_main(self):
| with patch.object(postfix, '_parse_main', return_value=({'A': 'a'}, ['b'])):
self.assertDictEqual(postfix.show_main('path'), {'A': 'a'})
|
'Test for set a single config value in the master.cf file'
| def test_set_main(self):
| with patch.object(postfix, '_parse_main', return_value=({'A': 'a'}, ['b'])):
with patch.object(postfix, '_write_conf', return_value=None):
self.assertTrue(postfix.set_main('key', 'value'))
|
'Test for show contents of the mail queue'
| def test_show_queue(self):
| with patch.dict(postfix.__salt__, {'cmd.run': MagicMock(return_value='A\nB')}):
self.assertEqual(postfix.show_queue(), [])
|
'Test for delete message(s) from the mail queue'
| def test_delete(self):
| with patch.object(postfix, 'show_queue', return_value={}):
self.assertDictEqual(postfix.delete('queue_id'), {'result': False, 'message': 'No message in queue with ID queue_id'})
with patch.dict(postfix.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}):
self.assertDictEqual(postfix.delete('ALL'), {'result': True, 'message': 'Successfully removed all messages'})
|
'Test for set held message(s) in the mail queue to unheld'
| def test_hold(self):
| with patch.object(postfix, 'show_queue', return_value={}):
self.assertDictEqual(postfix.hold('queue_id'), {'result': False, 'message': 'No message in queue with ID queue_id'})
with patch.dict(postfix.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}):
self.assertDictEqual(postfix.hold('ALL'), {'result': True, 'message': 'Successfully placed all messages on hold'})
|
'Test for put message(s) on hold from the mail queue'
| def test_unhold(self):
| with patch.object(postfix, 'show_queue', return_value={}):
self.assertDictEqual(postfix.unhold('queue_id'), {'result': False, 'message': 'No message in queue with ID queue_id'})
with patch.dict(postfix.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}):
self.assertDictEqual(postfix.unhold('ALL'), {'result': True, 'message': 'Successfully set all message as unheld'})
|
'Test for requeue message(s) in the mail queue'
| def test_requeue(self):
| with patch.object(postfix, 'show_queue', return_value={}):
self.assertDictEqual(postfix.requeue('queue_id'), {'result': False, 'message': 'No message in queue with ID queue_id'})
with patch.dict(postfix.__salt__, {'cmd.run_all': MagicMock(return_value={'retcode': 0})}):
self.assertDictEqual(postfix.requeue('ALL'), {'result': True, 'message': 'Successfully requeued all messages'})
|
'Test to list all InfluxDB databases'
| def test_db_list(self):
| mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
self.assertEqual(influx08.db_list(user='root', password='root', host='localhost', port=8086), DB_LIST)
|
'Tests for checks if a database exists in InfluxDB'
| def test_db_exists(self):
| with patch.object(influx08, 'db_list', side_effect=[[{'name': 'A'}], None]):
self.assertTrue(influx08.db_exists(name='A', user='root', password='root', host='localhost', port=8000))
self.assertFalse(influx08.db_exists(name='A', user='root', password='root', host='localhost', port=8000))
|
'Test to create a database'
| def test_db_create(self):
| with patch.object(influx08, 'db_exists', side_effect=[True, False]):
self.assertFalse(influx08.db_create(name='A', user='root', password='root', host='localhost', port=8000))
mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
self.assertTrue(influx08.db_create(name='A', user='root', password='root', host='localhost', port=8000))
|
'Test to remove a database'
| def test_db_remove(self):
| with patch.object(influx08, 'db_exists', side_effect=[False, True]):
self.assertFalse(influx08.db_remove(name='A', user='root', password='root', host='localhost', port=8000))
mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
self.assertTrue(influx08.db_remove(name='A', user='root', password='root', host='localhost', port=8000))
|
'Tests for list cluster admins or database users.'
| def test_user_list(self):
| mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
self.assertListEqual(influx08.user_list(database='A', user='root', password='root', host='localhost', port=8086), USER_LIST)
self.assertListEqual(influx08.user_list(user='root', password='root', host='localhost', port=8086), USER_LIST)
|
'Test to checks if a cluster admin or database user exists.'
| def test_user_exists(self):
| with patch.object(influx08, 'user_list', side_effect=[[{'name': 'A'}], None]):
self.assertTrue(influx08.user_exists(name='A', user='root', password='root', host='localhost', port=8000))
self.assertFalse(influx08.user_exists(name='A', user='root', password='root', host='localhost', port=8000))
|
'Tests to change password for a cluster admin or a database user.'
| def test_user_chpass(self):
| with patch.object(influx08, 'user_exists', return_value=False):
self.assertFalse(influx08.user_chpass(name='A', passwd='*', user='root', password='root', host='localhost', port=8000))
self.assertFalse(influx08.user_chpass(name='A', passwd='*', database='test', user='root', password='root', host='localhost', port=8000))
mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
with patch.object(influx08, 'user_exists', return_value=True):
self.assertTrue(influx08.user_chpass(name='A', passwd='*', user='root', password='root', host='localhost', port=8000))
self.assertTrue(influx08.user_chpass(name='A', passwd='*', database='test', user='root', password='root', host='localhost', port=8000))
|
'Tests to remove a cluster admin or a database user.'
| def test_user_remove(self):
| with patch.object(influx08, 'user_exists', return_value=False):
self.assertFalse(influx08.user_remove(name='A', user='root', password='root', host='localhost', port=8000))
self.assertFalse(influx08.user_remove(name='A', database='test', user='root', password='root', host='localhost', port=8000))
mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
with patch.object(influx08, 'user_exists', return_value=True):
self.assertTrue(influx08.user_remove(name='A', user='root', password='root', host='localhost', port=8000))
self.assertTrue(influx08.user_remove(name='A', database='test', user='root', password='root', host='localhost', port=8000))
|
'Test for querying data'
| def test_query(self):
| mock_inf_db_client = MagicMock(return_value=MockInfluxDBClient())
with patch.object(influx08, '_client', mock_inf_db_client):
self.assertTrue(influx08.query(database='db', query='q', user='root', password='root', host='localhost', port=8000))
|
'Test for Return version from ipset --version'
| def test_version(self):
| with patch.object(ipset, '_ipset_cmd', return_value='A'):
mock = MagicMock(return_value='A\nB\nC')
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertEqual(ipset.version(), 'B')
|
'Test for Create new custom set'
| def test_new_set(self):
| self.assertEqual(ipset.new_set(), 'Error: Set needs to be specified')
self.assertEqual(ipset.new_set('s'), 'Error: Set Type needs to be specified')
self.assertEqual(ipset.new_set('s', 'd'), 'Error: Set Type is invalid')
self.assertEqual(ipset.new_set('s', 'bitmap:ip'), 'Error: range is a required argument')
mock = MagicMock(return_value=False)
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertTrue(ipset.new_set('s', 'bitmap:ip', range='range'))
|
'Test for Delete ipset set.'
| def test_delete_set(self):
| self.assertEqual(ipset.delete_set(), 'Error: Set needs to be specified')
with patch.object(ipset, '_ipset_cmd', return_value='A'):
mock = MagicMock(return_value=True)
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertTrue(ipset.delete_set('set', 'family'))
|
'Test for Delete ipset set.'
| def test_rename_set(self):
| self.assertEqual(ipset.rename_set(), 'Error: Set needs to be specified')
self.assertEqual(ipset.rename_set('s'), 'Error: New name for set needs to be specified')
with patch.object(ipset, '_find_set_type', return_value=False):
self.assertEqual(ipset.rename_set('s', 'd'), 'Error: Set does not exist')
with patch.object(ipset, '_find_set_type', return_value=True):
self.assertEqual(ipset.rename_set('s', 'd'), 'Error: New Set already exists')
with patch.object(ipset, '_find_set_type', side_effect=[True, False]):
with patch.object(ipset, '_ipset_cmd', return_value='A'):
mock = MagicMock(return_value=True)
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertTrue(ipset.rename_set('set', 'new_set'))
|
'Test for List all ipset sets.'
| def test_list_sets(self):
| with patch.object(ipset, '_ipset_cmd', return_value='A'):
mock = MagicMock(return_value='A:a')
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertEqual(ipset.list_sets(), [{'A': ''}])
|
'Test for Check that given ipset set exists.'
| def test_check_set(self):
| self.assertEqual(ipset.check_set(), 'Error: Set needs to be specified')
with patch.object(ipset, '_find_set_info', side_effect=[False, True]):
self.assertFalse(ipset.check_set('set'))
self.assertTrue(ipset.check_set('set'))
|
'Test for Append an entry to the specified set.'
| def test_add(self):
| self.assertEqual(ipset.add(), 'Error: Set needs to be specified')
self.assertEqual(ipset.add('set'), 'Error: Entry needs to be specified')
with patch.object(ipset, '_find_set_info', return_value=None):
self.assertEqual(ipset.add('set', 'entry'), 'Error: Set set does not exist')
mock = MagicMock(return_value={'Type': 'type', 'Header': 'Header'})
with patch.object(ipset, '_find_set_info', mock):
self.assertEqual(ipset.add('set', 'entry', timeout=0), 'Error: Set set not created with timeout support')
self.assertEqual(ipset.add('set', 'entry', packets=0), 'Error: Set set not created with counters support')
self.assertEqual(ipset.add('set', 'entry', comment=0), 'Error: Set set not created with comment support')
mock = MagicMock(return_value={'Type': 'bitmap:ip', 'Header': 'Header'})
with patch.object(ipset, '_find_set_info', mock):
with patch.object(ipset, '_find_set_members', return_value='entry'):
self.assertEqual(ipset.add('set', 'entry'), 'Warn: Entry entry already exists in set set')
with patch.object(ipset, '_find_set_members', return_value='A'):
mock = MagicMock(return_value='')
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertEqual(ipset.add('set', 'entry'), 'Success')
mock = MagicMock(return_value='out')
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertEqual(ipset.add('set', 'entry'), 'Error: out')
|
'Test for Delete an entry from the specified set.'
| def test_delete(self):
| self.assertEqual(ipset.delete(), 'Error: Set needs to be specified')
self.assertEqual(ipset.delete('s'), 'Error: Entry needs to be specified')
with patch.object(ipset, '_find_set_type', return_value=None):
self.assertEqual(ipset.delete('set', 'entry'), 'Error: Set set does not exist')
with patch.object(ipset, '_find_set_type', return_value=True):
with patch.object(ipset, '_ipset_cmd', return_value='A'):
mock = MagicMock(side_effect=['', 'A'])
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertEqual(ipset.delete('set', 'entry'), 'Success')
self.assertEqual(ipset.delete('set', 'entry'), 'Error: A')
|
'Test for Check that an entry exists in the specified set.'
| def test_check(self):
| self.assertEqual(ipset.check(), 'Error: Set needs to be specified')
self.assertEqual(ipset.check('s'), 'Error: Entry needs to be specified')
with patch.object(ipset, '_find_set_type', return_value=None):
self.assertEqual(ipset.check('set', 'entry'), 'Error: Set set does not exist')
with patch.object(ipset, '_find_set_type', return_value='hash:ip'):
with patch.object(ipset, '_find_set_members', side_effect=['entry', '', ['192.168.0.4', '192.168.0.5'], ['192.168.0.3'], ['192.168.0.6'], ['192.168.0.4', '192.168.0.5'], ['192.168.0.3'], ['192.168.0.6']]):
self.assertTrue(ipset.check('set', 'entry'))
self.assertFalse(ipset.check('set', 'entry'))
self.assertTrue(ipset.check('set', '192.168.0.4/31'))
self.assertFalse(ipset.check('set', '192.168.0.4/31'))
self.assertFalse(ipset.check('set', '192.168.0.4/31'))
self.assertTrue(ipset.check('set', '192.168.0.4-192.168.0.5'))
self.assertFalse(ipset.check('set', '192.168.0.4-192.168.0.5'))
self.assertFalse(ipset.check('set', '192.168.0.4-192.168.0.5'))
with patch.object(ipset, '_find_set_type', return_value='hash:net'):
with patch.object(ipset, '_find_set_members', side_effect=['entry', '', '192.168.0.4/31', '192.168.0.4/30', '192.168.0.4/31', '192.168.0.4/30']):
self.assertTrue(ipset.check('set', 'entry'))
self.assertFalse(ipset.check('set', 'entry'))
self.assertTrue(ipset.check('set', '192.168.0.4/31'))
self.assertFalse(ipset.check('set', '192.168.0.4/31'))
self.assertTrue(ipset.check('set', '192.168.0.4-192.168.0.5'))
self.assertFalse(ipset.check('set', '192.168.0.4-192.168.0.5'))
|
'Test for Test if an entry is in the specified set.'
| def test_test(self):
| self.assertEqual(ipset.test(), 'Error: Set needs to be specified')
self.assertEqual(ipset.test('s'), 'Error: Entry needs to be specified')
with patch.object(ipset, '_find_set_type', return_value=None):
self.assertEqual(ipset.test('set', 'entry'), 'Error: Set set does not exist')
with patch.object(ipset, '_find_set_type', return_value=True):
mock = MagicMock(side_effect=[{'retcode': 1}, {'retcode': (-1)}])
with patch.dict(ipset.__salt__, {'cmd.run_all': mock}):
self.assertFalse(ipset.test('set', 'entry'))
self.assertTrue(ipset.test('set', 'entry'))
|
'Test for Flush entries in the specified set'
| def test_flush(self):
| with patch.object(ipset, '_find_set_type', return_value=None):
self.assertEqual(ipset.flush('set'), 'Error: Set set does not exist')
with patch.object(ipset, '_find_set_type', return_value=True):
mock = MagicMock(side_effect=['', 'A'])
with patch.dict(ipset.__salt__, {'cmd.run': mock}):
self.assertTrue(ipset.flush('set'))
self.assertFalse(ipset.flush('set'))
|
'Test to see if the given license key is installed'
| def test_installed(self):
| mock = MagicMock(return_value='Partial Product Key: ABCDE')
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
out = win_license.installed('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /dli')
self.assertTrue(out)
|
'Test to see if the given license key is installed when the key is different'
| def test_installed_diff(self):
| mock = MagicMock(return_value='Partial Product Key: 12345')
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
out = win_license.installed('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /dli')
self.assertFalse(out)
|
'Test installing the given product key'
| def test_install(self):
| mock = MagicMock()
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
win_license.install('AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /ipk AAAAA-AAAAA-AAAAA-AAAA-AAAAA-ABCDE')
|
'Test uninstalling the given product key'
| def test_uninstall(self):
| mock = MagicMock()
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
win_license.uninstall()
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /upk')
|
'Test activating the current product key'
| def test_activate(self):
| mock = MagicMock()
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
win_license.activate()
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /ato')
|
'Test checking if the minion is licensed'
| def test_licensed(self):
| mock = MagicMock(return_value='License Status: Licensed')
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
win_license.licensed()
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /dli')
|
'Test getting the info about the current license key'
| def test_info(self):
| expected = {'description': 'Prof', 'licensed': True, 'name': 'Win7', 'partial_key': '12345'}
mock = MagicMock(return_value='Name: Win7\r\nDescription: Prof\r\nPartial Product Key: 12345\r\nLicense Status: Licensed')
with patch.dict(win_license.__salt__, {'cmd.run': mock}):
out = win_license.info()
mock.assert_called_once_with('cscript C:\\Windows\\System32\\slmgr.vbs /dli')
self.assertEqual(out, expected)
|
'Test for start'
| def test_start(self):
| with patch.dict(monit.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(monit.start('name'))
|
'Test for Stops service via monit'
| def test_stop(self):
| with patch.dict(monit.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(monit.stop('name'))
|
'Test for Restart service via monit'
| def test_restart(self):
| with patch.dict(monit.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(monit.restart('name'))
|
'Test for Unmonitor service via monit'
| def test_unmonitor(self):
| with patch.dict(monit.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(monit.unmonitor('name'))
|
'Test for monitor service via monit'
| def test_monitor(self):
| with patch.dict(monit.__salt__, {'cmd.retcode': MagicMock(return_value=False)}):
self.assertTrue(monit.monitor('name'))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.