From 078fbdafaf2f5365203510dc3ba35eb212adaf97 Mon Sep 17 00:00:00 2001 From: hardik Date: Sun, 27 Sep 2015 07:03:46 +0530 Subject: [PATCH] Refactored filter implementation. 1) Previously filter() was used to remove empty fields which creates problem while calulating length. 2) respose.body is returning byte literal string. So decode() function is used to convert it in simple string. Change-Id: I5e36dcb0a7482b030ca249248b5cbf8d14142c04 Partially-Implements: blueprint mistral-py3 --- mistral/api/controllers/v2/types.py | 4 ++-- mistral/tests/unit/api/v2/test_actions.py | 4 ++-- mistral/tests/unit/api/v2/test_executions.py | 4 ++-- mistral/tests/unit/api/v2/test_workflows.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mistral/api/controllers/v2/types.py b/mistral/api/controllers/v2/types.py index f656d763..2f0efac5 100644 --- a/mistral/api/controllers/v2/types.py +++ b/mistral/api/controllers/v2/types.py @@ -35,8 +35,8 @@ class ListType(wtypes.UserType): """ items = [v.strip().lower() for v in six.text_type(value).split(',')] - # filter() to remove empty items. - return filter(None, items) + # remove empty items. + return [x for x in items if x] @staticmethod def frombasetype(value): diff --git a/mistral/tests/unit/api/v2/test_actions.py b/mistral/tests/unit/api/v2/test_actions.py index c7238fa3..0378f9c7 100644 --- a/mistral/tests/unit/api/v2/test_actions.py +++ b/mistral/tests/unit/api/v2/test_actions.py @@ -325,7 +325,7 @@ class TestActionsController(base.FunctionalTest): self.assertIn( "Length of sort_keys must be equal or greater than sort_dirs", - resp.body + resp.body.decode() ) def test_get_all_pagination_unknown_direction(self): @@ -336,4 +336,4 @@ class TestActionsController(base.FunctionalTest): self.assertEqual(400, resp.status_int) - self.assertIn("Unknown sort direction", resp.body) + self.assertIn("Unknown sort direction", resp.body.decode()) diff --git a/mistral/tests/unit/api/v2/test_executions.py b/mistral/tests/unit/api/v2/test_executions.py index 92556a80..f8e38225 100644 --- a/mistral/tests/unit/api/v2/test_executions.py +++ b/mistral/tests/unit/api/v2/test_executions.py @@ -296,7 +296,7 @@ class TestExecutionsController(base.FunctionalTest): self.assertIn( "Length of sort_keys must be equal or greater than sort_dirs", - resp.body + resp.body.decode() ) def test_get_all_pagination_unknown_direction(self): @@ -307,4 +307,4 @@ class TestExecutionsController(base.FunctionalTest): self.assertEqual(400, resp.status_int) - self.assertIn("Unknown sort direction", resp.body) + self.assertIn("Unknown sort direction", resp.body.decode()) diff --git a/mistral/tests/unit/api/v2/test_workflows.py b/mistral/tests/unit/api/v2/test_workflows.py index 6a30a11c..ffaba621 100644 --- a/mistral/tests/unit/api/v2/test_workflows.py +++ b/mistral/tests/unit/api/v2/test_workflows.py @@ -420,7 +420,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertIn( "Length of sort_keys must be equal or greater than sort_dirs", - resp.body + resp.body.decode() ) def test_get_all_pagination_unknown_direction(self): @@ -431,7 +431,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertEqual(400, resp.status_int) - self.assertIn("Unknown sort direction", resp.body) + self.assertIn("Unknown sort direction", resp.body.decode()) @mock.patch('mistral.db.v2.api.get_workflow_definitions') def test_get_all_with_fields_filter(self, mock_get_db_wfs): @@ -461,7 +461,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertIn( "nonexist are invalid", - resp.body + resp.body.decode() ) def test_validate(self):