summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Krotscheck <krotscheck@gmail.com>2015-04-28 16:49:54 -0700
committerMichael Krotscheck <krotscheck@gmail.com>2015-04-28 21:51:18 -0700
commit09ffae38ae48cc6cb63e3df0c66328b87d17631c (patch)
tree2ca46139208b43ebb276b0f8f6ce1094adb54dd6
parentee1fc55aa9852c6f40bf938c3f6cf2d3aeaaf764 (diff)
downloadoslo-middleware-09ffae38ae48cc6cb63e3df0c66328b87d17631c.tar.gz
Update CORS tests to use config fixture's load_raw_values
The newer version of oslo_config contains a method that allows us to load raw values into our fixture directly. This patch updates the relevant unit tests to use this method instead of the manual load/clear it was doing previously. Change-Id: I415bed500995c389c4a4bcf9787609a806562018
-rw-r--r--oslo_middleware/tests/test_cors.py72
1 files changed, 31 insertions, 41 deletions
diff --git a/oslo_middleware/tests/test_cors.py b/oslo_middleware/tests/test_cors.py
index 5552898..bd696a5 100644
--- a/oslo_middleware/tests/test_cors.py
+++ b/oslo_middleware/tests/test_cors.py
@@ -13,6 +13,7 @@
# under the License.
from oslo.config import cfg
+from oslo.config import fixture
from oslotest import base as test_base
import webob
import webob.dec
@@ -32,47 +33,36 @@ class CORSTestBase(test_base.BaseTestCase):
def application(req):
return 'Hello, World!!!'
- # Force a reload of the configuration after this test clears.
- self.addCleanup(cfg.CONF.reload_config_files)
-
- # Make sure the namespace exists for our tests.
- if not cfg.CONF._namespace:
- cfg.CONF.__call__(args=[])
-
- # Manually load configuration options into the parser.
- raw_config = {
- 'cors': {
- 'allowed_origin': ['http://valid.example.com'],
- 'allow_credentials': ['False'],
- 'max_age': [''],
- 'expose_headers': [''],
- 'allow_methods': ['GET'],
- 'allow_headers': ['']
- },
- 'cors.credentials': {
- 'allowed_origin': ['http://creds.example.com'],
- 'allow_credentials': ['True']
- },
- 'cors.exposed-headers': {
- 'allowed_origin': ['http://headers.example.com'],
- 'expose_headers': ['X-Header-1,X-Header-2'],
- 'allow_headers': ['X-Header-1,X-Header-2']
- },
- 'cors.cached': {
- 'allowed_origin': ['http://cached.example.com'],
- 'max_age': ['3600']
- },
- 'cors.get-only': {
- 'allowed_origin': ['http://get.example.com'],
- 'allow_methods': ['GET']
- },
- 'cors.all-methods': {
- 'allowed_origin': ['http://all.example.com'],
- 'allow_methods': ['GET,PUT,POST,DELETE,HEAD']
- }
- }
- namespace = cfg.CONF._namespace
- namespace._add_parsed_config_file(raw_config, raw_config)
+ # Set up the config fixture.
+ config = self.useFixture(fixture.Config(cfg.CONF))
+
+ config.load_raw_values(group='cors',
+ allowed_origin='http://valid.example.com',
+ allow_credentials='False',
+ max_age='',
+ expose_headers='',
+ allow_methods='GET',
+ allow_headers='')
+
+ config.load_raw_values(group='cors.credentials',
+ allowed_origin='http://creds.example.com',
+ allow_credentials='True')
+
+ config.load_raw_values(group='cors.exposed-headers',
+ allowed_origin='http://headers.example.com',
+ expose_headers='X-Header-1,X-Header-2',
+ allow_headers='X-Header-1,X-Header-2')
+
+ config.load_raw_values(group='cors.cached',
+ allowed_origin='http://cached.example.com',
+ max_age='3600')
+
+ config.load_raw_values(group='cors.get-only',
+ allowed_origin='http://get.example.com',
+ allow_methods='GET')
+ config.load_raw_values(group='cors.all-methods',
+ allowed_origin='http://all.example.com',
+ allow_methods='GET,PUT,POST,DELETE,HEAD')
# Now that the config is set up, create our application.
self.application = cors.CORS(application, cfg.CONF)