pep8 1.1 changes and updates

Change-Id: I8bc3582bb3f35a3d841bb1e8c03b62ba61ff92d7
This commit is contained in:
Joe Heck
2012-06-01 18:07:26 -07:00
parent aa97614330
commit 52b392281e
22 changed files with 398 additions and 374 deletions

View File

@@ -131,7 +131,7 @@ class ManagerWithFind(Manager):
for obj in self.list():
try:
if all(getattr(obj, attr) == value
for (attr, value) in searches):
for (attr, value) in searches):
found.append(obj)
except AttributeError:
continue
@@ -171,7 +171,7 @@ class Resource(object):
def __repr__(self):
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
k != 'manager')
k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)

View File

@@ -101,8 +101,12 @@ class HTTPNotImplemented(ClientException):
# for c in ClientException.__subclasses__())
#
# Instead, we have to hardcode it:
_code_map = dict((c.http_status, c) for c in [BadRequest, Unauthorized,
Forbidden, NotFound, OverLimit, HTTPNotImplemented])
_code_map = dict((c.http_status, c) for c in [BadRequest,
Unauthorized,
Forbidden,
NotFound,
OverLimit,
HTTPNotImplemented])
def from_response(response, body):

View File

@@ -82,7 +82,8 @@ class Client(client.HTTPClient):
try:
httpclient = client.HTTPClient()
resp, body = httpclient.request(url, "GET",
headers={'Accept': 'application/json'})
headers={'Accept':
'application/json'})
if resp.status in (200, 204): # in some cases we get No Content
try:
results = {}
@@ -90,8 +91,8 @@ class Client(client.HTTPClient):
results['message'] = "Keystone found at %s" % url
version = body['version']
# Stable/diablo incorrect format
id, status, version_url = self._get_version_info(
version, url)
id, status, version_url = \
self._get_version_info(version, url)
results[str(id)] = {"id": id,
"status": status,
"url": version_url}
@@ -100,8 +101,8 @@ class Client(client.HTTPClient):
# Correct format
results['message'] = "Keystone found at %s" % url
for version in body['versions']['values']:
id, status, version_url = self._get_version_info(
version, url)
id, status, version_url = \
self._get_version_info(version, url)
results[str(id)] = {"id": id,
"status": status,
"url": version_url}
@@ -142,7 +143,8 @@ class Client(client.HTTPClient):
if not url.endswith("/"):
url += '/'
resp, body = httpclient.request("%sextensions" % url, "GET",
headers={'Accept': 'application/json'})
headers={'Accept':
'application/json'})
if resp.status in (200, 204): # in some cases we get No Content
try:
results = {}
@@ -150,15 +152,17 @@ class Client(client.HTTPClient):
if 'values' in body['extensions']:
# Parse correct format (per contract)
for extension in body['extensions']['values']:
alias, name = self._get_extension_info(
extension['extension'])
alias, name = \
self._get_extension_info(
extension['extension']
)
results[alias] = name
return results
else:
# Support incorrect, but prevalent format
for extension in body['extensions']:
alias, name = self._get_extension_info(
extension)
alias, name = \
self._get_extension_info(extension)
results[alias] = name
return results
else:

View File

@@ -29,7 +29,7 @@ class ServiceCatalog(object):
def get_token(self):
"""Fetch token details fron service catalog"""
token = {'id': self.catalog['token']['id'],
'expires': self.catalog['token']['expires']}
'expires': self.catalog['token']['expires']}
try:
token['user_id'] = self.catalog['user']['id']
token['tenant_id'] = self.catalog['token']['tenant']['id']

View File

