Merge "Adding to_dict() method to Resource class"

This commit is contained in:
Jenkins
2015-08-05 14:08:45 +00:00
committed by Gerrit Code Review
6 changed files with 32 additions and 22 deletions

View File

@@ -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()])

View File

@@ -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'])

View File

@@ -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')

View File

@@ -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):

View File

@@ -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'])

View File

@@ -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')