From d8824eeb63b0e5019a39b1b1a301328e329c363b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 22 Sep 2016 15:29:11 +0200 Subject: [PATCH] Fixed issue saving tasks. The Eve hook that added 'parent_info' caused this issue, as the validation fails when saving a document that contains this. The easiest fix was to prefix it with an underscore, so that the SDK automatically strips it before saving. --- attract/tasks/eve_hooks.py | 2 +- tests/test_tasks.py | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/attract/tasks/eve_hooks.py b/attract/tasks/eve_hooks.py index 2abd11e..92b3746 100644 --- a/attract/tasks/eve_hooks.py +++ b/attract/tasks/eve_hooks.py @@ -32,7 +32,7 @@ def fetch_task_parent_info(node): return parent.pop('_id') # always there, but also already included in the node. - node['parent_info'] = parent + node['_parent_info'] = parent def fetch_tasks_parent_info(nodes): diff --git a/tests/test_tasks.py b/tests/test_tasks.py index ba1b66b..6fa1f4f 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -4,11 +4,13 @@ import responses from bson import ObjectId import pillarsdk +import pillar.api.utils import pillar.tests import pillar.auth import pillar.tests.common_test_data as ctd from abstract_attract_test import AbstractAttractTest +from pillarsdk.utils import remove_private_keys class TaskWorkflowTest(AbstractAttractTest): @@ -20,13 +22,13 @@ class TaskWorkflowTest(AbstractAttractTest): self.sdk_project = pillarsdk.Project(pillar.tests.mongo_to_sdk(self.project)) - def create_task(self, task_type=None): + def create_task(self, task_type=None, parent=None): with self.app.test_request_context(): # Log in as project admin user pillar.auth.login_user(ctd.EXAMPLE_PROJECT_OWNER_ID) self.mock_blenderid_validate_happy() - task = self.mngr.create_task(self.sdk_project, task_type=task_type) + task = self.mngr.create_task(self.sdk_project, task_type=task_type, parent=parent) self.assertIsInstance(task, pillarsdk.Node) return task @@ -71,3 +73,22 @@ class TaskWorkflowTest(AbstractAttractTest): self.assertEqual(u'todo', found['properties']['status']) self.assertEqual(u'nööw name', found['name']) self.assertEqual(u'€ ≠ ¥', found['description']) + + @responses.activate + def test_load_save_task(self): + """Test for the Eve hooks -- we should be able to PUT what we GET.""" + + task_parent = self.create_task(task_type=u'Just düüüh it') + task_child = self.create_task(task_type=u'mamaaaah', + parent=task_parent['_id']) + + self.create_valid_auth_token(ctd.EXAMPLE_PROJECT_OWNER_ID, 'token') + + url = '/api/nodes/%s' % task_child['_id'] + resp = self.get(url) + json_task = resp.json() + + self.put(url, + json=remove_private_keys(json_task), + auth_token='token', + headers={'If-Match': json_task['_etag']})