From bc44cea775eb16d2ad2c7f46f0ddd418d3223584 Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Fri, 27 May 2011 15:50:52 -0500 Subject: Build base classes for tests --- test/functional/base.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/functional/base.py b/test/functional/base.py index b1d59845..d30134bc 100644 --- a/test/functional/base.py +++ b/test/functional/base.py @@ -15,4 +15,63 @@ # limitations under the License. +import dtest + +import ksapi + + options = None + + +def _get_ksapi(): + """Get an instance of KeystoneAPI20.""" + + # If debug mode has been enabled, let's select a debug stream + dbstream = None + if options.debug: + dbstream = dtest.status + + # Build and return the API object + return ksapi.KeystoneAPI20(options.keystone, dbstream) + + +class BaseKeystoneTest(dtest.DTestCase): + """Base class for Keystone tests.""" + + def setUp(self): + """Initialize tests by setting up a KeystoneAPI20 to call.""" + + # Build the API object + self.ks = _get_ksapi() + + +class KeystoneTest(BaseKeystoneTest): + """Base class for Keystone tests.""" + + token = None + + @classmethod + def setUpClass(cls): + """Initialize tests by setting up a keystone token.""" + + # Get an API object + ks = _get_ksapi() + + # Next, let's authenticate + resp = ks.authenticate(options.username, options.password) + + # Finally, save the authentication token + cls.token = resp.obj['auth']['token']['id'] + + @classmethod + def tearDownClass(cls): + """Revoke the authentication token.""" + + # Get an API object + ks = _get_ksapi() + + # Now, let's revoke the token + resp = ks.revoke_token(cls.token, cls.token) + + # For completeness sake... + cls.token = None -- cgit