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

View File

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

View File

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

View File

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

View File

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

View File

@@ -44,7 +44,7 @@ class CredentialsManager(base.ManagerWithFind):
:rtype: list of :class:`EC2` :rtype: list of :class:`EC2`
""" """
return self._list("/users/%s/credentials/OS-EC2" % user_id, return self._list("/users/%s/credentials/OS-EC2" % user_id,
"credentials") "credentials")
def get(self, user_id, access): def get(self, user_id, access):
""" """
@@ -59,4 +59,4 @@ class CredentialsManager(base.ManagerWithFind):
Delete an access/secret pair for a user Delete an access/secret pair for a user
""" """
return self._delete("/users/%s/credentials/OS-EC2/%s" % 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): def create(self, region, service_id, publicurl, adminurl, internalurl):
body = {'endpoint': {'region': region, body = {'endpoint': {'region': region,
'service_id': service_id, 'service_id': service_id,
'publicurl': publicurl, 'publicurl': publicurl,
'adminurl': adminurl, 'adminurl': adminurl,
'internalurl': internalurl}} 'internalurl': internalurl}}
return self._create('/endpoints', body, 'endpoint') return self._create('/endpoints', body, 'endpoint')
def delete(self, id): def delete(self, id):

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -26,14 +26,14 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
"id": "v2.0", "id": "v2.0",
"status": "beta", "status": "beta",
"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": "http://docs.openstack.org/api/" "href": "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",
@@ -46,32 +46,31 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
"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": "application/" "type": "application/vnd.openstack.identity-v2.0+xml",
"vnd.openstack.identity-v2.0+xml", },
}, { {
"base": "application/json", "base": "application/json",
"type": "application/" "type": "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):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT), "body": json.dumps(self.TEST_RESPONSE_DICT),
}) })
httplib2.Http.request(self.TEST_ROOT_URL, httplib2.Http.request(self.TEST_ROOT_URL,
'GET', 'GET',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
cs = client.Client() cs = client.Client()
@@ -79,20 +78,21 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
self.assertIsInstance(versions, dict) self.assertIsInstance(versions, dict)
self.assertIn('message', versions) self.assertIn('message', versions)
self.assertIn('v2.0', 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] self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
['href']) ['href'])
def test_get_version_local(self): def test_get_version_local(self):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(self.TEST_RESPONSE_DICT), "body": json.dumps(self.TEST_RESPONSE_DICT),
}) })
httplib2.Http.request("http://localhost:35357", httplib2.Http.request("http://localhost:35357",
'GET', 'GET',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
cs = client.Client() cs = client.Client()
@@ -100,6 +100,7 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
self.assertIsInstance(versions, dict) self.assertIsInstance(versions, dict)
self.assertIn('message', versions) self.assertIn('message', versions)
self.assertIn('v2.0', 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] 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 = { self.TEST_REQUEST_HEADERS = {
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient', 'User-Agent': 'python-keystoneclient',
} }
self.TEST_POST_HEADERS = { self.TEST_POST_HEADERS = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient', '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 = { req_body = {
"tenant_id": tenant_id, "tenant_id": tenant_id,
} }
resp_body = { resp_body = {
"credential": { "credential": {
"access": "access", "access": "access",
@@ -33,12 +33,12 @@ class EC2Tests(utils.TestCase):
"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),
}) })
url = urlparse.urljoin(self.TEST_URL, url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2' % user_id) 'v2.0/users/%s/credentials/OS-EC2' % user_id)
@@ -46,7 +46,7 @@ class EC2Tests(utils.TestCase):
'POST', 'POST',
body=json.dumps(req_body), body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \ headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
cred = self.client.ec2.create(user_id, tenant_id) cred = self.client.ec2.create(user_id, tenant_id)
@@ -66,12 +66,12 @@ class EC2Tests(utils.TestCase):
"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),
}) })
url = urlparse.urljoin(self.TEST_URL, url = urlparse.urljoin(self.TEST_URL,
'v2.0/users/%s/credentials/OS-EC2/%s' % 'v2.0/users/%s/credentials/OS-EC2/%s' %
@@ -79,7 +79,7 @@ class EC2Tests(utils.TestCase):
httplib2.Http.request(url, httplib2.Http.request(url,
'GET', 'GET',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
cred = self.client.ec2.get(user_id, 'access') cred = self.client.ec2.get(user_id, 'access')
@@ -101,29 +101,29 @@ class EC2Tests(utils.TestCase):
"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,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
}) })
url = urlparse.urljoin(self.TEST_URL, 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, httplib2.Http.request(url,
'GET', 'GET',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
creds = self.client.ec2.list(user_id) creds = self.client.ec2.list(user_id)
@@ -141,7 +141,7 @@ class EC2Tests(utils.TestCase):
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' % 'v2.0/users/%s/credentials/OS-EC2/%s' %
@@ -149,7 +149,7 @@ class EC2Tests(utils.TestCase):
httplib2.Http.request(url, httplib2.Http.request(url,
'DELETE', 'DELETE',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
self.client.ec2.delete(user_id, access) self.client.ec2.delete(user_id, access)

View File

@@ -13,12 +13,12 @@ class EndpointTests(utils.TestCase):
self.TEST_REQUEST_HEADERS = { self.TEST_REQUEST_HEADERS = {
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient', 'User-Agent': 'python-keystoneclient',
} }
self.TEST_POST_HEADERS = { self.TEST_POST_HEADERS = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Auth-Token': 'aToken', 'X-Auth-Token': 'aToken',
'User-Agent': 'python-keystoneclient', 'User-Agent': 'python-keystoneclient',
} }
self.TEST_ENDPOINTS = { self.TEST_ENDPOINTS = {
'endpoints': [ 'endpoints': [
{ {
@@ -27,16 +27,16 @@ class EndpointTests(utils.TestCase):
'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s', 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s', 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'region': 'RegionOne', 'region': 'RegionOne',
}, },
{ {
'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s', 'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'id': '8f9531231e044e218824b0e58688d263', 'id': '8f9531231e044e218824b0e58688d263',
'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s', 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s', 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
'region': 'RegionOne', 'region': 'RegionOne',
} }
] ]
} }
def test_create(self): def test_create(self):
req_body = { req_body = {
@@ -46,8 +46,8 @@ class EndpointTests(utils.TestCase):
"internalurl": "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", "adminurl": "http://host-3:8774/v1.1/$(tenant_id)s",
"service_id": "e044e21", "service_id": "e044e21",
}
} }
}
resp_body = { resp_body = {
"endpoint": { "endpoint": {
@@ -56,20 +56,20 @@ class EndpointTests(utils.TestCase):
"id": "1fd485b2ffd54f409a5ecd42cba11401", "id": "1fd485b2ffd54f409a5ecd42cba11401",
"internalurl": "http://host-3:8774/v1.1/$(tenant_id)s", "internalurl": "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,
"body": json.dumps(resp_body), "body": json.dumps(resp_body),
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints'), 'v2.0/endpoints'),
'POST', 'POST',
body=json.dumps(req_body), body=json.dumps(req_body),
headers=self.TEST_POST_HEADERS) \ headers=self.TEST_POST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
endpoint = self.client.endpoints.create( endpoint = self.client.endpoints.create(
@@ -85,12 +85,12 @@ class EndpointTests(utils.TestCase):
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'),
'DELETE', 'DELETE',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
self.client.endpoints.delete('8f953') self.client.endpoints.delete('8f953')
@@ -99,13 +99,13 @@ class EndpointTests(utils.TestCase):
resp = httplib2.Response({ resp = httplib2.Response({
"status": 200, "status": 200,
"body": json.dumps(self.TEST_ENDPOINTS), "body": json.dumps(self.TEST_ENDPOINTS),
}) })
httplib2.Http.request(urlparse.urljoin(self.TEST_URL, httplib2.Http.request(urlparse.urljoin(self.TEST_URL,
'v2.0/endpoints'), 'v2.0/endpoints'),
'GET', 'GET',
headers=self.TEST_REQUEST_HEADERS) \ headers=self.TEST_REQUEST_HEADERS) \
.AndReturn((resp, resp['body'])) .AndReturn((resp, resp['body']))
self.mox.ReplayAll() self.mox.ReplayAll()
endpoint_list = self.client.endpoints.list() endpoint_list = self.client.endpoints.list()

View File

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

View File

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

View File

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

View File

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

View File

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