@@ -56,70 +56,85 @@ class OpenStackIdentityShell(object):
)
# Global arguments
parser.add_argument('-h', '--help',
action='store_true',
help=argparse.SUPPRESS,
)
parser.add_argument('-h',
'--help',
action='store_true',
help=argparse.SUPPRESS)
parser.add_argument('--debug',
default=False,
action='store_true',
help=argparse.SUPPRESS)
default=False,
action='store_true',
help=argparse.SUPPRESS)
parser.add_argument('--os_username', metavar='<auth-user-name>',
default=env('OS_USERNAME'),
help='Defaults to env[OS_USERNAME]')
parser.add_argument('--os_username',
metavar='<auth-user-name>',
default=env('OS_USERNAME'),
help='Defaults to env[OS_USERNAME]')
parser.add_argument('--os_password', metavar='<auth-password>',
default=env('OS_PASSWORD'),
help='Defaults to env[OS_PASSWORD]')
parser.add_argument('--os_password',
metavar='<auth-password>',
default=env('OS_PASSWORD'),
help='Defaults to env[OS_PASSWORD]')
parser.add_argument('--os_tenant_name', metavar='<auth-tenant-name>',
default=env('OS_TENANT_NAME'),
help='Defaults to env[OS_TENANT_NAME]')
parser.add_argument('--os_tenant_name',
metavar='<auth-tenant-name>',
default=env('OS_TENANT_NAME'),
help='Defaults to env[OS_TENANT_NAME]')
parser.add_argument('--os_tenant_id', metavar='<tenant-id>',
default=env('OS_TENANT_ID'),
help='Defaults to env[OS_TENANT_ID]')
parser.add_argument('--os_tenant_id',
metavar='<tenant-id>',
default=env('OS_TENANT_ID'),
help='Defaults to env[OS_TENANT_ID]')
parser.add_argument('--os_auth_url', metavar='<auth-url>',
default=env('OS_AUTH_URL'),
help='Defaults to env[OS_AUTH_URL]')
parser.add_argument('--os_auth_url',
metavar='<auth-url>',
default=env('OS_AUTH_URL'),
help='Defaults to env[OS_AUTH_URL]')
parser.add_argument('--os_region_name', metavar='<region-name>',
default=env('OS_REGION_NAME'),
help='Defaults to env[OS_REGION_NAME]')
parser.add_argument('--os_region_name',
metavar='<region-name>',
default=env('OS_REGION_NAME'),
help='Defaults to env[OS_REGION_NAME]')
parser.add_argument('--os_identity_api_version',
metavar='<identity-api-version>',
default=env('OS_IDENTITY_API_VERSION', 'KEYSTONE_VERSION'),
help='Defaults to env[OS_IDENTITY_API_VERSION] or 2.0')
metavar='<identity-api-version>',
default=env('OS_IDENTITY_API_VERSION',
'KEYSTONE_VERSION'),
help='Defaults to env[OS_IDENTITY_API_VERSION]'
' or 2.0')
parser.add_argument('--token', metavar='<service-token>',
default=env('SERVICE_TOKEN'),
help='Defaults to env[SERVICE_TOKEN]')
parser.add_argument('--token',
metavar='<service-token>',
default=env('SERVICE_TOKEN'),
help='Defaults to env[SERVICE_TOKEN]')
parser.add_argument('--endpoint', metavar='<service-endpoint>',
default=env('SERVICE_ENDPOINT'),
help='Defaults to env[SERVICE_ENDPOINT]')
parser.add_argument('--endpoint',
metavar='<service-endpoint>',
default=env('SERVICE_ENDPOINT'),
help='Defaults to env[SERVICE_ENDPOINT]')
# FIXME(dtroyer): The args below are here for diablo compatibility,
# remove them in folsum cycle
parser.add_argument('--username', metavar='<auth-user-name>',
help='Deprecated')
parser.add_argument('--username',
metavar='<auth-user-name>',
help='Deprecated')
parser.add_argument('--password', metavar='<auth-password>',
help='Deprecated')
parser.add_argument('--password',
metavar='<auth-password>',
help='Deprecated')
parser.add_argument('--tenant_name', metavar='<tenant-name>',
help='Deprecated')
parser.add_argument('--tenant_name',
metavar='<tenant-name>',
help='Deprecated')
parser.add_argument('--auth_url', metavar='<auth-url>',
help='Deprecated')
parser.add_argument('--auth_url',
metavar='<auth-url>',
help='Deprecated')
parser.add_argument('--region_name', metavar='<region-name>',
help='Deprecated')
parser.add_argument('--region_name',
metavar='<region-name>',
help='Deprecated')
return parser
@@ -151,16 +166,14 @@ class OpenStackIdentityShell(object):
help = desc.strip().split('\n')[0]
arguments = getattr(callback, 'arguments', [])
subparser = subparsers.add_parser(command,
subparser = subparsers.add_parser(
command,
help=help,
description=desc,
add_help=False,
formatter_class=OpenStackHelpFormatter
)
subparser.add_argument('-h', '--help',
action='help',
help=argparse.SUPPRESS,
)
formatter_class=OpenStackHelpFormatter)
subparser.add_argument('-h', '--help', action='help',
help=argparse.SUPPRESS)
self.subcommands[command] = subparser
for (args, kwargs) in arguments:
subparser.add_argument(*args, **kwargs)
@@ -219,12 +232,14 @@ class OpenStackIdentityShell(object):
if args.token or args.endpoint and not (
args.token and args.endpoint):
if not args.token:
raise exc.CommandError('Expecting a token provided '
'via either --token or env[SERVICE_TOKEN]')
raise exc.CommandError(
'Expecting a token provided via either --token or '
'env[SERVICE_TOKEN]')
if not args.endpoint:
raise exc.CommandError('Expecting an endpoint provided '
'via either --endpoint or env[SERVICE_ENDPOINT]')
raise exc.CommandError(
'Expecting an endpoint provided via either --endpoint '
'or env[SERVICE_ENDPOINT]')
# if it looks like the user wants to provide a credentials
# but is missing something
@@ -232,16 +247,19 @@ class OpenStackIdentityShell(object):
and not (args.os_username and args.os_password and
args.os_auth_url)):
if not args.os_username:
raise exc.CommandError('Expecting a username provided '
'via either --os_username or env[OS_USERNAME]')
raise exc.CommandError(
'Expecting a username provided via either '
'--os_username or env[OS_USERNAME]')
if not args.os_password:
raise exc.CommandError('Expecting a password provided '
'via either --os_password or env[OS_PASSWORD]')
raise exc.CommandError(
'Expecting a password provided via either '
'--os_password or env[OS_PASSWORD]')
if not args.os_auth_url:
raise exc.CommandError('Expecting an auth URL '
'via either --os_auth_url or env[OS_AUTH_URL]')
raise exc.CommandError(
'Expecting an auth URL via either --os_auth_url or '
'env[OS_AUTH_URL]')
if utils.isunauthenticated(args.func):
self.cs = shell_generic.CLIENT_CLASS(endpoint=args.os_auth_url)

