Fix more tests in python34 gate

Patch contains fixes for following errors:
- 'filter' object is not subscriptable (fix in mistral/tests/base.py)
- Unicode-objects must be encoded before hashing (fix in
mistral/db/v2/sqlalchemy/models.py)
- 'dict' object has no attribute 'itervalues' (fixes in
mistral/workbook/v2/workflows.py and mistral/workflow/data_flow.py)
- 'dict_items' object does not support indexing (fix in
mistral/workbook/base.py)
- object.__new__(dict_keys) is not safe, use dict_keys.__new__()
(fix in mistral/engine/utils.py)

Partial-Bug: #1378537

Change-Id: Ic9ecae34cce9b1190cef4fd53d2012117002a4c2
This commit is contained in:
Anastasia Kuznetsova 2015-09-23 14:00:28 +03:00
parent 1dc5f737f8
commit 65ee32721f
6 changed files with 14 additions and 8 deletions

View File

@ -282,7 +282,8 @@ def _get_hash_function_by(column_name):
def calc_hash(context): def calc_hash(context):
d = context.current_parameters[column_name] or {} d = context.current_parameters[column_name] or {}
return hashlib.sha256(json.dumps(sorted(d.items()))).hexdigest() return hashlib.sha256(json.dumps(sorted(d.items())).
encode('utf-8')).hexdigest()
return calc_hash return calc_hash

View File

@ -26,7 +26,7 @@ LOG = logging.getLogger(__name__)
def validate_input(definition, input, spec=None): def validate_input(definition, input, spec=None):
input_param_names = copy.copy((input or {}).keys()) input_param_names = copy.copy(list((input or {}).keys()))
missing_param_names = [] missing_param_names = []
spec_input = (spec.get_input() if spec else spec_input = (spec.get_input() if spec else

View File

@ -125,9 +125,11 @@ class BaseTest(base.BaseTestCase):
return True return True
filtered_items = filter(lambda item: _matches(item, **props), items) filtered_items = list(
filter(lambda item: _matches(item, **props), items)
)
found = len(list(filtered_items)) found = len(filtered_items)
if found != count: if found != count:
LOG.info("[failed test ctx] items=%s, expected_props=%s" % (str( LOG.info("[failed test ctx] items=%s, expected_props=%s" % (str(

View File

@ -263,7 +263,7 @@ class BaseSpec(object):
@staticmethod @staticmethod
def _as_tuple(val): def _as_tuple(val):
return val.items()[0] if isinstance(val, dict) else (val, '') return list(val.items())[0] if isinstance(val, dict) else (val, '')
@staticmethod @staticmethod
def _parse_cmd_and_input(cmd_str): def _parse_cmd_and_input(cmd_str):

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import six
from mistral import exceptions as exc from mistral import exceptions as exc
from mistral import utils from mistral import utils
from mistral.workbook import types from mistral.workbook import types
@ -60,7 +62,7 @@ class WorkflowSpec(base.BaseSpec):
# Inject 'type' here, so instantiate_spec function can recognize the # Inject 'type' here, so instantiate_spec function can recognize the
# specific subclass of TaskSpec. # specific subclass of TaskSpec.
for task in self._data.get('tasks').itervalues(): for task in six.itervalues(self._data.get('tasks')):
task['type'] = self._type task['type'] = self._type
self._tasks = self._spec_property('tasks', tasks.TaskSpecList) self._tasks = self._spec_property('tasks', tasks.TaskSpecList)

View File

@ -14,6 +14,7 @@
# limitations under the License. # limitations under the License.
import copy import copy
import six
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -135,7 +136,7 @@ class ProxyAwareDict(dict):
return d return d
def iteritems(self): def iteritems(self):
for k, _ in super(ProxyAwareDict, self).iteritems(): for k, _ in six.iteritems(super(ProxyAwareDict, self)):
yield k, self[k] yield k, self[k]
def to_builtin_dict(self): def to_builtin_dict(self):
@ -263,7 +264,7 @@ def add_workflow_variables_to_context(wf_ex, wf_spec):
def extract_task_result_proxies_to_context(ctx): def extract_task_result_proxies_to_context(ctx):
ctx = ProxyAwareDict(copy.deepcopy(ctx)) ctx = ProxyAwareDict(copy.deepcopy(ctx))
for task_ex_id, task_ex_name in ctx['__tasks'].iteritems(): for task_ex_id, task_ex_name in six.iteritems(ctx['__tasks']):
ctx[task_ex_name] = TaskResultProxy(task_ex_id) ctx[task_ex_name] = TaskResultProxy(task_ex_id)
return ctx return ctx