From 90457d594a091a0f8dfa0f25f2308cb22c9842b8 Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Fri, 27 Oct 2017 16:39:05 +0100 Subject: [PATCH] Add deprecated context parameters to the new security context In the recent parameter migration, a number of parameters were incorrectly deprecated. They were not redirected to the new location correctly and would cause an error. Change-Id: I5ea09c3c79df5a43b06194a48f7425a15a1b23cf Closes-Bug: #1728081 (cherry picked from commit e195c6d90fee0dc6b0435efd9aec6b383923cd88) --- mistral_lib/actions/context.py | 7 ++- mistral_lib/tests/actions/test_base.py | 9 +-- mistral_lib/tests/actions/test_context.py | 69 +++++++++++++++++++++++ 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 mistral_lib/tests/actions/test_context.py diff --git a/mistral_lib/actions/context.py b/mistral_lib/actions/context.py index a08c819..295a388 100644 --- a/mistral_lib/actions/context.py +++ b/mistral_lib/actions/context.py @@ -61,7 +61,8 @@ class SecurityContext(object): def __init__(self, auth_uri=None, auth_cacert=None, insecure=None, service_catalog=None, region_name=None, is_trust_scoped=None, redelivered=None, expires_at=None, trust_id=None, - is_target=None): + is_target=None, project_id=None, project_name=None, + user_name=None, auth_token=None): self.auth_uri = auth_uri self.auth_cacert = auth_cacert self.insecure = insecure @@ -72,6 +73,10 @@ class SecurityContext(object): self.expires_at = expires_at self.trust_id = trust_id self.is_target = is_target + self.project_id = project_id + self.project_name = project_name + self.user_name = user_name + self.auth_token = auth_token class ExecutionContext(object): diff --git a/mistral_lib/tests/actions/test_base.py b/mistral_lib/tests/actions/test_base.py index 865a07d..ad1f015 100644 --- a/mistral_lib/tests/actions/test_base.py +++ b/mistral_lib/tests/actions/test_base.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. from mistral_lib import actions +from mistral_lib.actions import context from mistral_lib.tests import base as tests_base @@ -24,8 +25,8 @@ class TestAction(actions.Action): class TestActionsBase(tests_base.TestCase): - def test_run(self): - context = {"name": "test"} + def test_run_empty_context(self): + ctx = context.ActionContext() action = TestAction() - result = action.run(context) - assert result == context + result = action.run(ctx) + assert result == ctx diff --git a/mistral_lib/tests/actions/test_context.py b/mistral_lib/tests/actions/test_context.py new file mode 100644 index 0000000..b98775d --- /dev/null +++ b/mistral_lib/tests/actions/test_context.py @@ -0,0 +1,69 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from mistral_lib.actions import context +from mistral_lib.tests import base as tests_base + + +def _fake_context(): + security_ctx = context.SecurityContext( + auth_uri='auth_uri', + auth_cacert='auth_cacert', + insecure='insecure', + service_catalog='service_catalog', + region_name='region_name', + is_trust_scoped='is_trust_scoped', + redelivered='redelivered', + expires_at='expires_at', + trust_id='trust_id', + is_target='is_target', + project_id='project_id') + + execution_ctx = context.ExecutionContext( + workflow_execution_id='workflow_execution_id', + task_id='task_id', + action_execution_id='action_execution_id', + workflow_name='workflow_name', + callback_url='callback_url') + + ctx = context.ActionContext(security_ctx, execution_ctx) + return ctx + + +class TestActionsBase(tests_base.TestCase): + + def test_empty_context(self): + + ctx = context.ActionContext( + context.SecurityContext(), + context.ExecutionContext() + ) + + self.assertIsInstance(ctx.security, context.SecurityContext) + self.assertIsInstance(ctx.execution, context.ExecutionContext) + + self.assertEqual(ctx.security.auth_uri, None) + self.assertEqual(ctx.execution.workflow_name, None) + + def test_deprecated_properties(self): + + ctx = _fake_context() + + deprecated_properties = [ + "auth_uri", "user_name", "auth_token", "project_name", + "project_id", "insecure" + ] + + for deprecated in deprecated_properties: + old = getattr(ctx, deprecated) + new = getattr(ctx.security, deprecated) + self.assertEqual(old, new)