View File

@@ -127,8 +127,9 @@ class Client(client.HTTPClient):
# in fact we should rewrite the client to support the service
# catalog (api calls should be directable to any endpoints)
try:
self.management_url = self.service_catalog.url_for(attr='region',
filter_value=self.region_name, endpoint_type='adminURL')
self.management_url = self.service_catalog.url_for(
attr='region', filter_value=self.region_name,
endpoint_type='adminURL')
except:
# Unscoped tokens don't return a service catalog
_logger.exception("unable to retrieve service catalog with token")

View File

@@ -44,7 +44,7 @@ class CredentialsManager(base.ManagerWithFind):
:rtype: list of :class:`EC2`
"""
return self._list("/users/%s/credentials/OS-EC2" % user_id,
"credentials")
"credentials")
def get(self, user_id, access):
"""
@@ -59,4 +59,4 @@ class CredentialsManager(base.ManagerWithFind):
Delete an access/secret pair for a user
"""
return self._delete("/users/%s/credentials/OS-EC2/%s" %
(user_id, base.getid(access)))
(user_id, base.getid(access)))

View File

@@ -29,10 +29,10 @@ class EndpointManager(base.ManagerWithFind):
def create(self, region, service_id, publicurl, adminurl, internalurl):
body = {'endpoint': {'region': region,
'service_id': service_id,
'publicurl': publicurl,
'adminurl': adminurl,
'internalurl': internalurl}}
'service_id': service_id,
'publicurl': publicurl,
'adminurl': adminurl,
'internalurl': internalurl}}
return self._create('/endpoints', body, 'endpoint')
def delete(self, id):

View File

@@ -118,8 +118,8 @@ def do_tenant_get(kc, args):
def do_tenant_create(kc, args):
"""Create new tenant"""
tenant = kc.tenants.create(args.name,
description=args.description,
enabled=utils.string_to_bool(args.enabled))
description=args.description,
enabled=utils.string_to_bool(args.enabled))
utils.print_dict(tenant._info)
@@ -157,7 +157,7 @@ def do_tenant_delete(kc, args):
help='Name of new service (must be unique)')
@utils.arg('--type', metavar='<type>', required=True,
help='Service type (one of: identity, compute, network, '
'image, or object-store)')
'image, or object-store)')
@utils.arg('--description', metavar='<service-description>',
help='Description of service')
def do_service_create(kc, args):
@@ -270,7 +270,7 @@ def do_ec2_credentials_create(kc, args):
@utils.arg('--user_id', metavar='<user-id>', help='User ID')
@utils.arg('--access', metavar='<access-key>', required=True,
help='Access Key')
help='Access Key')
def do_ec2_credentials_get(kc, args):
"""Display EC2-compatibile credentials"""
if not args.user_id:
@@ -300,7 +300,7 @@ def do_ec2_credentials_list(kc, args):
@utils.arg('--user_id', metavar='<user-id>', help='User ID')
@utils.arg('--access', metavar='<access-key>', required=True,
help='Access Key')
help='Access Key')
def do_ec2_credentials_delete(kc, args):
"""Delete EC2-compatibile credentials"""
if not args.user_id:
@@ -369,9 +369,11 @@ def do_endpoint_list(kc, args):
help='Internal URL endpoint')
def do_endpoint_create(kc, args):
"""Create a new endpoint associated with a service"""
endpoint = kc.endpoints.create(
args.region, args.service_id, args.publicurl,
args.adminurl, args.internalurl)
endpoint = kc.endpoints.create(args.region,
args.service_id,
args.publicurl,
args.adminurl,
args.internalurl)
utils.print_dict(endpoint._info)

View File

@@ -48,8 +48,8 @@ class Tenant(base.Resource):
def remove_user(self, user, role):
return self.manager.api.roles.remove_user_role(base.getid(user),
base.getid(role),
self.id)
base.getid(role),
self.id)
def list_users(self):
return self.manager.list_users(self.id)

View File

@@ -57,7 +57,7 @@ class UserManager(base.ManagerWithFind):
"enabled": enabled}}
self._update("/users/%s/OS-KSADM/enabled" % base.getid(user), params,
"user")
"user")
def update_password(self, user, password):
"""

