本文整理汇总了Python中arches.app.models.graph.Graph.move_node方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.move_node方法的具体用法?Python Graph.move_node怎么用?Python Graph.move_node使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.models.graph.Graph
的用法示例。
在下文中一共展示了Graph.move_node方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_move_node
# 需要导入模块: from arches.app.models.graph import Graph [as 别名]
# 或者: from arches.app.models.graph.Graph import move_node [as 别名]
def test_move_node(self):
"""
test if a node can be successfully moved to another node in the graph
"""
# test moving a single node to another branch
# this node should be grouped with it's new parent nodegroup
graph = Graph(self.rootNode)
branch_one = graph.append_branch('P1', graphid=self.NODE_NODETYPE_GRAPHID)
branch_two = graph.append_branch('P1', graphid=self.NODE_NODETYPE_GRAPHID)
branch_three = graph.append_branch('P1', graphid=self.SINGLE_NODE_GRAPHID)
branch_three_nodeid = branch_three.nodes.iterkeys().next()
branch_one_rootnodeid = branch_one.root.nodeid
graph.move_node(branch_three_nodeid, 'P1', branch_one_rootnodeid)
new_parent_nodegroup = None
moved_branch_nodegroup = None
for node_id, node in graph.nodes.iteritems():
if node_id == branch_one_rootnodeid:
new_parent_nodegroup = node.nodegroup
if node_id == branch_three_nodeid:
moved_branch_nodegroup = node.nodegroup
self.assertIsNotNone(new_parent_nodegroup)
self.assertIsNotNone(moved_branch_nodegroup)
self.assertEqual(new_parent_nodegroup, moved_branch_nodegroup)
# test moving a branch to another branch
# this branch should NOT be grouped with it's new parent nodegroup
branch_two_rootnodeid = branch_two.root.nodeid
graph.move_node(branch_one_rootnodeid, 'P1', branch_two_rootnodeid)
new_parent_nodegroup = None
moved_branch_nodegroup = None
for node_id, node in graph.nodes.iteritems():
if node_id == branch_two_rootnodeid:
new_parent_nodegroup = node.nodegroup
if node_id == branch_one_rootnodeid:
moved_branch_nodegroup = node.nodegroup
self.assertIsNotNone(new_parent_nodegroup)
self.assertIsNotNone(moved_branch_nodegroup)
self.assertNotEqual(new_parent_nodegroup, moved_branch_nodegroup)
updated_edge = None
for edge_id, edge in graph.edges.iteritems():
if (edge.domainnode_id == branch_two_rootnodeid and
edge.rangenode_id == branch_one_rootnodeid):
updated_edge = edge
self.assertIsNotNone(updated_edge)
# save and retrieve the graph from the database and confirm that
# the graph shape has been saved properly
graph.save()
graph = Graph(self.rootNode)
tree = graph.get_tree()
self.assertEqual(len(tree['children']), 1)
level_one_node = tree['children'][0]
self.assertEqual(branch_two_rootnodeid, level_one_node['node'].nodeid)
self.assertEqual(len(level_one_node['children']), 2)
for child in level_one_node['children']:
if child['node'].nodeid == branch_one_rootnodeid:
self.assertEqual(len(child['children']), 2)
found_branch_three = False
for child in child['children']:
if child['node'].nodeid == branch_three_nodeid:
found_branch_three = True
self.assertTrue(found_branch_three)
else:
self.assertEqual(len(child['children']), 0)