call('limit', None, iff=None), call('marker', None, iff=None), call('prefix', '/lala', iff='/lala'), call('delimiter', 'X', iff='X'), ]) FR.status_code = 304 self.assertEqual(self.client.list_objects(), []) FR.status_code = 404 self.assertRaises(ClientError, self.client.list_objects) @patch('%s.get' % client_pkg, return_value=FR()) @patch('%s.set_param' % client_pkg) def test_list_objects_in_path(self, SP, get): FR.json = object_list path = '/some/awsome/path' acc, cont = self.client.account, self.client.container self.client.list_objects_in_path(path) exp = '/%s/%s' % (acc, cont) get.assert_called_once_with(exp, success=(200, 204, 404)) self.assertEqual(SP.mock_calls, [call('format', 'json'), call('path', path)]) FR.status_code = 404 self.assertRaises(ClientError, self.client.list_objects) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(StorageClient, 'Storage Client', argv[1:])
self.assertEqual(self.client.delete_snapshot('sid'), 'hea') snapshots_delete.assert_called_once_with('sid') @patch('%s.types_get' % rest_pkg, return_value=FakeResponse()) def test_list_volume_types(self, types_get): FakeResponse.json = dict(volume_types='ret list') self.assertEqual(self.client.list_volume_types(), 'ret list') self.assertEqual(types_get.mock_calls[-1], call()) @patch('%s.types_get' % rest_pkg, return_value=FakeResponse()) def test_get_volume_type_details(self, types_get): FakeResponse.json = dict(volume_type='ret dict') self.assertEqual(self.client.get_volume_type_details('vtid'), 'ret dict') self.assertEqual(types_get.mock_calls[-1], call('vtid')) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'BlockStorageRestClient': not_found = False runTestCase(BlockStorageRestClient, 'Block Storage Rest Client', argv[2:]) if not argv[1:] or argv[1] == 'BlockStorageClient': not_found = False runTestCase(BlockStorageClient, 'Block Storage Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
if key in src: self.assert_dicts_are_equal(r, {key: src[key]}) else: self.assert_dicts_are_equal(r, dict()) def test_path4url(self): utf = u'\u03a6\u03bf\u03cd\u03c4\u03c3\u03bf\u03c2'.encode('utf-8') for expected, args in ( ('', ('')), ('/path1/path2', ('path1', 'path2')), ('/1/number/0.28', (1, 'number', 0.28)), ('/1/n/u/m/b/er/X', ('//1//', '//n//u///m////b/er/', 'X//')), ('/p1/%s/p2' % utf.decode('utf-8'), ('p1', utf, 'p2'))): self.assertEqual(utils.path4url(*args), expected) def test_readall(self): tstr = '1234567890' with TemporaryFile() as f: f.write(tstr) f.flush() f.seek(0) self.assertEqual(utils.readall(f, 5), tstr[:5]) self.assertEqual(utils.readall(f, 10), tstr[5:]) self.assertEqual(utils.readall(f, 1), '') self.assertRaises(IOError, utils.readall, f, 1, 0) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(Utils, 'clients.utils methods', argv[1:])
import astakosclient self.client._uuids['t1'] = 'uuid 0' self.client._astakos['uuid 0'] = astakosclient.AstakosClient( self.url, self.token) self.client._usernames2uuids['uuid 0'] = dict(name0='uuid 0') exp = dict() for i in range(3): exp['name%s' % i] = 'uuid %s' % i self.assertEqual(exp, self.client.usernames2uuids( ['name1', 'name2'], 'dont care')) resolve.assert_called_once_with('dont care') validate.assert_called_once_with('t1') get_uuids.assert_called_once_with(['name1', 'name2']) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'AstakosClient': not_found = False runTestCase(AstakosClient, 'Kamaki Astakos Client', argv[2:]) if not argv[1:] or argv[1] == 'LoggedAstakosClient': not_found = False runTestCase(LoggedAstakosClient, 'Logged Astakos Client', argv[2:]) if not argv[1:] or argv[1] == 'CachedAstakosClient': not_found = False runTestCase(CachedAstakosClient, 'Cached Astakos Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
header_calls = [ call('Content-Length', 0), ] prf = 'X-Image-Meta-' if name: header_calls.append(call('%sName' % prf, name)) if disk_format: header_calls.append(call('%sDisk-Format' % prf, disk_format)) if container_format: header_calls.append( call('%sContainer-Format' % prf, container_format)) if status: header_calls.append(call('%sStatus' % prf, status)) if public is not None: header_calls.append(call('%sIs-Public' % prf, public)) if owner_id: header_calls.append(call('%sOwner' % prf, owner_id)) for k, v in properties.items(): header_calls.append(call('%sProperty-%s' % (prf, k), v)) self.assertEqual(sorted(set_header.mock_calls[hcnt:]), sorted(header_calls)) hcnt = len(set_header.mock_calls) self.assertEqual(put.mock_calls[-1], call('/images/%s' % image_id, success=200)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(ImageClient, 'Plankton Client', argv[1:])
status, public, owner_id, properties) = args self.assertEqual(r, FR.headers) header_calls = [call('Content-Length', 0), ] prf = 'X-Image-Meta-' if name: header_calls.append(call('%sName' % prf, name)) if disk_format: header_calls.append(call('%sDisk-Format' % prf, disk_format)) if container_format: header_calls.append( call('%sContainer-Format' % prf, container_format)) if status: header_calls.append(call('%sStatus' % prf, status)) if public is not None: header_calls.append(call('%sIs-Public' % prf, public)) if owner_id: header_calls.append(call('%sOwner' % prf, owner_id)) for k, v in properties.items(): header_calls.append(call('%sProperty-%s' % (prf, k), v)) self.assertEqual( sorted(set_header.mock_calls[hcnt:]), sorted(header_calls)) hcnt = len(set_header.mock_calls) self.assertEqual( put.mock_calls[-1], call('/images/%s' % image_id, success=200)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(ImageClient, 'Plankton Client', argv[1:])
volume_id = 'vid' for args in product(('dn', None), ('dd', None)): self.assertEqual( self.client.create_snapshot(volume_id, *args), 'ret') kwargs = dict(zip(keys, args)) self.assertEqual( create_snapshot.mock_calls[-1], call(volume_id, **kwargs)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'CycladesComputeClient': not_found = False runTestCase(CycladesComputeClient, 'Cyclades Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesNetworkClient': not_found = False runTestCase(CycladesNetworkClient, 'CycladesNetwork Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesComputeRestClient': not_found = False runTestCase(CycladesComputeRestClient, 'CycladesRest Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesBlockStorageRestClient': not_found = False runTestCase( CycladesBlockStorageRestClient, 'Cyclades Block Storage Rest Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesBlockStorageClient': not_found = False runTestCase(
call('format', 'json'), call('limit', None, iff=None), call('marker', None, iff=None), call('prefix', '/lala', iff='/lala'), call('delimiter', 'X', iff='X'), ]) FR.status_code = 304 self.assertEqual(self.client.list_objects(), []) FR.status_code = 404 self.assertRaises(ClientError, self.client.list_objects) @patch('%s.get' % client_pkg, return_value=FR()) @patch('%s.set_param' % client_pkg) def test_list_objects_in_path(self, SP, get): FR.json = object_list path = '/some/awsome/path' acc, cont = self.client.account, self.client.container self.client.list_objects_in_path(path) exp = '/%s/%s' % (acc, cont) get.assert_called_once_with(exp, success=(200, 204, 404)) self.assertEqual( SP.mock_calls, [call('format', 'json'), call('path', path)]) FR.status_code = 404 self.assertRaises(ClientError, self.client.list_objects) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(StorageClient, 'Storage Client', argv[1:])
self.client.start_server(vm_id) SP.assert_called_once_with( vm_id, json_data=dict(start=dict()), success=202) @patch('%s.servers_action_post' % cyclades_pkg, return_value=FR()) def test_get_server_console(self, SP): cnsl = dict(console=dict(info1='i1', info2='i2', info3='i3')) FR.json = cnsl vm_id = vm_recv['server']['id'] r = self.client.get_server_console(vm_id) SP.assert_called_once_with( vm_id, json_data=dict(console=dict(type='vnc')), success=200) self.assert_dicts_are_equal(r, cnsl['console']) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'CycladesClient': not_found = False runTestCase(CycladesNetworkClient, 'Cyclades Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesNetworkClient': not_found = False runTestCase(CycladesNetworkClient, 'CycladesNetwork Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesRestClient': not_found = False runTestCase(CycladesRestClient, 'CycladesRest Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
self.assertEqual(self.client.delete_snapshot('sid'), 'hea') snapshots_delete.assert_called_once_with('sid') @patch('%s.types_get' % rest_pkg, return_value=FakeResponse()) def test_list_volume_types(self, types_get): FakeResponse.json = dict(volume_types='ret list') self.assertEqual(self.client.list_volume_types(), 'ret list') self.assertEqual(types_get.mock_calls[-1], call()) @patch('%s.types_get' % rest_pkg, return_value=FakeResponse()) def test_get_volume_type_details(self, types_get): FakeResponse.json = dict(volume_type='ret dict') self.assertEqual( self.client.get_volume_type_details('vtid'), 'ret dict') self.assertEqual(types_get.mock_calls[-1], call('vtid')) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'BlockStorageRestClient': not_found = False runTestCase( BlockStorageRestClient, 'Block Storage Rest Client', argv[2:]) if not argv[1:] or argv[1] == 'BlockStorageClient': not_found = False runTestCase(BlockStorageClient, 'Block Storage Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
char_pairs = ( ('\b', '\\x08'), ('\n', '\\n'), ('\a', '\\x07'), ('\f', '\\x0c'), ('\t', '\\t'), ('\v', '\\x0b'), ('\r', '\\r'), ('\072', ':'), ('\016', '\\x0e'), ('\\', '\\'), ('\\n', '\\n'), ("'", '\''), ('"', '"'), (u'\u039f\x89', u'\u039f\\x89'), ) for orig_char, esc_char in char_pairs: for word1, word2 in product(('synnefo', gr_kamaki), ('kamaki', gr_synnefo)): orig_str = word1 + orig_char + word2 esc_str = word1 + esc_char + word2 self.assertEqual(utils.escape_ctrl_chars(orig_str), esc_str) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(Utils, 'clients.utils methods', argv[1:])
self.token, self.url, logger=getLogger('astakosclient'))) self.assertEqual(get_endpoints.mock_calls[-1], call()) self.assertEqual(get_usernames.mock_calls[-1], call([42, 43])) @patch( '%s.LoggedAstakosClient.get_uuids' % astakos_pkg, return_value={'username42': 42, 'username43': 43}) def test_usernames2uuids(self, get_uuids): from astakosclient import AstakosClientException self.assertRaises( AstakosClientException, self.client.usernames2uuids, ['u1', 'u2']) with patch( '%s.LoggedAstakosClient.__init__' % astakos_pkg, return_value=None) as sac: with patch( '%s.LoggedAstakosClient.get_endpoints' % astakos_pkg, return_value=example) as get_endpoints: r = self.client.usernames2uuids(['u1', 'u2']) self.assert_dicts_are_equal( r, {'username42': 42, 'username43': 43}) self.assertEqual(sac.mock_calls[-1], call( self.token, self.url, logger=getLogger('astakosclient'))) self.assertEqual(get_endpoints.mock_calls[-1], call()) self.assertEqual(get_uuids.mock_calls[-1], call(['u1', 'u2'])) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase runTestCase(AstakosClient, 'AstakosClient', argv[1:])
import astakosclient self.client._uuids['t1'] = 'uuid 0' self.client._astakos['uuid 0'] = astakosclient.AstakosClient( self.url, self.token) self.client._usernames2uuids['uuid 0'] = dict(name0='uuid 0') exp = dict() for i in range(3): exp['name%s' % i] = 'uuid %s' % i self.assertEqual( exp, self.client.usernames2uuids(['name1', 'name2'], 'dont care')) resolve.assert_called_once_with('dont care') validate.assert_called_once_with('t1') get_uuids.assert_called_once_with(['name1', 'name2']) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'AstakosClient': not_found = False runTestCase(AstakosClient, 'Kamaki Astakos Client', argv[2:]) if not argv[1:] or argv[1] == 'LoggedAstakosClient': not_found = False runTestCase(LoggedAstakosClient, 'Logged Astakos Client', argv[2:]) if not argv[1:] or argv[1] == 'CachedAstakosClient': not_found = False runTestCase(CachedAstakosClient, 'Cached Astakos Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
('fps', None), ('sg', None)): FakeObject.json = dict(port='rv') port_id, network_id = 'pid', 'nid' kwargs = dict( network_id=network_id, name=name, status=status, admin_state_up=admin_state_up, mac_address=mac_address, fixed_ips=fixed_ips, security_groups=security_groups) self.assertEqual( self.client.update_port(port_id, **kwargs), 'rv') req = dict() for k, v in kwargs.items(): if v: req[k] = v expargs = dict(json_data=dict(port=req), success=200) self.assertEqual( ports_put.mock_calls[-1], call(port_id, **expargs)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'NetworkClient': not_found = False runTestCase(NetworkClient, 'Network Client', argv[2:]) if not argv[1:] or argv[1] == 'NetworkRestClient': not_found = False runTestCase(NetworkRestClient, 'NetworkRest Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
def test_create_keypair(self, post): keypair = dict(name=key_name, public_key=public_key, fingerpint="ke:yf:in:ge:rp:in:t") FR.json = dict(keypair=keypair) r = self.client.create_key(key_name=key_name, public_key=public_key) post.assert_called_once_with(json_data=dict(keypair=dict( name=key_name, public_key=public_key)), success=201) self.assert_dicts_are_equal(r, keypair) @patch('%s.keypairs_delete' % compute_pkg, return_value=FR()) def test_delete_keypair(self, delete): FR.json = dict(keypair=keypair_list['keypairs'][0]['keypair']) r = self.client.delete_keypair(key_name) delete.assert_called_once_with(key_name, success=204) self.assert_dicts_are_equal(r, keypair_list['keypairs'][0]['keypair']) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'ComputeClient': not_found = False runTestCase(ComputeClient, 'Compute Client', argv[2:]) if not argv[1:] or argv[1] == 'ComputeRest': not_found = False runTestCase(ComputeRestClient, 'ComputeRest Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
volume_id = 'vid' for args in product(('dn', None), ('dd', None)): self.assertEqual(self.client.create_snapshot(volume_id, *args), 'ret') kwargs = dict(zip(keys, args)) self.assertEqual(create_snapshot.mock_calls[-1], call(volume_id, **kwargs)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'CycladesComputeClient': not_found = False runTestCase(CycladesComputeClient, 'Cyclades Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesNetworkClient': not_found = False runTestCase(CycladesNetworkClient, 'CycladesNetwork Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesComputeRestClient': not_found = False runTestCase(CycladesComputeRestClient, 'CycladesRest Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesBlockStorageRestClient': not_found = False runTestCase(CycladesBlockStorageRestClient, 'Cyclades Block Storage Rest Client', argv[2:]) if not argv[1:] or argv[1] == 'CycladesBlockStorageClient': not_found = False runTestCase(CycladesBlockStorageClient, 'Cyclades Block Storage Client', argv[2:]) if not_found:
ip='102.0.0.1', pool='pisine'), ]) for args in product(('t1', 't2'), (None, 'fip')): r = self.client.get_floating_ip(*args) tenant_id, fip = args self.assertEqual(r, FR.json['floating_ips']) self.assertEqual(get.mock_calls[-1], call(tenant_id, fip)) @patch('%s.floating_ips_delete' % compute_pkg, return_value=FR()) def test_delete_floating_ip(self, delete): for args in product(('t1', 't2'), (None, 'fip')): r = self.client.delete_floating_ip(*args) tenant_id, fip = args self.assertEqual(r, FR.headers) self.assertEqual(delete.mock_calls[-1], call(tenant_id, fip)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'ComputeClient': not_found = False runTestCase(ComputeClient, 'Compute Client', argv[2:]) if not argv[1:] or argv[1] == 'ComputeRest': not_found = False runTestCase(ComputeRestClient, 'ComputeRest Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])
port_id, network_id = 'pid', 'nid' kwargs = dict(network_id=network_id, name=name, status=status, admin_state_up=admin_state_up, mac_address=mac_address, fixed_ips=fixed_ips, security_groups=security_groups) self.assertEqual(self.client.update_port(port_id, **kwargs), 'rv') req = dict() for k, v in kwargs.items(): if v: req[k] = v expargs = dict(json_data=dict(port=req), success=200) self.assertEqual(ports_put.mock_calls[-1], call(port_id, **expargs)) if __name__ == '__main__': from sys import argv from kamaki.clients.test import runTestCase not_found = True if not argv[1:] or argv[1] == 'NetworkClient': not_found = False runTestCase(NetworkClient, 'Network Client', argv[2:]) if not argv[1:] or argv[1] == 'NetworkRestClient': not_found = False runTestCase(NetworkRestClient, 'NetworkRest Client', argv[2:]) if not_found: print('TestCase %s not found' % argv[1])