def setUp(cls): cls.VALUE_KEY = "@display_value" cls.RESOURCE_KEY = "resource" cls.DISPLAY_DESCRIPTION_KEY = "displaydescription" cls.DISPLAY_NAME_KEY = "displayname" cls.GRAPH_ID_KEY = "graph_id" cls.LEGACY_ID_KEY = "legacyid" cls.MAP_POPUP_KEY = "map_popup" cls.RESOURCE_INSTANCE_ID_KEY = "resourceinstanceid" cls.nodegroup = models.NodeGroup() cls.grouping_node = models.Node(datatype="semantic", name="Test Node Grouping", nodegroup=cls.nodegroup) cls.string_node = models.Node(datatype="string", name="Test Node") cls.grouping_tile = models.TileModel(data={}, nodegroup_id=str( cls.grouping_node.pk)) cls.string_tile = models.TileModel( data={str(cls.string_node.pk): "value_1"}, nodegroup_id=str(cls.string_node.pk)) cls.grouping_node.nodegroupid = cls.grouping_node.nodeid cls.string_node.nodegroupid = cls.string_node.nodeid # let's mock Resource since it's minimally used # and complex to get `displayname` cls.test_resource = mock.Mock(displayname="Test Resource", tiles=[])
def setUp(cls): cls.grouping_node = models.Node(datatype="semantic", name="Test Node Grouping") cls.string_node = models.Node(datatype="string", name="Test Node") cls.grouping_tile = models.TileModel(data={}, nodegroup_id=str(cls.grouping_node.pk)) cls.string_tile = models.TileModel(data={str(cls.string_node.pk): "value_1"}, nodegroup_id=str(cls.string_node.pk)) # le'ts mock Resource since it's minimally used # and complex to get `displayname` cls.test_resource = mock.Mock(displayname="Test Resource", tiles=[])
def add_node(self, node): """ Adds a node to this graph Arguments: node -- a dictionary representing a Node instance or an actual models.Node instance """ if not isinstance(node, models.Node): nodeobj = node.copy() node = models.Node() node.nodeid = nodeobj.get('nodeid', None) node.name = nodeobj.get('name', '') node.description = nodeobj.get('description', '') node.istopnode = nodeobj.get('istopnode', '') node.ontologyclass = nodeobj.get('ontologyclass', '') node.datatype = nodeobj.get('datatype', '') node.nodegroup_id = nodeobj.get('nodegroupid', '') node.branchmetadata_id = nodeobj.get('branchmetadataid', '') if node.nodegroup_id != None and node.nodegroup_id != '': node.nodegroup = models.NodeGroup(pk=node.nodegroup_id, cardinality=nodeobj.get( 'cardinality', '')) if node.pk == None: node.pk = uuid.uuid1() if node.nodegroup != None: self.nodegroups[node.nodegroup.pk] = node.nodegroup self.nodes[node.pk] = node return node
def add_node(self, node, nodegroups=None): """ Adds a node to this graph Arguments: node -- a dictionary representing a Node instance or an actual models.Node instance """ if not isinstance(node, models.Node): nodeobj = node.copy() node = models.Node() node.nodeid = nodeobj.get('nodeid', None) node.name = nodeobj.get('name', '') node.description = nodeobj.get('description', '') node.istopnode = nodeobj.get('istopnode', '') node.ontologyclass = nodeobj.get('ontologyclass', '') node.datatype = nodeobj.get('datatype', '') node.nodegroup_id = nodeobj.get('nodegroup_id', '') node.config = nodeobj.get('config', None) node.issearchable = nodeobj.get('issearchable', True) node.nodeid = uuid.UUID(str(node.nodeid)) if node.nodegroup_id != None and node.nodegroup_id != '': node.nodegroup_id = uuid.UUID(str(node.nodegroup_id)) node.nodegroup = self.get_or_create_nodegroup( nodegroupid=node.nodegroup_id) if nodegroups is not None and str( node.nodegroup_id) in nodegroups: node.nodegroup.cardinality = nodegroups[str( node.nodegroup_id)]["cardinality"] node.nodegroup.legacygroupid = nodegroups[str( node.nodegroup_id)]["legacygroupid"] node.nodegroup.parentnodegroupid = nodegroups[str( node.nodegroup_id)]["parentnodegroup_id"] else: node.nodegroup = None node.graph = self if self.ontology == None: node.ontologyclass = None if node.pk == None: node.pk = uuid.uuid1() if node.istopnode: self.root = node self.nodes[node.pk] = node return node
def add_node(self, node): """ Adds a node to this graph Arguments: node -- a dictionary representing a Node instance or an actual models.Node instance """ if not isinstance(node, models.Node): nodeobj = node.copy() node = models.Node() node.nodeid = nodeobj.get('nodeid', None) node.name = nodeobj.get('name', '') node.description = nodeobj.get('description', '') node.istopnode = nodeobj.get('istopnode', '') node.ontologyclass = nodeobj.get('ontologyclass', '') node.datatype = nodeobj.get('datatype', '') node.nodegroup_id = nodeobj.get('nodegroup_id', '') node.validations.set(nodeobj.get('validations', [])) if node.nodegroup_id != None and node.nodegroup_id != '': node.nodegroup_id = uuid.UUID(str(node.nodegroup_id)) node.nodegroup = self.get_or_create_nodegroup( nodegroupid=node.nodegroup_id) else: node.nodegroup = None node.graph = self if self.ontology == None: node.ontologyclass = None if node.pk == None: node.pk = uuid.uuid1() if node.istopnode: self.root = node self.nodes[node.pk] = node return node