Backslash continuations (python-keystoneclient)

Fixes bug #940023

Backslash continuations removal for python-keystoneclient

Change-Id: I816fc39ced20bb8ba8a42d3f07a03da94a76f8ea
This commit is contained in:
Zhongyue Luo
2012-02-29 11:31:10 +08:00
parent c10ba52316
commit c8350b7a67
14 changed files with 451 additions and 335 deletions

View File

@@ -107,8 +107,8 @@ class Client(client.HTTPClient):
"url": version_url} "url": version_url}
return results return results
else: else:
results['message'] = "Unrecognized response from %s" \ results['message'] = ("Unrecognized response from %s"
% url % url)
return results return results
except KeyError: except KeyError:
raise exceptions.AuthorizationFailure() raise exceptions.AuthorizationFailure()
@@ -162,8 +162,8 @@ class Client(client.HTTPClient):
results[alias] = name results[alias] = name
return results return results
else: else:
results['message'] = "Unrecognized extensions" \ results['message'] = ("Unrecognized extensions "
" response from %s" % url "response from %s" % url)
return results return results
except KeyError: except KeyError:
raise exceptions.AuthorizationFailure() raise exceptions.AuthorizationFailure()

View File

@@ -47,13 +47,13 @@ def do_discover(cs, args):
print versions['message'] print versions['message']
for key, version in versions.iteritems(): for key, version in versions.iteritems():
if key != 'message': if key != 'message':
print " - supports version %s (%s) here %s" % \ print (" - supports version %s (%s) here %s" %
(version['id'], version['status'], version['url']) (version['id'], version['status'], version['url']))
extensions = cs.discover_extensions(version['url']) extensions = cs.discover_extensions(version['url'])
if extensions: if extensions:
for key, extension in extensions.iteritems(): for key, extension in extensions.iteritems():
if key != 'message': if key != 'message':
print " - and %s: %s" % \ print (" - and %s: %s" %
(key, extension) (key, extension))
else: else:
print "No Keystone-compatible endpoint found" print "No Keystone-compatible endpoint found"

View File

@@ -49,7 +49,7 @@ class OpenStackIdentityShell(object):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='keystone', prog='keystone',
description=__doc__.strip(), description=__doc__.strip(),
epilog='See "keystone help COMMAND" '\ epilog='See "keystone help COMMAND" '
'for help on a specific command.', 'for help on a specific command.',
add_help=False, add_help=False,
formatter_class=OpenStackHelpFormatter, formatter_class=OpenStackHelpFormatter,

View File

@@ -64,8 +64,8 @@ def find_resource(manager, name_or_id):
try: try:
return manager.find(name=name_or_id) return manager.find(name=name_or_id)
except exceptions.NotFound: except exceptions.NotFound:
msg = "No %s with a name or ID of '%s' exists." % \ msg = ("No %s with a name or ID of '%s' exists." %
(manager.resource_class.__name__.lower(), name_or_id) (manager.resource_class.__name__.lower(), name_or_id))
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)

View File

