Interface objects added to api, api_tests and api adjusted to use them
This commit is contained in:
@@ -26,17 +26,53 @@ def url_for(request, service_name, admin=False):
|
||||
rv = catalog[service_name][0]['internalURL']
|
||||
return rv
|
||||
|
||||
def tenant_dict_for(tenant):
|
||||
return {"id": tenant.id,
|
||||
"description": tenant.description,
|
||||
"enabled": tenant.enabled
|
||||
}
|
||||
class Tenant(object):
|
||||
''' Simple wrapper around openstackx.auth.tokens.Tenant
|
||||
|
||||
Defines what information is available from a Tenant, because
|
||||
openstackx resources can have undocumented fields.
|
||||
'''
|
||||
def __init__(self, tenant):
|
||||
self.tenant = tenant
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.tenant.id
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self.tenant.description
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return self.tenant.enabled
|
||||
|
||||
|
||||
class Token(object):
|
||||
''' Simple wrapper around openstackx.auth.tokens.Token
|
||||
|
||||
Defines what information is available from a Token, because
|
||||
openstackx resources can have undocumented fields.
|
||||
'''
|
||||
def __init__(self, token):
|
||||
self.token = token
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self.token.id
|
||||
|
||||
@property
|
||||
def serviceCatalog(self):
|
||||
return self.token.serviceCatalog
|
||||
|
||||
@property
|
||||
def tenant_id(self):
|
||||
return self.token.tenant_id
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
return self.token.username
|
||||
|
||||
def token_dict_for(token):
|
||||
return {"id": token.id,
|
||||
"username": token.username,
|
||||
"tenant_id": token.tenant_id
|
||||
}
|
||||
|
||||
def compute_api(request):
|
||||
compute = openstack.compute.Compute(
|
||||
@@ -193,16 +229,18 @@ def service_update(request, name, enabled):
|
||||
|
||||
|
||||
def token_get_tenant(request, tenant_id):
|
||||
# TODO(mgius): tests for views using this api call
|
||||
tenants = auth_api().tenants.for_token(request.session['token'])
|
||||
for t in tenants:
|
||||
if str(t.id) == str(tenant_id):
|
||||
return tenant_dict_for(t)
|
||||
return Tenant(t)
|
||||
|
||||
LOG.warning('Unknown tenant id "%s" requested' % tenant_id)
|
||||
|
||||
|
||||
def token_list_tenants(request, token):
|
||||
return [tenant_dict_for(t) for t in auth_api().tenants.for_token(token)]
|
||||
# TODO(mgius): tests for views using this api call
|
||||
return [Tenant(t) for t in auth_api().tenants.for_token(token)]
|
||||
|
||||
|
||||
def tenant_create(request, tenant_id, description, enabled):
|
||||
@@ -222,8 +260,7 @@ def tenant_update(request, tenant_id, description, enabled):
|
||||
|
||||
|
||||
def token_create(request, tenant, username, password):
|
||||
return token_dict_for(auth_api().tokens.create(tenant, username, password))
|
||||
|
||||
return Token(auth_api().tokens.create(tenant, username, password))
|
||||
|
||||
def token_info(request, token):
|
||||
hdrs = {"Content-type": "application/json",
|
||||
|
||||
@@ -13,17 +13,35 @@ TEST_USERNAME = 'testUser'
|
||||
TEST_TOKEN_ID = 'userId'
|
||||
|
||||
class Tenant(object):
|
||||
''' More or less fakes what the api is looking for '''
|
||||
def __init__(self, id, description, enabled):
|
||||
self.id = id
|
||||
self.description = description
|
||||
self.enabled = enabled
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other.id and \
|
||||
self.description == other.description and \
|
||||
self.enabled == other.enabled
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
class Token(object):
|
||||
''' More or less fakes what the api is looking for '''
|
||||
def __init__(self, id, username, tenant_id):
|
||||
self.id = id
|
||||
self.username = username
|
||||
self.tenant_id = tenant_id
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other.id and \
|
||||
self.username == other.username and \
|
||||
self.tenant_id == other.tenant_id
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self == other
|
||||
|
||||
class AuthApiTests(test.TestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
@@ -54,10 +72,7 @@ class AuthApiTests(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
ret_val = api.token_get_tenant(request_mock, TEST_TENANT_ID)
|
||||
self.assertDictEqual(ret_val,
|
||||
{'id': TEST_TENANT_ID,
|
||||
'description': TEST_TENANT_DESCRIPTION,
|
||||
'enabled': True})
|
||||
self.assertEqual(tenant_list[1], ret_val)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@@ -107,15 +122,8 @@ class AuthApiTests(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
|
||||
ret_val = api.token_list_tenants(request_mock, 'aToken')
|
||||
self.assertItemsEqual(ret_val,
|
||||
[
|
||||
{'id': TEST_TENANT_ID,
|
||||
'description': TEST_TENANT_DESCRIPTION,
|
||||
'enabled': True},
|
||||
{'id': 'notTheDroid',
|
||||
'description': 'notTheDroid_desc',
|
||||
'enabled': False},
|
||||
])
|
||||
for tenant in ret_val:
|
||||
self.assertIn(tenant, tenant_list)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
@@ -139,10 +147,18 @@ class AuthApiTests(test.TestCase):
|
||||
ret_val = api.token_create(request_mock, TEST_TENANT_ID,
|
||||
TEST_USERNAME, TEST_PASSWORD)
|
||||
|
||||
self.assertEqual(ret_val,
|
||||
{'id': TEST_TOKEN_ID,
|
||||
'username': TEST_USERNAME,
|
||||
'tenant_id': TEST_TENANT_ID
|
||||
})
|
||||
self.assertEqual(test_token, ret_val)
|
||||
|
||||
self.mox.VerifyAll()
|
||||
|
||||
class GlanceApiTests(test.TestCase):
|
||||
def setUp(self):
|
||||
self.mox = mox.Mox()
|
||||
|
||||
def tearDown(self):
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def test_image_all_metadata(self):
|
||||
self.failIf(True)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user