diff --git a/mistralclient/api/base.py b/mistralclient/api/base.py index 0d207ecb..44018e89 100644 --- a/mistralclient/api/base.py +++ b/mistralclient/api/base.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import copy import json import logging @@ -41,6 +42,9 @@ class Resource(object): # In this case we already defined the attribute on the class pass + def to_dict(self): + return copy.deepcopy(self._data) + def __str__(self): vals = ", ".join(["%s='%s'" % (n, v) for n, v in self._data.items()]) diff --git a/mistralclient/tests/unit/v2/test_action_executions.py b/mistralclient/tests/unit/v2/test_action_executions.py index d4236f54..009eb085 100644 --- a/mistralclient/tests/unit/v2/test_action_executions.py +++ b/mistralclient/tests/unit/v2/test_action_executions.py @@ -46,7 +46,7 @@ class TestActionExecutions(base.BaseClientV2Test): self.assertIsNotNone(action_execution) self.assertEqual(action_executions.ActionExecution( self.action_executions, ACTION_EXEC - ).__dict__, action_execution.__dict__) + ).to_dict(), action_execution.to_dict()) mock.assert_called_once_with( URL_TEMPLATE, json.dumps(body)) @@ -65,7 +65,7 @@ class TestActionExecutions(base.BaseClientV2Test): self.assertIsNotNone(action_execution) self.assertEqual(action_executions.ActionExecution( self.action_executions, ACTION_EXEC - ).__dict__, action_execution.__dict__) + ).to_dict(), action_execution.to_dict()) mock.assert_called_once_with( URL_TEMPLATE_ID % ACTION_EXEC['id'], json.dumps(body)) @@ -82,7 +82,7 @@ class TestActionExecutions(base.BaseClientV2Test): self.assertEqual(action_executions.ActionExecution( self.action_executions, ACTION_EXEC - ).__dict__, action_execution.__dict__) + ).to_dict(), action_execution.to_dict()) mock.assert_called_once_with(URL_TEMPLATE) @@ -93,7 +93,7 @@ class TestActionExecutions(base.BaseClientV2Test): self.assertEqual(action_executions.ActionExecution( self.action_executions, ACTION_EXEC - ).__dict__, action_execution.__dict__) + ).to_dict(), action_execution.to_dict()) mock.assert_called_once_with( URL_TEMPLATE_ID % ACTION_EXEC['id']) diff --git a/mistralclient/tests/unit/v2/test_environments.py b/mistralclient/tests/unit/v2/test_environments.py index a86d5cba..4628ada6 100644 --- a/mistralclient/tests/unit/v2/test_environments.py +++ b/mistralclient/tests/unit/v2/test_environments.py @@ -69,8 +69,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test): env = environment_list[0] self.assertDictEqual( - environments.Environment(self.environments, ENVIRONMENT).__dict__, - env.__dict__ + environments.Environment(self.environments, ENVIRONMENT).to_dict(), + env.to_dict() ) mock.assert_called_once_with(URL_TEMPLATE) @@ -82,8 +82,8 @@ class TestEnvironmentsV2(base.BaseClientV2Test): self.assertIsNotNone(env) self.assertDictEqual( - environments.Environment(self.environments, ENVIRONMENT).__dict__, - env.__dict__ + environments.Environment(self.environments, ENVIRONMENT).to_dict(), + env.to_dict() ) mock.assert_called_once_with(URL_TEMPLATE_NAME % 'env') diff --git a/mistralclient/tests/unit/v2/test_executions.py b/mistralclient/tests/unit/v2/test_executions.py index 2b7fad36..71677e33 100644 --- a/mistralclient/tests/unit/v2/test_executions.py +++ b/mistralclient/tests/unit/v2/test_executions.py @@ -52,8 +52,8 @@ class TestExecutionsV2(base.BaseClientV2Test): EXEC['input']) self.assertIsNotNone(ex) - self.assertEqual(executions.Execution(self.executions, EXEC).__dict__, - ex.__dict__) + self.assertEqual(executions.Execution(self.executions, EXEC).to_dict(), + ex.to_dict()) mock.assert_called_once_with(URL_TEMPLATE, json.dumps(body)) @unittest2.expectedFailure @@ -76,8 +76,8 @@ class TestExecutionsV2(base.BaseClientV2Test): ex = self.executions.update(EXEC['id'], EXEC['state']) self.assertIsNotNone(ex) - self.assertEqual(executions.Execution(self.executions, EXEC).__dict__, - ex.__dict__) + self.assertEqual(executions.Execution(self.executions, EXEC).to_dict(), + ex.to_dict()) mock.assert_called_once_with( URL_TEMPLATE_ID % EXEC['id'], json.dumps(body)) @@ -89,8 +89,8 @@ class TestExecutionsV2(base.BaseClientV2Test): self.assertEqual(1, len(execution_list)) ex = execution_list[0] - self.assertEqual(executions.Execution(self.executions, EXEC).__dict__, - ex.__dict__) + self.assertEqual(executions.Execution(self.executions, EXEC).to_dict(), + ex.to_dict()) mock.assert_called_once_with(URL_TEMPLATE) def test_get(self): @@ -98,8 +98,8 @@ class TestExecutionsV2(base.BaseClientV2Test): ex = self.executions.get(EXEC['id']) - self.assertEqual(executions.Execution(self.executions, EXEC).__dict__, - ex.__dict__) + self.assertEqual(executions.Execution(self.executions, EXEC).to_dict(), + ex.to_dict()) mock.assert_called_once_with(URL_TEMPLATE_ID % EXEC['id']) def test_delete(self): diff --git a/mistralclient/tests/unit/v2/test_tasks.py b/mistralclient/tests/unit/v2/test_tasks.py index a0ef459f..0daf2104 100644 --- a/mistralclient/tests/unit/v2/test_tasks.py +++ b/mistralclient/tests/unit/v2/test_tasks.py @@ -41,7 +41,10 @@ class TestTasksV2(base.BaseClientV2Test): self.assertEqual(1, len(task_list)) task = task_list[0] - self.assertEqual(tasks.Task(self.tasks, TASK).__dict__, task.__dict__) + self.assertEqual( + tasks.Task(self.tasks, TASK).to_dict(), + task.to_dict() + ) mock.assert_called_once_with(URL_TEMPLATE) def test_get(self): @@ -49,6 +52,9 @@ class TestTasksV2(base.BaseClientV2Test): task = self.tasks.get(TASK['id']) - self.assertEqual(tasks.Task(self.tasks, TASK).__dict__, task.__dict__) + self.assertEqual( + tasks.Task(self.tasks, TASK).to_dict(), + task.to_dict() + ) mock.assert_called_once_with( URL_TEMPLATE_ID % TASK['id']) diff --git a/mistralclient/tests/unit/v2/test_workbooks.py b/mistralclient/tests/unit/v2/test_workbooks.py index c0c28981..1dc3f833 100644 --- a/mistralclient/tests/unit/v2/test_workbooks.py +++ b/mistralclient/tests/unit/v2/test_workbooks.py @@ -103,8 +103,8 @@ class TestWorkbooksV2(base.BaseClientV2Test): wb = workbook_list[0] self.assertEqual( - workbooks.Workbook(self.workbooks, WORKBOOK).__dict__, - wb.__dict__ + workbooks.Workbook(self.workbooks, WORKBOOK).to_dict(), + wb.to_dict() ) mock.assert_called_once_with(URL_TEMPLATE) @@ -116,8 +116,8 @@ class TestWorkbooksV2(base.BaseClientV2Test): self.assertIsNotNone(wb) self.assertEqual( - workbooks.Workbook(self.workbooks, WORKBOOK).__dict__, - wb.__dict__ + workbooks.Workbook(self.workbooks, WORKBOOK).to_dict(), + wb.to_dict() ) mock.assert_called_once_with(URL_TEMPLATE_NAME % 'wb')