@@ -54,22 +54,24 @@ class ShellTest(utils.TestCase):
shell('user-list') shell('user-list')
assert do_tenant_mock.called assert do_tenant_mock.called
((a, b), c) = do_tenant_mock.call_args ((a, b), c) = do_tenant_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq ' shell('--os_auth_url http://0.0.0.0:5000/ --os_password xyzpdq '
'--os_tenant_id 1234 --os_tenant_name fred ' '--os_tenant_id 1234 --os_tenant_name fred '
'--os_username barney ' '--os_username barney '
'--os_identity_api_version 2.0 user-list') '--os_identity_api_version 2.0 user-list')
assert do_tenant_mock.called assert do_tenant_mock.called
((a, b), c) = do_tenant_mock.call_args ((a, b), c) = do_tenant_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
('http://0.0.0.0:5000/', 'xyzpdq', '1234', expect = ('http://0.0.0.0:5000/', 'xyzpdq', '1234',
'fred', 'barney', '2.0') 'fred', 'barney', '2.0')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_shell_user_create_args(self): def test_shell_user_create_args(self):
"""Test user-create args""" """Test user-create args"""
@@ -85,26 +87,30 @@ class ShellTest(utils.TestCase):
'--pass=secrete --tenant_id=barrr --enabled=true') '--pass=secrete --tenant_id=barrr --enabled=true')
assert do_uc_mock.called assert do_uc_mock.called
((a, b), c) = do_uc_mock.call_args ((a, b), c) = do_uc_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.tenant_id, b.name, b.passwd, b.enabled) == \ self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
('barrr', 'FOO', 'secrete', 'true') actual = (b.tenant_id, b.name, b.passwd, b.enabled)
expect = ('barrr', 'FOO', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# Test case with --os_tenant_id and --tenant_id args present # Test case with --os_tenant_id and --tenant_id args present
shell('--os_tenant_id=os-tenant user-create --name=FOO ' shell('--os_tenant_id=os-tenant user-create --name=FOO '
'--pass=secrete --tenant_id=barrr --enabled=true') '--pass=secrete --tenant_id=barrr --enabled=true')
assert do_uc_mock.called assert do_uc_mock.called
((a, b), c) = do_uc_mock.call_args ((a, b), c) = do_uc_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'os-tenant', expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'os-tenant',
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.tenant_id, b.name, b.passwd, b.enabled) == \ self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
('barrr', 'FOO', 'secrete', 'true') actual = (b.tenant_id, b.name, b.passwd, b.enabled)
expect = ('barrr', 'FOO', 'secrete', 'true')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_do_tenant_create(self): def test_do_tenant_create(self):
do_tenant_mock = mock.MagicMock() do_tenant_mock = mock.MagicMock()
@@ -139,24 +145,30 @@ class ShellTest(utils.TestCase):
'--tenant_id=ec2-tenant --user=ec2-user') '--tenant_id=ec2-tenant --user=ec2-user')
assert do_ec2_mock.called assert do_ec2_mock.called
((a, b), c) = do_ec2_mock.call_args ((a, b), c) = do_ec2_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.tenant_id, b.user) == ('ec2-tenant', 'ec2-user') self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant_id, b.user)
expect = ('ec2-tenant', 'ec2-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
# Test case with two --tenant_id args present # Test case with two --tenant_id args present
shell('--os_tenant_id=os-tenant ec2-credentials-create ' shell('--os_tenant_id=os-tenant ec2-credentials-create '
'--tenant_id=ec2-tenant --user=ec2-user') '--tenant_id=ec2-tenant --user=ec2-user')
assert do_ec2_mock.called assert do_ec2_mock.called
((a, b), c) = do_ec2_mock.call_args ((a, b), c) = do_ec2_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'os-tenant', expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'os-tenant',
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.tenant_id, b.user) == ('ec2-tenant', 'ec2-user') self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.tenant_id, b.user)
expect = ('ec2-tenant', 'ec2-user')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
def test_do_ec2_get(self): def test_do_ec2_get(self):
do_shell_mock = mock.MagicMock() do_shell_mock = mock.MagicMock()
@@ -195,11 +207,14 @@ class ShellTest(utils.TestCase):
'--adminurl=http://example.com:9876/adm') '--adminurl=http://example.com:9876/adm')
assert do_shell_mock.called assert do_shell_mock.called
((a, b), c) = do_shell_mock.call_args ((a, b), c) = do_shell_mock.call_args
assert (b.os_auth_url, b.os_password, b.os_tenant_id, actual = (b.os_auth_url, b.os_password, b.os_tenant_id,
b.os_tenant_name, b.os_username, b.os_tenant_name, b.os_username,
b.os_identity_api_version) == \ b.os_identity_api_version)
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID, expect = (DEFAULT_AUTH_URL, DEFAULT_PASSWORD, DEFAULT_TENANT_ID,
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '') DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.service_id, b.publicurl, b.adminurl) == ('2', self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
actual = (b.service_id, b.publicurl, b.adminurl)
expect = ('2',
'http://example.com:1234/go', 'http://example.com:1234/go',
'http://example.com:9876/adm') 'http://example.com:9876/adm')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))

