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.
This commit is contained in:
2016-09-22 15:29:11 +02:00
parent 8a360c0cda
commit d8824eeb63
2 changed files with 24 additions and 3 deletions

View File

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

View File

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