View File

@@ -33,8 +33,7 @@ class ClientTest(utils.TestCase):
def test_get_call():
resp, body = cl.get("/hi")
headers = {"X-Auth-Token": "token",
"User-Agent": cl.USER_AGENT,
}
"User-Agent": cl.USER_AGENT}
mock_request.assert_called_with("http://127.0.0.1:5000/hi",
"GET", headers=headers)
# Automatic JSON parsing

View File

@@ -20,54 +20,52 @@ SERVICE_CATALOG = {
"id": "123",
"name": "jqsmith",
"roles": [{
"id": "234",
"name": "compute:admin"
},
{
"id": "235",
"name": "object-store:admin",
"tenantId": "1"
}
],
"id": "234",
"name": "compute:admin"
},
{
"id": "235",
"name": "object-store:admin",
"tenantId": "1"
}],
"roles_links": []
},
"serviceCatalog": [{
"name": "Cloud Servers",
"type": "compute",
"endpoints": [{
"tenantId": "1",
"publicURL": "https://compute.north.host/v1/1234",
"internalURL": "https://compute.north.host/v1/1234",
"region": "North",
"versionId": "1.0",
"versionInfo": "https://compute.north.host/v1.0/",
"versionList": "https://compute.north.host/"
},
{
"tenantId": "2",
"publicURL": "https://compute.north.host/v1.1/3456",
"internalURL": "https://compute.north.host/v1.1/3456",
"region": "North",
"versionId": "1.1",
"versionInfo": "https://compute.north.host/v1.1/",
"versionList": "https://compute.north.host/"
}
],
"endpoints_links": []
"name": "Cloud Servers",
"type": "compute",
"endpoints": [{
"tenantId": "1",
"publicURL": "https://compute.north.host/v1/1234",
"internalURL": "https://compute.north.host/v1/1234",
"region": "North",
"versionId": "1.0",
"versionInfo": "https://compute.north.host/v1.0/",
"versionList": "https://compute.north.host/"
},
{
"tenantId": "2",
"publicURL": "https://compute.north.host/v1.1/3456",
"internalURL": "https://compute.north.host/v1.1/3456",
"region": "North",
"versionId": "1.1",
"versionInfo": "https://compute.north.host/v1.1/",
"versionList": "https://compute.north.host/"
}],
"endpoints_links": []
},
{
"name": "Cloud Files",
"type": "object-store",
"endpoints": [{
"tenantId": "11",
"publicURL": "https://compute.north.host/v1/blah-blah",
"internalURL": "https://compute.north.host/v1/blah-blah",
"region": "South",
"versionId": "1.0",
"versionInfo": "uri",
"versionList": "uri"
},
{
"tenantId": "11",
"publicURL": "https://compute.north.host/v1/blah-blah",
"internalURL": "https://compute.north.host/v1/blah-blah",
"region": "South",
"versionId": "1.0",
"versionInfo": "uri",
"versionList": "uri"
},
{
"tenantId": "2",
"publicURL": "https://compute.north.host/v1.1/blah-blah",
"internalURL": "https://compute.north.host/v1.1/blah-blah",
@@ -75,21 +73,19 @@ SERVICE_CATALOG = {
"versionId": "1.1",
"versionInfo": "https://compute.north.host/v1.1/",
"versionList": "https://compute.north.host/"
}
],
}],
"endpoints_links":[{
"rel":"next",
"href":"https://identity.north.host/v2.0/endpoints?marker=2"
}
]
"rel":"next",
"href":"https://identity.north.host/v2.0/"
"endpoints?marker=2"
}]
}
],
"serviceCatalog_links": [{
"rel": "next",
"href": ("https://identity.host/v2.0/endpoints?"
"session=2hfh8Ar&marker=2")
}
]
"rel": "next",
"href": ("https://identity.host/v2.0/endpoints?"
"session=2hfh8Ar&marker=2")
}]
}
}
@@ -105,27 +101,26 @@ class ServiceCatalogTest(utils.TestCase):
self.assertEquals(sc.url_for('tenantId', '2', service_type='compute'),
"https://compute.north.host/v1.1/3456")
self.assertRaises(exceptions.EndpointNotFound,
sc.url_for, "region", "South", service_type='compute')
self.assertRaises(exceptions.EndpointNotFound, sc.url_for, "region",
"South", service_type='compute')
def test_service_catalog_endpoints(self):
sc = service_catalog.ServiceCatalog(SERVICE_CATALOG['access'])
public_ep = sc.get_endpoints(service_type='compute',
endpoint_type='publicURL')
endpoint_type='publicURL')
self.assertEquals(public_ep['compute'][1]['tenantId'], '2')
self.assertEquals(public_ep['compute'][1]['versionId'], '1.1')
self.assertEquals(public_ep['compute'][1]['internalURL'],
"https://compute.north.host/v1.1/3456")
"https://compute.north.host/v1.1/3456")
def test_token(self):
sc = service_catalog.ServiceCatalog(SERVICE_CATALOG['access'])
self.assertEquals(sc.get_token(),
{'id': 'ab48a9efdfedb23ty3494',
'tenant_id': '345',
'user_id': '123',
'expires': '2010-11-01T03:32:15-05:00'})
self.assertEquals(sc.get_token(), {
'id': 'ab48a9efdfedb23ty3494',
'tenant_id': '345',
'user_id': '123',
'expires': '2010-11-01T03:32:15-05:00'})
self.assertEquals(sc.catalog['token']['expires'],
"2010-11-01T03:32:15-05:00")
self.assertEquals(sc.catalog['token']['tenant']['id'],
'345')
"2010-11-01T03:32:15-05:00")
self.assertEquals(sc.catalog['token']['tenant']['id'], '345')

