summaryrefslogtreecommitdiff
path: root/openstackclient/tests/functional/identity/v2/common.py
diff options
context:
space:
mode:
authorRui Chen <chenrui.momo@gmail.com>2017-06-06 21:03:33 +0800
committerDean Troyer <dtroyer@gmail.com>2017-07-20 16:39:32 +0000
commitf1d32dbe9b6f5f2e47853b9969483fa841e451f4 (patch)
tree1149b1d37c63a81caa58c9f6613f0726b9ddb3b5 /openstackclient/tests/functional/identity/v2/common.py
parentac8cac4b63590e3b583faee88b6c481f2f3e9d9a (diff)
downloadpython-openstackclient-f1d32dbe9b6f5f2e47853b9969483fa841e451f4.tar.gz
Clean up the changes of os.environ in functional tests
Use fixtures to restore the API version changes of os.environ in each functional tests, aims to avoid the following test cases failing in unexpected context. And make sure setUpClass/tearDownClass call super class's corresponding methods first. Change-Id: Ie248fe9d3a9e25f1b076c9f2c363200f29a83817 Closes-Bug: #1696080
Diffstat (limited to 'openstackclient/tests/functional/identity/v2/common.py')
-rw-r--r--openstackclient/tests/functional/identity/v2/common.py29
1 files changed, 22 insertions, 7 deletions
diff --git a/openstackclient/tests/functional/identity/v2/common.py b/openstackclient/tests/functional/identity/v2/common.py
index 69ef728b..f4bc10bd 100644
--- a/openstackclient/tests/functional/identity/v2/common.py
+++ b/openstackclient/tests/functional/identity/v2/common.py
@@ -12,6 +12,7 @@
import os
+import fixtures
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions as tempest_exceptions
@@ -41,17 +42,13 @@ class IdentityTests(base.TestCase):
@classmethod
def setUpClass(cls):
- # prepare v2 env
- os.environ['OS_IDENTITY_API_VERSION'] = '2.0'
- auth_url = os.environ.get('OS_AUTH_URL')
- if auth_url:
- os.environ['OS_AUTH_URL'] = auth_url.replace('v3', 'v2.0')
-
+ super(IdentityTests, cls).setUpClass()
# create dummy project
cls.project_name = data_utils.rand_name('TestProject')
cls.project_description = data_utils.rand_name('description')
try:
cls.openstack(
+ '--os-identity-api-version 2 '
'project create '
'--description %(description)s '
'--enable '
@@ -69,7 +66,25 @@ class IdentityTests(base.TestCase):
@classmethod
def tearDownClass(cls):
- cls.openstack('project delete %s' % cls.project_name)
+ try:
+ cls.openstack(
+ '--os-identity-api-version 2 '
+ 'project delete %s' % cls.project_name)
+ finally:
+ super(IdentityTests, cls).tearDownClass()
+
+ def setUp(self):
+ super(IdentityTests, self).setUp()
+ # prepare v2 env
+ ver_fixture = fixtures.EnvironmentVariable(
+ 'OS_IDENTITY_API_VERSION', '2.0')
+ self.useFixture(ver_fixture)
+ auth_url = os.environ.get('OS_AUTH_URL')
+ if auth_url:
+ auth_url_fixture = fixtures.EnvironmentVariable(
+ 'OS_AUTH_URL', auth_url.replace('v3', 'v2.0')
+ )
+ self.useFixture(auth_url_fixture)
def _create_dummy_project(self, add_clean_up=True):
project_name = data_utils.rand_name('TestProject')