summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrant Knudson <bknudson@us.ibm.com>2014-01-03 11:48:43 -0600
committerBrant Knudson <bknudson@us.ibm.com>2014-01-10 12:33:11 -0600
commitcba02dabedea9c0ed6b462f8e2596cfdce222a9c (patch)
treeca15f2a5391602a295a00497aca962eaff61af22
parent0753970616860440282ad2c4aeabd1003945c756 (diff)
downloadkeystone-cba02dabedea9c0ed6b462f8e2596cfdce222a9c.tar.gz
Cleanup test_no_admin_token_auth cleanup code
The addCleanup call for the temporary paste config file was separated from where it was needed because the function that required it was outside the TestNoAdminTokenAuth class. This moves the function to be a member and moves the addCleanup call in the member function right where it's needed. It's better to put the addCleanup code close to where it's needed because then it will be called even if an exception occurs. Change-Id: I50c97a3229958f4d15c7cd68ffa2a9d45914d1db
-rw-r--r--keystone/tests/test_no_admin_token_auth.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/keystone/tests/test_no_admin_token_auth.py b/keystone/tests/test_no_admin_token_auth.py
index 20fb661e4..5c2817903 100644
--- a/keystone/tests/test_no_admin_token_auth.py
+++ b/keystone/tests/test_no_admin_token_auth.py
@@ -20,35 +20,32 @@ import webtest
from keystone import tests
-def _generate_paste_config():
- # Generate a file, based on keystone-paste.ini, that doesn't include
- # admin_token_auth in the pipeline
-
- with open(tests.dirs.etc('keystone-paste.ini'), 'r') as f:
- contents = f.read()
-
- new_contents = contents.replace(' admin_token_auth ', ' ')
-
- with open(tests.dirs.tmp('no_admin_token_auth-paste.ini'), 'w') as f:
- f.write(new_contents)
-
-
class TestNoAdminTokenAuth(tests.TestCase):
def setUp(self):
super(TestNoAdminTokenAuth, self).setUp()
self.load_backends()
- _generate_paste_config()
- self.addCleanup(os.remove,
- tests.dirs.tmp('no_admin_token_auth-paste.ini'))
- # TODO(blk-u): Make _generate_paste_config a member function and have
- # it also do addCleanup.
+ self._generate_paste_config()
self.admin_app = webtest.TestApp(
self.loadapp(tests.dirs.tmp('no_admin_token_auth'), name='admin'),
extra_environ=dict(REMOTE_ADDR='127.0.0.1'))
self.addCleanup(setattr, self, 'admin_app', None)
+ def _generate_paste_config(self):
+ # Generate a file, based on keystone-paste.ini, that doesn't include
+ # admin_token_auth in the pipeline
+
+ with open(tests.dirs.etc('keystone-paste.ini'), 'r') as f:
+ contents = f.read()
+
+ new_contents = contents.replace(' admin_token_auth ', ' ')
+
+ filename = tests.dirs.tmp('no_admin_token_auth-paste.ini')
+ with open(filename, 'w') as f:
+ f.write(new_contents)
+ self.addCleanup(os.remove, filename)
+
def test_request_no_admin_token_auth(self):
# This test verifies that if the admin_token_auth middleware isn't
# in the paste pipeline that users can still make requests.