Merge "Move _generate_paste_config to tests.core"
This commit is contained in:
commit
30615ee007
|
@ -131,6 +131,28 @@ def setup_test_database():
|
|||
pass
|
||||
|
||||
|
||||
def generate_paste_config(extension_name):
|
||||
# Generate a file, based on keystone-paste.ini, that is named:
|
||||
# extension_name.ini, and includes extension_name in the pipeline
|
||||
with open(etcdir('keystone-paste.ini'), 'r') as f:
|
||||
contents = f.read()
|
||||
|
||||
new_contents = contents.replace(' service_v3',
|
||||
' %s service_v3' % (extension_name))
|
||||
|
||||
new_paste_file = tmpdir(extension_name + '.ini')
|
||||
with open(new_paste_file, 'w') as f:
|
||||
f.write(new_contents)
|
||||
|
||||
return new_paste_file
|
||||
|
||||
|
||||
def remove_generated_paste_config(extension_name):
|
||||
# Remove the generated paste config file, named extension_name.ini
|
||||
paste_file_to_remove = tmpdir(extension_name + '.ini')
|
||||
os.remove(paste_file_to_remove)
|
||||
|
||||
|
||||
def teardown_test_database():
|
||||
sql.core.set_global_engine(None)
|
||||
|
||||
|
|
|
@ -25,26 +25,10 @@ from keystone.tests import core as test
|
|||
import test_v3
|
||||
|
||||
|
||||
# TODO(gyee): we need to generalize this one and stash it into tests.core
|
||||
def _generate_paste_config(filter_name, new_paste_file_name):
|
||||
# Generate a file, based on keystone-paste.ini, that includes
|
||||
# endpoint_filter_extension in the pipeline
|
||||
|
||||
with open(test.etcdir('keystone-paste.ini'), 'r') as f:
|
||||
contents = f.read()
|
||||
|
||||
new_contents = contents.replace(' service_v3',
|
||||
' %s service_v3' % (filter_name))
|
||||
|
||||
with open(new_paste_file_name, 'w') as f:
|
||||
f.write(new_contents)
|
||||
|
||||
|
||||
class TestExtensionCase(test_v3.RestfulTestCase):
|
||||
|
||||
EXTENSION_NAME = 'endpoint_filter'
|
||||
EXTENSION_FILTER_NAME = 'endpoint_filter_extension'
|
||||
PASTE_INI = 'keystone-endpoint-filter-paste.ini'
|
||||
EXTENSION_TO_ADD = 'endpoint_filter_extension'
|
||||
|
||||
def setup_database(self):
|
||||
self.conf_files = super(TestExtensionCase, self).config_files()
|
||||
|
@ -60,11 +44,7 @@ class TestExtensionCase(test_v3.RestfulTestCase):
|
|||
migration.db_sync(version=None, repo_path=self.repo_path)
|
||||
|
||||
def setUp(self):
|
||||
self._paste_file_name = test.tmpdir(self.PASTE_INI)
|
||||
_generate_paste_config(self.EXTENSION_FILTER_NAME,
|
||||
self._paste_file_name)
|
||||
super(TestExtensionCase, self).setUp(app_conf='config:%s' % (
|
||||
self._paste_file_name))
|
||||
super(TestExtensionCase, self).setUp()
|
||||
self.default_request_url = (
|
||||
'/OS-EP-FILTER/projects/%(project_id)s'
|
||||
'/endpoints/%(endpoint_id)s' % {
|
||||
|
@ -73,7 +53,6 @@ class TestExtensionCase(test_v3.RestfulTestCase):
|
|||
|
||||
def tearDown(self):
|
||||
super(TestExtensionCase, self).tearDown()
|
||||
os.remove(self._paste_file_name)
|
||||
self.conf_files.pop()
|
||||
|
||||
|
||||
|
|
|
@ -53,6 +53,23 @@ class RestfulTestCase(test_content_types.RestfulTestCase):
|
|||
def teardown_database(self):
|
||||
test.teardown_test_database()
|
||||
|
||||
def generate_paste_config(self):
|
||||
new_paste_file = None
|
||||
try:
|
||||
new_paste_file = test.generate_paste_config(self.EXTENSION_TO_ADD)
|
||||
except AttributeError:
|
||||
# no need to report this error here, as most tests will not have
|
||||
# EXTENSION_TO_ADD defined.
|
||||
pass
|
||||
finally:
|
||||
return new_paste_file
|
||||
|
||||
def remove_generated_paste_config(self):
|
||||
try:
|
||||
test.remove_generated_paste_config(self.EXTENSION_TO_ADD)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
def setUp(self, load_sample_data=True, app_conf='keystone'):
|
||||
"""Setup for v3 Restful Test Cases.
|
||||
|
||||
|
@ -65,6 +82,11 @@ class RestfulTestCase(test_content_types.RestfulTestCase):
|
|||
self.config(self.config_files())
|
||||
|
||||
self.setup_database()
|
||||
|
||||
new_paste_file = self.generate_paste_config()
|
||||
if new_paste_file:
|
||||
app_conf = 'config:%s' % (new_paste_file)
|
||||
|
||||
# ensure the cache region instance is setup
|
||||
cache.configure_cache_region(cache.REGION)
|
||||
|
||||
|
@ -147,6 +169,7 @@ class RestfulTestCase(test_content_types.RestfulTestCase):
|
|||
self.public_server = None
|
||||
self.admin_server = None
|
||||
self.teardown_database()
|
||||
self.remove_generated_paste_config()
|
||||
# need to reset the plug-ins
|
||||
auth.controllers.AUTH_METHODS = {}
|
||||
#drop the policy rules
|
||||
|
|
|
@ -19,8 +19,6 @@ import os
|
|||
import urlparse
|
||||
import uuid
|
||||
|
||||
import webtest
|
||||
|
||||
from keystone.common import cms
|
||||
from keystone.common.sql import migration
|
||||
from keystone import config
|
||||
|
@ -28,17 +26,17 @@ from keystone import contrib
|
|||
from keystone.contrib import oauth1
|
||||
from keystone.contrib.oauth1 import controllers
|
||||
from keystone.openstack.common import importutils
|
||||
from keystone.tests import core
|
||||
|
||||
import test_v3
|
||||
|
||||
|
||||
OAUTH_PASTE_FILE = 'v3_oauth1-paste.ini'
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class OAuth1Tests(test_v3.RestfulTestCase):
|
||||
|
||||
EXTENSION_NAME = 'oauth1'
|
||||
EXTENSION_TO_ADD = 'oauth_extension'
|
||||
|
||||
def setup_database(self):
|
||||
super(OAuth1Tests, self).setup_database()
|
||||
|
@ -51,29 +49,10 @@ class OAuth1Tests(test_v3.RestfulTestCase):
|
|||
|
||||
def setUp(self):
|
||||
super(OAuth1Tests, self).setUp()
|
||||
|
||||
# Now that the app has been served, we can query CONF values
|
||||
self.base_url = (CONF.public_endpoint % CONF) + "v3"
|
||||
self.controller = controllers.OAuthControllerV3()
|
||||
self.base_url = CONF.public_endpoint % CONF + "v3"
|
||||
self._generate_paste_config()
|
||||
self.admin_app = webtest.TestApp(
|
||||
self.loadapp('v3_oauth1', name='admin'))
|
||||
self.public_app = webtest.TestApp(
|
||||
self.loadapp('v3_oauth1', name='admin'))
|
||||
|
||||
def tearDown(self):
|
||||
os.remove(OAUTH_PASTE_FILE)
|
||||
super(OAuth1Tests, self).tearDown()
|
||||
|
||||
def _generate_paste_config(self):
|
||||
# Generate a file, based on keystone-paste.ini,
|
||||
# that includes oauth_extension in the pipeline
|
||||
old_pipeline = " ec2_extension "
|
||||
new_pipeline = " oauth_extension ec2_extension "
|
||||
|
||||
with open(core.etcdir('keystone-paste.ini'), 'r') as f:
|
||||
contents = f.read()
|
||||
new_contents = contents.replace(old_pipeline, new_pipeline)
|
||||
with open(OAUTH_PASTE_FILE, 'w') as f:
|
||||
f.write(new_contents)
|
||||
|
||||
def _create_single_consumer(self):
|
||||
ref = {'description': uuid.uuid4().hex}
|
||||
|
@ -97,7 +76,6 @@ class OAuth1Tests(test_v3.RestfulTestCase):
|
|||
http_url=self.base_url + url,
|
||||
http_method='POST',
|
||||
parameters=params)
|
||||
|
||||
hmac = oauth1.SignatureMethod_HMAC_SHA1()
|
||||
oreq.sign_request(hmac, consumer, None)
|
||||
headers.update(oreq.to_header())
|
||||
|
|
Loading…
Reference in New Issue