View File

@@ -28,27 +28,27 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"id": self.TEST_TOKEN,
"tenant": {
"id": self.TEST_TENANT_ID
},
},
},
"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,
},
"tenantId": self.TEST_TENANT_ID,
},
}
"tenantId": self.TEST_TENANT_ID,
},
}
self.TEST_REQUEST_HEADERS = {
'Content-Type': 'application/json',
'User-Agent': 'python-keystoneclient',
}
}
def test_authenticate_failure(self):
_auth = 'auth'
@@ -61,21 +61,21 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
"unauthorized": {
"message": "Unauthorized",
"code": "401",
},
}),
})
},
}),
})
# Implicit retry on API calls, so it gets called twice
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
# Workaround for issue with assertRaises on python2.6
@@ -95,16 +95,16 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
{
"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]
@@ -112,12 +112,12 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn(responses[0])
.AndReturn(responses[0])
httplib2.Http.request(self.TEST_ADMIN_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn(responses[1])
.AndReturn(responses[1])
self.mox.ReplayAll()
cs = client.Client(username=self.TEST_USER,
@@ -127,7 +127,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["adminURL"])
['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
@@ -135,13 +135,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client(username=self.TEST_USER,
@@ -150,7 +150,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["adminURL"])
['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
@@ -160,13 +160,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client(username=self.TEST_USER,
@@ -183,13 +183,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client(token=self.TEST_TOKEN,
@@ -197,7 +197,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
auth_url=self.TEST_URL)
self.assertEqual(cs.management_url,
self.TEST_RESPONSE_DICT["access"]["serviceCatalog"][3]
['endpoints'][0]["adminURL"])
['endpoints'][0]["adminURL"])
self.assertEqual(cs.auth_token,
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
@@ -210,13 +210,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request(self.TEST_URL + "/tokens",
'POST',
body=json.dumps(self.TEST_REQUEST_BODY),
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client(token=self.TEST_TOKEN,

View File

@@ -26,14 +26,14 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
"id": "v2.0",
"status": "beta",
"updated": "2011-11-19T00:00:00Z",
"links": [{
"rel": "self",
"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/",
"links": [
{"rel": "self",
"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/",
}, {
"rel": "describedby",
"type": "application/pdf",
@@ -46,32 +46,31 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
"href": "http://127.0.0.1:5000/v2.0/identity.wadl",
}],
"media-types": [{
"base": "application/xml",
"type": "application/"
"vnd.openstack.identity-v2.0+xml",
}, {
"base": "application/json",
"type": "application/"
"vnd.openstack.identity-v2.0+json",
}],
"base": "application/xml",
"type": "application/vnd.openstack.identity-v2.0+xml",
},
{
"base": "application/json",
"type": "application/vnd.openstack.identity-v2.0+json",
}],
},
}
}],
},
}
self.TEST_REQUEST_HEADERS = {
'User-Agent': 'python-keystoneclient',
'Accept': 'application/json',
}
}
def test_get_versions(self):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request(self.TEST_ROOT_URL,
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client()
@@ -79,20 +78,21 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
self.assertIsInstance(versions, dict)
self.assertIn('message', versions)
self.assertIn('v2.0', versions)
self.assertEquals(versions['v2.0']['url'],
self.assertEquals(
versions['v2.0']['url'],
self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
['href'])
['href'])
def test_get_version_local(self):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT),
})
})
httplib2.Http.request("http://localhost:35357",
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cs = client.Client()
@@ -100,6 +100,7 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
self.assertIsInstance(versions, dict)
self.assertIn('message', versions)
self.assertIn('v2.0', versions)
self.assertEquals(versions['v2.0']['url'],
self.assertEquals(
versions['v2.0']['url'],
self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
['href'])
['href'])

View File

@@ -13,19 +13,19 @@ class EC2Tests(utils.TestCase):
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",
@@ -33,12 +33,12 @@ class EC2Tests(utils.TestCase):
"tenant_id": tenant_id,
"created": "12/12/12",
"enabled": True,
}
}
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps(resp_body),
})
})
url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2' % user_id)
@@ -46,7 +46,7 @@ class EC2Tests(utils.TestCase):
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cred = self.client.ec2.create(user_id, tenant_id)
@@ -66,12 +66,12 @@ class EC2Tests(utils.TestCase):
"tenant_id": tenant_id,
"created": "12/12/12",
"enabled": True,
}
}
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps(resp_body),
})
})
url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2/%s' %
@@ -79,7 +79,7 @@ class EC2Tests(utils.TestCase):
httplib2.Http.request(url,
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
cred = self.client.ec2.get(user_id, 'access')
@@ -101,29 +101,29 @@ class EC2Tests(utils.TestCase):
"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,
"body": json.dumps(resp_body),
})
})
url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2' % user_id)
httplib2.Http.request(url,
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
creds = self.client.ec2.list(user_id)
@@ -141,7 +141,7 @@ class EC2Tests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2/%s' %
@@ -149,7 +149,7 @@ class EC2Tests(utils.TestCase):
httplib2.Http.request(url,
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.ec2.delete(user_id, access)

View File

@@ -13,12 +13,12 @@ class EndpointTests(utils.TestCase):
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': [
{
@@ -27,16 +27,16 @@ class EndpointTests(utils.TestCase):
'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 = {
@@ -46,8 +46,8 @@ class EndpointTests(utils.TestCase):
"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": {
@@ -56,20 +56,20 @@ class EndpointTests(utils.TestCase):
"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,
"body": json.dumps(resp_body),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
endpoint = self.client.endpoints.create(
@@ -85,12 +85,12 @@ class EndpointTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints/8f953'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.endpoints.delete('8f953')
@@ -99,13 +99,13 @@ class EndpointTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_ENDPOINTS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
endpoint_list = self.client.endpoints.list()

View File

@@ -13,50 +13,50 @@ class RoleTests(utils.TestCase):
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,
}
],
},
}
}
],
},
}
def test_create(self):
req_body = {
"role": {
"name": "sysadmin",
}
}
}
resp_body = {
"role": {
"name": "sysadmin",
"id": 3,
}
}
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps(resp_body),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role = self.client.roles.create(req_body['role']['name'])
@@ -68,12 +68,12 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.roles.delete(1)
@@ -83,13 +83,13 @@ class RoleTests(utils.TestCase):
"status": 200,
"body": json.dumps({
'role': self.TEST_ROLES['roles']['values'][0],
}),
})
}),
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles/1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role = self.client.roles.get(1)
@@ -101,13 +101,13 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_ROLES),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/roles'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role_list = self.client.roles.list()
@@ -117,13 +117,13 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_ROLES),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/foo/roles'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role_list = self.client.roles.roles_for_user('foo')
@@ -133,13 +133,13 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_ROLES),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/barrr/users/foo/roles'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
role_list = self.client.roles.roles_for_user('foo', 'barrr')
@@ -149,14 +149,14 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/foo/roles/OS-KSADM/barrr'),
'PUT',
body='null',
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.roles.add_user_role('foo', 'barrr')
@@ -165,14 +165,14 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'PUT',
body='null',
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.roles.add_user_role('foo', 'barrr', '4')
@@ -181,13 +181,13 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/foo/roles/OS-KSADM/barrr'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.roles.remove_user_role('foo', 'barrr')
@@ -196,13 +196,13 @@ class RoleTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.roles.remove_user_role('foo', 'barrr', '4')

