Moved node_setattr() to pillar.api.utils.
This commit is contained in:
@@ -6,7 +6,7 @@ import logging
|
||||
import attr
|
||||
import flask
|
||||
import flask_login
|
||||
from bson import ObjectId
|
||||
|
||||
from eve.methods.put import put_internal
|
||||
from werkzeug import exceptions as wz_exceptions
|
||||
|
||||
@@ -14,6 +14,7 @@ import pillarsdk
|
||||
import pillar.api.utils
|
||||
from pillar.web.system_util import pillar_api
|
||||
from pillar.api.nodes.custom import register_patch_handler
|
||||
from pillar.api.utils import node_setattr
|
||||
from pillar import attrs_extra
|
||||
|
||||
from attract.node_types import node_type_shot, node_type_task
|
||||
@@ -206,23 +207,6 @@ class ShotManager(object):
|
||||
return summary
|
||||
|
||||
|
||||
def node_setattr(node, key, value):
|
||||
"""Sets a node property by dotted key.
|
||||
|
||||
Modifies the node in-place. Deletes None values.
|
||||
"""
|
||||
|
||||
set_on = node
|
||||
while key and '.' in key:
|
||||
head, key = key.split('.', 1)
|
||||
set_on = set_on[head]
|
||||
|
||||
if value is None:
|
||||
set_on.pop(key, None)
|
||||
else:
|
||||
set_on[key] = value
|
||||
|
||||
|
||||
@register_patch_handler(node_type_shot['name'])
|
||||
def patch_shot(node_id, patch):
|
||||
assert_is_valid_patch(patch)
|
||||
|
@@ -146,63 +146,6 @@ class ShotManagerTest(AbstractShotTest):
|
||||
# def shot_status_summary(self, project_id):
|
||||
|
||||
|
||||
class NodeSetattrTest(unittest.TestCase):
|
||||
def test_simple(self):
|
||||
from attract.shots import node_setattr
|
||||
|
||||
node = {}
|
||||
node_setattr(node, 'a', 5)
|
||||
self.assertEqual({'a': 5}, node)
|
||||
|
||||
node_setattr(node, 'b', {'complexer': 'value'})
|
||||
self.assertEqual({'a': 5, 'b': {'complexer': 'value'}}, node)
|
||||
|
||||
def test_dotted(self):
|
||||
from attract.shots import node_setattr
|
||||
|
||||
node = {}
|
||||
self.assertRaises(KeyError, node_setattr, node, 'a.b', 5)
|
||||
|
||||
node = {'b': {}}
|
||||
node_setattr(node, 'b.simple', 'value')
|
||||
self.assertEqual({'b': {'simple': 'value'}}, node)
|
||||
|
||||
node_setattr(node, 'b.complex', {'yes': 'value'})
|
||||
self.assertEqual({'b': {'simple': 'value',
|
||||
'complex': {'yes': 'value'}}}, node)
|
||||
|
||||
node_setattr(node, 'b.complex', {'yes': 5})
|
||||
self.assertEqual({'b': {'simple': 'value',
|
||||
'complex': {'yes': 5}}}, node)
|
||||
|
||||
def test_none_simple(self):
|
||||
from attract.shots import node_setattr
|
||||
|
||||
node = {}
|
||||
node_setattr(node, 'a', None)
|
||||
node_setattr(node, None, 'b')
|
||||
self.assertEqual({None: 'b'}, node)
|
||||
|
||||
def test_none_dotted(self):
|
||||
from attract.shots import node_setattr
|
||||
|
||||
node = {}
|
||||
self.assertRaises(KeyError, node_setattr, node, 'a.b', None)
|
||||
|
||||
node = {'b': {}}
|
||||
node_setattr(node, 'b.simple', None)
|
||||
self.assertEqual({'b': {}}, node)
|
||||
|
||||
node_setattr(node, 'b.complex', {'yes': None})
|
||||
self.assertEqual({'b': {'complex': {'yes': None}}}, node)
|
||||
|
||||
node_setattr(node, 'b.complex.yes', None)
|
||||
self.assertEqual({'b': {'complex': {}}}, node)
|
||||
|
||||
node_setattr(node, 'b.complex', {None: 5})
|
||||
self.assertEqual({'b': {'complex': {None: 5}}}, node)
|
||||
|
||||
|
||||
class PatchShotTest(AbstractShotTest):
|
||||
@responses.activate
|
||||
def test_patch_from_blender_happy(self):
|
||||
|
Reference in New Issue
Block a user