View File

@@ -33,8 +33,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"user": { "user": {
"id": self.TEST_USER "id": self.TEST_USER
}, },
"serviceCatalog": self.TEST_SERVICE_CATALOG "serviceCatalog": self.TEST_SERVICE_CATALOG,
} },
} }
self.TEST_REQUEST_BODY = { self.TEST_REQUEST_BODY = {
"auth": { "auth": {
@@ -42,21 +42,27 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"username": self.TEST_USER, "username": self.TEST_USER,
"password": self.TEST_TOKEN, "password": self.TEST_TOKEN,
}, },
"tenantId": self.TEST_TENANT_ID "tenantId": self.TEST_TENANT_ID,
} },
} }
self.TEST_REQUEST_HEADERS = { self.TEST_REQUEST_HEADERS = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-Agent': 'python-keystoneclient' 'User-Agent': 'python-keystoneclient',
} }
def test_authenticate_failure(self): def test_authenticate_failure(self):
self.TEST_REQUEST_BODY['auth']['passwordCredentials']['password'] = \ _auth = 'auth'
'bad_key' _cred = 'passwordCredentials'
_pass = 'password'
self.TEST_REQUEST_BODY[_auth][_cred][_pass] = 'bad_key'
resp = httplib2.Response({ resp = httplib2.Response({
"status": 401, "status": 401,
"body": json.dumps({"unauthorized": { "body": json.dumps({
"message": "Unauthorized", "code": "401"}}), "unauthorized": {
"message": "Unauthorized",
"code": "401",
},
}),
}) })
# Implicit retry on API calls, so it gets called twice # Implicit retry on API calls, so it gets called twice
@@ -81,15 +87,21 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_auth_redirect(self): def test_auth_redirect(self):
correct_response = json.dumps(self.TEST_RESPONSE_DICT) correct_response = json.dumps(self.TEST_RESPONSE_DICT)
dict_responses = [ dict_responses = [
{"headers": {'location': self.TEST_ADMIN_URL + "/tokens"}, {
"headers": {
'location': self.TEST_ADMIN_URL + "/tokens",
},
"status": 305, "status": 305,
"body": "Use proxy"}, "body": "Use proxy",
{"headers": {}, },
{
"headers": {},
"status": 200, "status": 200,
"body": correct_response} "body": correct_response,
},
] ]
responses = [(to_http_response(resp), resp['body']) for responses = [(to_http_response(resp), resp['body'])
resp in dict_responses] for resp in dict_responses]
httplib2.Http.request(self.TEST_URL + "/tokens", httplib2.Http.request(self.TEST_URL + "/tokens",
'POST', 'POST',

View File

@@ -28,38 +28,38 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
"updated": "2011-11-19T00:00:00Z", "updated": "2011-11-19T00:00:00Z",
"links": [{ "links": [{
"rel": "self", "rel": "self",
"href": "http://127.0.0.1:5000/v2.0/" "href": "http://127.0.0.1:5000/v2.0/",
}, { }, {
"rel": "describedby", "rel": "describedby",
"type": "text/html", "type": "text/html",
"href": "href": "http://docs.openstack.org/api/"
"http://docs.openstack.org/api/openstack-identity-service/2.0/content/" "openstack-identity-service/2.0/content/",
}, { }, {
"rel": "describedby", "rel": "describedby",
"type": "application/pdf", "type": "application/pdf",
"href": "href": "http://docs.openstack.org/api/"
"http://docs.openstack.org/api/openstack-identity-service/2.0/\ "openstack-identity-service/2.0/"
identity-dev-guide-2.0.pdf" "identity-dev-guide-2.0.pdf",
}, { }, {
"rel": "describedby", "rel": "describedby",
"type": "application/vnd.sun.wadl+xml", "type": "application/vnd.sun.wadl+xml",
"href": "http://127.0.0.1:5000/v2.0/identity.wadl" "href": "http://127.0.0.1:5000/v2.0/identity.wadl",
}], }],
"media-types": [{ "media-types": [{
"base": "application/xml", "base": "application/xml",
"type": "type": "application/"
"application/vnd.openstack.identity-v2.0+xml" "vnd.openstack.identity-v2.0+xml",
}, { }, {
"base": "application/json", "base": "application/json",
"type": "type": "application/"
"application/vnd.openstack.identity-v2.0+json" "vnd.openstack.identity-v2.0+json",
}] }],
}] }],
} },
} }
self.TEST_REQUEST_HEADERS = { self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient', 'User-Agent': 'python-keystoneclient',
'Accept': 'application/json' 'Accept': 'application/json',
} }
def test_get_versions(self): def test_get_versions(self):