View File

@@ -13,12 +13,12 @@ class ServiceTests(utils.TestCase):
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": [
@@ -27,16 +27,16 @@ class ServiceTests(utils.TestCase):
"type": "compute",
"description": "Nova-compatible service.",
"id": 1
},
},
{
"name": "keystone",
"type": "identity",
"description": "Keystone-compatible service.",
"id": 2
},
],
},
}
},
],
},
}
def test_create(self):
req_body = {
@@ -44,33 +44,33 @@ class ServiceTests(utils.TestCase):
"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),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
service = self.client.services.create(
req_body['OS-KSADM:service']['name'],
req_body['OS-KSADM:service']['type'],
req_body['OS-KSADM:service']['description'])
req_body['OS-KSADM:service']['name'],
req_body['OS-KSADM:service']['type'],
req_body['OS-KSADM:service']['description'])
self.assertTrue(isinstance(service, services.Service))
self.assertEqual(service.id, 3)
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
@@ -79,12 +79,12 @@ class ServiceTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.services.delete(1)
@@ -94,12 +94,12 @@ class ServiceTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({'OS-KSADM:service': test_services}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services/1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
service = self.client.services.get(1)
@@ -112,13 +112,13 @@ class ServiceTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_SERVICES),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/OS-KSADM/services'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
service_list = self.client.services.list()

