From 29e13366ea2b16624be6213bedd3d0cca4063374 Mon Sep 17 00:00:00 2001 From: Jesse Andrews Date: Thu, 22 Dec 2011 13:09:43 -0800 Subject: [PATCH] common ks client creation --- README.rst | 1 + tests/test_keystoneclient_compat.py | 58 ++++++++++++++--------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/README.rst b/README.rst index 37afb9e425..8397e02743 100644 --- a/README.rst +++ b/README.rst @@ -179,3 +179,4 @@ Still To Do * Keystone import. * (./) Admin-only interface * Don't check git checkouts as often, to speed up tests + * common config - http://wiki.openstack.org/CommonConfigModule \ No newline at end of file diff --git a/tests/test_keystoneclient_compat.py b/tests/test_keystoneclient_compat.py index 760f78b1f1..9ad01b1770 100644 --- a/tests/test_keystoneclient_compat.py +++ b/tests/test_keystoneclient_compat.py @@ -3,13 +3,28 @@ from keystonelight import test 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): def setUp(self): 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): def setUp(self): @@ -59,30 +74,18 @@ class MasterCompatTestCase(CompatTestCase): # client.authenticate() def test_authenticate_tenant_name_and_tenants(self): - from keystoneclient.v2_0 import client as ks_client - - port = self.server.socket_info['socket'][1] - self.options['public_port'] = port - # 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() + client = self._client(auth_url=self._url(), + username='FOO', + password='foo', + tenant_name='BAR') tenants = client.tenants.list() self.assertEquals(tenants[0].id, self.tenant_bar['id']) def test_authenticate_tenant_id_and_tenants(self): - from keystoneclient.v2_0 import client as ks_client - - port = self.server.socket_info['socket'][1] - self.options['public_port'] = port - # 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() + client = self._client(auth_url=self._url(), + username='FOO', + password='foo', + tenant_id='bar') tenants = client.tenants.list() 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 returns unauthorized if not admin def test_tenant_create(self): - from keystoneclient.v2_0 import client as ks_client - port = self.server.socket_info['socket'][1] - self.options['public_port'] = port - # 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() + client = self._client(auth_url=self._url(), + username='FOO', + password='foo', + tenant_name='BAR') client.tenants.create("hello", description="My new tenant!", enabled=True) # FIXME(ja): assert tenant was created