common ks client creation

This commit is contained in:
Jesse Andrews 2011-12-22 13:09:43 -08:00
parent 5e4a877df2
commit 29e13366ea
2 changed files with 29 additions and 30 deletions

View File

@ -179,3 +179,4 @@ Still To Do
* Keystone import. * Keystone import.
* (./) Admin-only interface * (./) Admin-only interface
* Don't check git checkouts as often, to speed up tests * Don't check git checkouts as often, to speed up tests
* common config - http://wiki.openstack.org/CommonConfigModule

View File

@ -3,13 +3,28 @@ from keystonelight import test
from keystonelight import utils from keystonelight import utils
KEYSTONECLIENT_REPO = 'git://github.com/4P/python-keystoneclient.git' KEYSTONECLIENT_REPO = 'git://github.com/openstack/python-keystoneclient.git'
class CompatTestCase(test.TestCase): class CompatTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(CompatTestCase, self).setUp() super(CompatTestCase, self).setUp()
def _url(self):
port = self.server.socket_info['socket'][1]
self.options['public_port'] = port
# NOTE(termie): novaclient wants a "/" at the end, keystoneclient does not
return "http://localhost:%s/v2.0/" % port
def _client(self, **kwargs):
from keystoneclient.v2_0 import client as ks_client
port = self.server.socket_info['socket'][1]
self.options['public_port'] = port
kc = ks_client.Client(**kwargs)
kc.authenticate()
return kc
class MasterCompatTestCase(CompatTestCase): class MasterCompatTestCase(CompatTestCase):
def setUp(self): def setUp(self):
@ -59,30 +74,18 @@ class MasterCompatTestCase(CompatTestCase):
# client.authenticate() # client.authenticate()
def test_authenticate_tenant_name_and_tenants(self): def test_authenticate_tenant_name_and_tenants(self):
from keystoneclient.v2_0 import client as ks_client client = self._client(auth_url=self._url(),
username='FOO',
port = self.server.socket_info['socket'][1] password='foo',
self.options['public_port'] = port tenant_name='BAR')
# NOTE(termie): novaclient wants a "/" at the end, keystoneclient does not
client = ks_client.Client(auth_url="http://localhost:%s/v2.0/" % port,
username='FOO',
password='foo',
tenant_name='BAR')
client.authenticate()
tenants = client.tenants.list() tenants = client.tenants.list()
self.assertEquals(tenants[0].id, self.tenant_bar['id']) self.assertEquals(tenants[0].id, self.tenant_bar['id'])
def test_authenticate_tenant_id_and_tenants(self): def test_authenticate_tenant_id_and_tenants(self):
from keystoneclient.v2_0 import client as ks_client client = self._client(auth_url=self._url(),
username='FOO',
port = self.server.socket_info['socket'][1] password='foo',
self.options['public_port'] = port tenant_id='bar')
# NOTE(termie): novaclient wants a "/" at the end, keystoneclient does not
client = ks_client.Client(auth_url="http://localhost:%s/v2.0/" % port,
username='FOO',
password='foo',
tenant_id='bar')
client.authenticate()
tenants = client.tenants.list() tenants = client.tenants.list()
self.assertEquals(tenants[0].id, self.tenant_bar['id']) self.assertEquals(tenants[0].id, self.tenant_bar['id'])
@ -91,14 +94,9 @@ class MasterCompatTestCase(CompatTestCase):
# FIXME(ja): add a test that admin endpoint is only sent to admin user # FIXME(ja): add a test that admin endpoint is only sent to admin user
# FIXME(ja): add a test that admin endpoint returns unauthorized if not admin # FIXME(ja): add a test that admin endpoint returns unauthorized if not admin
def test_tenant_create(self): def test_tenant_create(self):
from keystoneclient.v2_0 import client as ks_client client = self._client(auth_url=self._url(),
port = self.server.socket_info['socket'][1] username='FOO',
self.options['public_port'] = port password='foo',
# NOTE(termie): novaclient wants a "/" at the end, keystoneclient does not tenant_name='BAR')
client = ks_client.Client(auth_url="http://localhost:%s/v2.0/" % port,
username='FOO',
password='foo',
tenant_id='bar')
client.authenticate()
client.tenants.create("hello", description="My new tenant!", enabled=True) client.tenants.create("hello", description="My new tenant!", enabled=True)
# FIXME(ja): assert tenant was created # FIXME(ja): assert tenant was created