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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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