View File

@@ -13,12 +13,12 @@ class TenantTests(utils.TestCase):
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": [
@@ -27,20 +27,20 @@ class TenantTests(utils.TestCase):
"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": [],
},
}
@@ -51,26 +51,26 @@ class TenantTests(utils.TestCase):
"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),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/tenants'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant = self.client.tenants.create(req_body['tenant']['name'],
@@ -85,12 +85,12 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.tenants.delete(1)
@@ -100,13 +100,13 @@ class TenantTests(utils.TestCase):
"status": 200,
"body": json.dumps({
'tenant': self.TEST_TENANTS['tenants']['values'][2],
}),
})
}),
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
t = self.client.tenants.get(1)
@@ -118,13 +118,13 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_TENANTS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant_list = self.client.tenants.list()
@@ -134,13 +134,13 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_TENANTS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants?limit=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant_list = self.client.tenants.list(limit=1)
@@ -150,13 +150,13 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_TENANTS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants?marker=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant_list = self.client.tenants.list(marker=1)
@@ -166,13 +166,13 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_TENANTS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants?marker=1&limit=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant_list = self.client.tenants.list(limit=1, marker=1)
@@ -185,27 +185,27 @@ class TenantTests(utils.TestCase):
"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),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
tenant = self.client.tenants.update(req_body['tenant']['id'],
@@ -222,14 +222,14 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'PUT',
body='null',
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.tenants.add_user('4', 'foo', 'barrr')
@@ -238,13 +238,13 @@ class TenantTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
self.client.tenants.remove_user('4', 'foo', 'barrr')
@@ -256,19 +256,19 @@ class TenantTests(utils.TestCase):
"name": "tenantX",
"description": "I changed you!",
"enabled": False,
},
}
},
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'PUT',
body='null',
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
# make tenant object with manager
@@ -284,18 +284,18 @@ class TenantTests(utils.TestCase):
"name": "tenantX",
"description": "I changed you!",
"enabled": False,
},
}
},
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps({}),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/tenants/4/users/foo/roles/OS-KSADM/barrr'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, None))
.AndReturn((resp, None))
self.mox.ReplayAll()
# make tenant object with manager