View File

@@ -10,21 +10,31 @@ from tests import utils
class EC2Tests(utils.TestCase): class EC2Tests(utils.TestCase):
def setUp(self): def setUp(self):
super(EC2Tests, self).setUp() super(EC2Tests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
}
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
def test_create(self): def test_create(self):
user_id = 'usr' user_id = 'usr'
tenant_id = 'tnt' tenant_id = 'tnt'
req_body = {"tenant_id": tenant_id} req_body = {
resp_body = {"credential": {"access": "access", "tenant_id": tenant_id,
}
resp_body = {
"credential": {
"access": "access",
"secret": "secret", "secret": "secret",
"tenant_id": tenant_id, "tenant_id": tenant_id,
"created": "12/12/12", "created": "12/12/12",
"enabled": True}} "enabled": True,
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -49,11 +59,15 @@ class EC2Tests(utils.TestCase):
def test_get(self): def test_get(self):
user_id = 'usr' user_id = 'usr'
tenant_id = 'tnt' tenant_id = 'tnt'
resp_body = {"credential": {"access": "access", resp_body = {
"credential": {
"access": "access",
"secret": "secret", "secret": "secret",
"tenant_id": tenant_id, "tenant_id": tenant_id,
"created": "12/12/12", "created": "12/12/12",
"enabled": True}} "enabled": True,
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -78,18 +92,26 @@ class EC2Tests(utils.TestCase):
def test_list(self): def test_list(self):
user_id = 'usr' user_id = 'usr'
tenant_id = 'tnt' tenant_id = 'tnt'
resp_body = {"credentials": { resp_body = {
"credentials": {
"values": [ "values": [
{"access": "access", {
"access": "access",
"secret": "secret", "secret": "secret",
"tenant_id": tenant_id, "tenant_id": tenant_id,
"created": "12/12/12", "created": "12/12/12",
"enabled": True}, "enabled": True,
{"access": "another", },
{
"access": "another",
"secret": "key", "secret": "key",
"tenant_id": tenant_id, "tenant_id": tenant_id,
"created": "12/12/31", "created": "12/12/31",
"enabled": True}]}} "enabled": True,
}
]
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
@@ -118,11 +140,12 @@ class EC2Tests(utils.TestCase):
access = 'access' access = 'access'
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
url = urlparse.urljoin(self.TEST_URL, url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2/%s' % (user_id, access)) 'v2.0/users/%s/credentials/OS-EC2/%s' %
(user_id, access))
httplib2.Http.request(url, httplib2.Http.request(url,
'DELETE', 'DELETE',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \

View File

@@ -10,58 +10,54 @@ from tests import utils
class EndpointTests(utils.TestCase): class EndpointTests(utils.TestCase):
def setUp(self): def setUp(self):
super(EndpointTests, self).setUp() super(EndpointTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
self.TEST_ENDPOINTS = {'endpoints': [ }
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
self.TEST_ENDPOINTS = {
'endpoints': [
{ {
'adminurl': 'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'http://host-1:8774/v1.1/$(tenant_id)s', 'id': '8f9531231e044e218824b0e58688d262',
'id': 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'8f9531231e044e218824b0e58688d262', 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'internalurl': 'region': 'RegionOne',
'http://host-1:8774/v1.1/$(tenant_id)s',
'publicurl':
'http://host-1:8774/v1.1/$(tenant_id)s',
'region':
'RegionOne'
}, },
{ {
'adminurl': 'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'http://host-1:8774/v1.1/$(tenant_id)s', 'id': '8f9531231e044e218824b0e58688d263',
'id': 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'8f9531231e044e218824b0e58688d263', 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'internalurl': 'region': 'RegionOne',
'http://host-1:8774/v1.1/$(tenant_id)s',
'publicurl':
'http://host-1:8774/v1.1/$(tenant_id)s',
'region':
'RegionOne'
} }
] ]
} }
def test_create(self): def test_create(self):
req_body = {"endpoint": {"region": "RegionOne", req_body = {
"publicurl": "endpoint": {
"http://host-3:8774/v1.1/$(tenant_id)s", "region": "RegionOne",
"internalurl": "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"http://host-3:8774/v1.1/$(tenant_id)s", "internalurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"adminurl": "adminurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"http://host-3:8774/v1.1/$(tenant_id)s", "service_id": "e044e21",
"service_id": "e044e21"}} }
}
resp_body = {"endpoint": { resp_body = {
"adminurl": "endpoint": {
"http://host-3:8774/v1.1/$(tenant_id)s", "adminurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"region": "RegionOne", "region": "RegionOne",
"id": "1fd485b2ffd54f409a5ecd42cba11401", "id": "1fd485b2ffd54f409a5ecd42cba11401",
"internalurl": "internalurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"http://host-3:8774/v1.1/$(tenant_id)s", "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"publicurl": }
"http://host-3:8774/v1.1/$(tenant_id)s"}} }
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
@@ -88,7 +84,7 @@ class EndpointTests(utils.TestCase):
def test_delete(self): def test_delete(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints/8f953'), 'v2.0/endpoints/8f953'),
@@ -113,5 +109,5 @@ class EndpointTests(utils.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
endpoint_list = self.client.endpoints.list() endpoint_list = self.client.endpoints.list()
[self.assertTrue(isinstance(r, endpoints.Endpoint)) \ [self.assertTrue(isinstance(r, endpoints.Endpoint))
for r in endpoint_list] for r in endpoint_list]

View File

@@ -10,29 +10,42 @@ from tests import utils
class RoleTests(utils.TestCase): class RoleTests(utils.TestCase):
def setUp(self): def setUp(self):
super(RoleTests, self).setUp() super(RoleTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
}
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
self.TEST_ROLES = { self.TEST_ROLES = {
"roles": { "roles": {
"values": [ "values": [
{ {
"name": "admin", "name": "admin",
"id": 1 "id": 1,
}, },
{ {
"name": "member", "name": "member",
"id": 2 "id": 2,
}
]
} }
],
},
} }
def test_create(self): def test_create(self):
req_body = {"role": {"name": "sysadmin"}} req_body = {
resp_body = {"role": {"name": "sysadmin", "id": 3}} "role": {
"name": "sysadmin",
}
}
resp_body = {
"role": {
"name": "sysadmin",
"id": 3,
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -54,7 +67,7 @@ class RoleTests(utils.TestCase):
def test_delete(self): def test_delete(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles/1'), 'v2.0/OS-KSADM/roles/1'),
@@ -68,8 +81,9 @@ class RoleTests(utils.TestCase):
def test_get(self): def test_get(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({'role': "body": json.dumps({
self.TEST_ROLES['roles']['values'][0]}), 'role': self.TEST_ROLES['roles']['values'][0],
}),
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles/1'), 'v2.0/OS-KSADM/roles/1'),

View File

@@ -10,12 +10,17 @@ from tests import utils
class ServiceTests(utils.TestCase): class ServiceTests(utils.TestCase):
def setUp(self): def setUp(self):
super(ServiceTests, self).setUp() super(ServiceTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
self.TEST_SERVICES = {"OS-KSADM:services": { }
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
self.TEST_SERVICES = {
"OS-KSADM:services": {
"values": [ "values": [
{ {
"name": "nova", "name": "nova",
@@ -26,22 +31,29 @@ class ServiceTests(utils.TestCase):
{ {
"name": "keystone", "name": "keystone",
"type": "identity", "type": "identity",
"description": ("Keystone-compatible " "description": "Keystone-compatible service.",
"service."),
"id": 2 "id": 2
} },
] ],
} },
} }
def test_create(self): def test_create(self):
req_body = {"OS-KSADM:service": {"name": "swift", req_body = {
"type": "object-store", "OS-KSADM:service": {
"description": "Swift-compatible service."}} "name": "swift",
resp_body = {"OS-KSADM:service": {"name": "swift",
"type": "object-store", "type": "object-store",
"description": "Swift-compatible service.", "description": "Swift-compatible service.",
"id": 3}} }
}
resp_body = {
"OS-KSADM:service": {
"name": "swift",
"type": "object-store",
"description": "Swift-compatible service.",
"id": 3,
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -66,7 +78,7 @@ class ServiceTests(utils.TestCase):
def test_delete(self): def test_delete(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services/1'), 'v2.0/OS-KSADM/services/1'),
@@ -78,10 +90,10 @@ class ServiceTests(utils.TestCase):
self.client.services.delete(1) self.client.services.delete(1)
def test_get(self): def test_get(self):
test_services = self.TEST_SERVICES['OS-KSADM:services']['values'][0]
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({'OS-KSADM:service': "body": json.dumps({'OS-KSADM:service': test_services}),
self.TEST_SERVICES['OS-KSADM:services']['values'][0]}),
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services/1'), 'v2.0/OS-KSADM/services/1'),
@@ -110,5 +122,5 @@ class ServiceTests(utils.TestCase):
self.mox.ReplayAll() self.mox.ReplayAll()
service_list = self.client.services.list() service_list = self.client.services.list()
[self.assertTrue(isinstance(r, services.Service)) \ [self.assertTrue(isinstance(r, services.Service))
for r in service_list] for r in service_list]

View File

@@ -10,44 +10,57 @@ from tests import utils
class TenantTests(utils.TestCase): class TenantTests(utils.TestCase):
def setUp(self): def setUp(self):
super(TenantTests, self).setUp() super(TenantTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
self.TEST_TENANTS = {"tenants": { }
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
self.TEST_TENANTS = {
"tenants": {
"values": [ "values": [
{ {
"enabled": True, "enabled": True,
"description": "A description change!", "description": "A description change!",
"name": "invisible_to_admin", "name": "invisible_to_admin",
"id": 3 "id": 3,
}, },
{ {
"enabled": True, "enabled": True,
"description": "None", "description": "None",
"name": "demo", "name": "demo",
"id": 2 "id": 2,
}, },
{ {
"enabled": True, "enabled": True,
"description": "None", "description": "None",
"name": "admin", "name": "admin",
"id": 1 "id": 1,
} }
], ],
"links": [] "links": [],
} },
} }
def test_create(self): def test_create(self):
req_body = {"tenant": {"name": "tenantX", req_body = {
"tenant": {
"name": "tenantX",
"description": "Like tenant 9, but better.", "description": "Like tenant 9, but better.",
"enabled": True}} "enabled": True
resp_body = {"tenant": {"name": "tenantX", },
}
resp_body = {
"tenant": {
"name": "tenantX",
"enabled": True, "enabled": True,
"id": 4, "id": 4,
"description": "Like tenant 9, but better."}} "description": "Like tenant 9, but better.",
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -71,7 +84,7 @@ class TenantTests(utils.TestCase):
def test_delete(self): def test_delete(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/1'), 'v2.0/tenants/1'),
@@ -85,8 +98,9 @@ class TenantTests(utils.TestCase):
def test_get(self): def test_get(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({'tenant': "body": json.dumps({
self.TEST_TENANTS['tenants']['values'][2]}), 'tenant': self.TEST_TENANTS['tenants']['values'][2],
}),
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/1'), 'v2.0/tenants/1'),
@@ -165,14 +179,22 @@ class TenantTests(utils.TestCase):
[self.assertTrue(isinstance(t, tenants.Tenant)) for t in tenant_list] [self.assertTrue(isinstance(t, tenants.Tenant)) for t in tenant_list]
def test_update(self): def test_update(self):
req_body = {"tenant": {"id": 4, req_body = {
"tenant": {
"id": 4,
"name": "tenantX", "name": "tenantX",
"description": "I changed you!", "description": "I changed you!",
"enabled": False}} "enabled": False,
resp_body = {"tenant": {"name": "tenantX", },
}
resp_body = {
"tenant": {
"name": "tenantX",
"enabled": False, "enabled": False,
"id": 4, "id": 4,
"description": "I changed you!"}} "description": "I changed you!",
},
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -228,10 +250,14 @@ class TenantTests(utils.TestCase):
self.client.tenants.remove_user('4', 'foo', 'barrr') self.client.tenants.remove_user('4', 'foo', 'barrr')
def test_tenant_add_user(self): def test_tenant_add_user(self):
req_body = {"tenant": {"id": 4, req_body = {
"tenant": {
"id": 4,
"name": "tenantX", "name": "tenantX",
"description": "I changed you!", "description": "I changed you!",
"enabled": False}} "enabled": False,
},
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({}), "body": json.dumps({}),
@@ -252,10 +278,14 @@ class TenantTests(utils.TestCase):
self.assertTrue(isinstance(tenant, tenants.Tenant)) self.assertTrue(isinstance(tenant, tenants.Tenant))
def test_tenant_remove_user(self): def test_tenant_remove_user(self):
req_body = {"tenant": {"id": 4, req_body = {
"tenant": {
"id": 4,
"name": "tenantX", "name": "tenantX",
"description": "I changed you!", "description": "I changed you!",
"enabled": False}} "enabled": False,
},
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({}), "body": json.dumps({}),

View File

@@ -10,11 +10,15 @@ from tests import utils
class UserTests(utils.TestCase): class UserTests(utils.TestCase):
def setUp(self): def setUp(self):
super(UserTests, self).setUp() super(UserTests, self).setUp()
self.TEST_REQUEST_HEADERS = {'X-Auth-Token': 'aToken', self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'} 'User-Agent': 'python-keystoneclient',
}
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient',
}
self.TEST_USERS = { self.TEST_USERS = {
"users": { "users": {
"values": [ "values": [
@@ -22,30 +26,38 @@ class UserTests(utils.TestCase):
"email": "None", "email": "None",
"enabled": True, "enabled": True,
"id": 1, "id": 1,
"name": "admin" "name": "admin",
}, },
{ {
"email": "None", "email": "None",
"enabled": True, "enabled": True,
"id": 2, "id": 2,
"name": "demo" "name": "demo",
}, },
] ]
} }
} }
def test_create(self): def test_create(self):
req_body = {"user": {"name": "gabriel", req_body = {
"user": {
"name": "gabriel",
"password": "test", "password": "test",
"tenantId": 2, "tenantId": 2,
"email": "test@example.com", "email": "test@example.com",
"enabled": True}} "enabled": True,
resp_body = {"user": {"name": "gabriel", }
}
resp_body = {
"user": {
"name": "gabriel",
"enabled": True, "enabled": True,
"tenantId": 2, "tenantId": 2,
"id": 3, "id": 3,
"password": "test", "password": "test",
"email": "test@example.com"}} "email": "test@example.com",
}
}
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
@@ -71,7 +83,7 @@ class UserTests(utils.TestCase):
def test_delete(self): def test_delete(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": "" "body": "",
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'), httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'),
'DELETE', 'DELETE',
@@ -84,7 +96,9 @@ class UserTests(utils.TestCase):
def test_get(self): def test_get(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps({'user': self.TEST_USERS['users']['values'][0]}) "body": json.dumps({
'user': self.TEST_USERS['users']['values'][0],
})
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/1'), 'v2.0/users/1'),

View File

@@ -144,8 +144,8 @@ class Fedora(Distro):
def get_distro(): def get_distro():
if os.path.exists('/etc/fedora-release') or \ if (os.path.exists('/etc/fedora-release') or
os.path.exists('/etc/redhat-release'): os.path.exists('/etc/redhat-release')):
return Fedora() return Fedora()
elif os.path.exists('/etc/debian_version'): elif os.path.exists('/etc/debian_version'):
return Debian() return Debian()