Files
deb-python-django-openstack…/openstack_auth/tests/data.py
Sascha Peilicke a13abea67f Fix testsuite after "Support keystoneclient 0.2.5+"
access.AccessInfo.factory() does a (keystone) API version check, thus
add versioned_scoped_token_dict to tests/data.py.
2013-07-01 11:00:15 +02:00

145 lines
4.9 KiB
Python

import uuid
from datetime import timedelta
from django.utils import datetime_safe
from keystoneclient.v2_0.roles import Role, RoleManager
from keystoneclient.v2_0.tenants import Tenant, TenantManager
from keystoneclient.v2_0.tokens import Token, TokenManager
from keystoneclient.v2_0.users import User, UserManager
from keystoneclient.service_catalog import ServiceCatalog
from keystoneclient import access
class TestDataContainer(object):
""" Arbitrary holder for test data in an object-oriented fashion. """
pass
def generate_test_data():
''' Builds a set of test_data data as returned by Keystone. '''
test_data = TestDataContainer()
keystone_service = {
'type': 'identity',
'name': 'keystone',
'endpoints_links': [],
'endpoints': [
{
'region': 'RegionOne',
'adminURL': 'http://admin.localhost:35357/v2.0',
'internalURL': 'http://internal.localhost:5000/v2.0',
'publicURL': 'http://public.localhost:5000/v2.0'
}
]
}
# Users
user_dict = {'id': uuid.uuid4().hex,
'name': 'gabriel',
'email': 'gabriel@example.com',
'password': 'swordfish',
'token': '',
'enabled': True}
test_data.user = User(UserManager(None), user_dict, loaded=True)
# Tenants
tenant_dict_1 = {'id': uuid.uuid4().hex,
'name': 'tenant_one',
'description': '',
'enabled': True}
tenant_dict_2 = {'id': uuid.uuid4().hex,
'name': '',
'description': '',
'enabled': False}
test_data.tenant_one = Tenant(TenantManager(None),
tenant_dict_1,
loaded=True)
test_data.tenant_two = Tenant(TenantManager(None),
tenant_dict_2,
loaded=True)
nova_service = {
'type': 'compute',
'name': 'nova',
'endpoint_links': [],
'endpoints': [
{
'region': 'RegionOne',
'adminURL': 'http://nova-admin.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id']),
'internalURL': 'http://nova-internal.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id']),
'publicURL': 'http://nova-public.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id'])
},
{
'region': 'RegionTwo',
'adminURL': 'http://nova2-admin.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id']),
'internalURL': 'http://nova2-internal.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id']),
'publicURL': 'http://nova2-public.localhost:8774/v2.0/%s' \
% (tenant_dict_1['id'])
}
]
}
# Roles
role_dict = {'id': uuid.uuid4().hex,
'name': 'Member'}
test_data.role = Role(RoleManager, role_dict)
# Tokens
tomorrow = datetime_safe.datetime.now() + timedelta(days=1)
expiration = datetime_safe.datetime.isoformat(tomorrow)
scoped_token_dict = {
'token': {
'id': uuid.uuid4().hex,
'expires': expiration,
'tenant': tenant_dict_1,
'tenants': [tenant_dict_1, tenant_dict_2]},
'user': {
'id': user_dict['id'],
'name': user_dict['name'],
'roles': [role_dict]},
'serviceCatalog': [keystone_service, nova_service]
}
test_data.scoped_token = Token(TokenManager(None),
scoped_token_dict,
loaded=True)
unscoped_token_dict = {
'token': {
'id': uuid.uuid4().hex,
'expires': expiration},
'user': {
'id': user_dict['id'],
'name': user_dict['name'],
'roles': [role_dict]},
'serviceCatalog': [keystone_service]
}
test_data.unscoped_token = Token(TokenManager(None),
unscoped_token_dict,
loaded=True)
# Service Catalog
test_data.service_catalog = ServiceCatalog.factory({
'serviceCatalog': [keystone_service, nova_service],
'token': {
'id': scoped_token_dict['token']['id'],
'expires': scoped_token_dict['token']['expires'],
'user_id': user_dict['id'],
'tenant_id': tenant_dict_1['id']
}
})
versioned_scoped_toked_dict = scoped_token_dict
versioned_scoped_toked_dict['version'] = 'v2.0'
test_data.access_info = access.AccessInfo(versioned_scoped_toked_dict)
return test_data