View File

@@ -9,12 +9,12 @@ class TokenTests(utils.TestCase):
def setUp(self):
super(TokenTests, self).setUp()
self.TEST_REQUEST_HEADERS = {
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'}
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'}
self.TEST_POST_HEADERS = {
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'}
'Content-Type': 'application/json',
'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient'}
def test_delete(self):
resp = httplib2.Response({
@@ -22,9 +22,9 @@ class TokenTests(utils.TestCase):
"body": ""})
req = httplib2.Http.request(
urlparse.urljoin(self.TEST_URL, 'v2.0/tokens/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS)
urlparse.urljoin(self.TEST_URL, 'v2.0/tokens/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS)
req.AndReturn((resp, resp['body']))
self.mox.ReplayAll()

View File

@@ -13,12 +13,12 @@ class UserTests(utils.TestCase):
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": [
@@ -27,16 +27,16 @@ class UserTests(utils.TestCase):
"enabled": True,
"id": 1,
"name": "admin",
},
},
{
"email": "None",
"enabled": True,
"id": 2,
"name": "demo",
},
]
}
},
]
}
}
def test_create(self):
req_body = {
@@ -46,8 +46,8 @@ class UserTests(utils.TestCase):
"tenantId": 2,
"email": "test@example.com",
"enabled": True,
}
}
}
resp_body = {
"user": {
"name": "gabriel",
@@ -56,18 +56,18 @@ class UserTests(utils.TestCase):
"id": 3,
"password": "test",
"email": "test@example.com",
}
}
}
resp = httplib2.Response({
"status": 200,
"body": json.dumps(resp_body),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users'),
'POST',
body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
user = self.client.users.create(req_body['user']['name'],
@@ -84,11 +84,11 @@ class UserTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": "",
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, 'v2.0/users/1'),
'DELETE',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
self.client.users.delete(1)
@@ -98,13 +98,13 @@ class UserTests(utils.TestCase):
"status": 200,
"body": json.dumps({
'user': self.TEST_USERS['users']['values'][0],
})
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
u = self.client.users.get(1)
@@ -116,13 +116,13 @@ class UserTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_USERS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
user_list = self.client.users.list()
@@ -132,13 +132,13 @@ class UserTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_USERS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users?limit=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
user_list = self.client.users.list(limit=1)
@@ -148,13 +148,13 @@ class UserTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_USERS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users?marker=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
user_list = self.client.users.list(marker=1)
@@ -164,13 +164,13 @@ class UserTests(utils.TestCase):
resp = httplib2.Response({
"status": 200,
"body": json.dumps(self.TEST_USERS),
})
})
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users?marker=1&limit=1'),
'GET',
headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body']))
.AndReturn((resp, resp['body']))
self.mox.ReplayAll()
user_list = self.client.users.list(limit=1, marker=1)
@@ -193,25 +193,25 @@ class UserTests(utils.TestCase):
'PUT',
body=json.dumps(req_2),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp_2, resp_2['body']))
.AndReturn((resp_2, resp_2['body']))
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/2/OS-KSADM/password'),
'PUT',
body=json.dumps(req_1),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp_1, resp_1['body']))
.AndReturn((resp_1, resp_1['body']))
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/2/OS-KSADM/tenant'),
'PUT',
body=json.dumps(req_3),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp_3, resp_3['body']))
.AndReturn((resp_3, resp_3['body']))
httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/users/2/OS-KSADM/enabled'),
'PUT',
body=json.dumps(req_4),
headers=self.TEST_POST_HEADERS) \
.AndReturn((resp_4, resp_4['body']))
.AndReturn((resp_4, resp_4['body']))
self.mox.ReplayAll()
user = self.client.users.update(2,