Ejemplo n.º 1
0
def append_branch(request, nodeid, property, branchmetadataid):
    if request.method == 'POST':
        graph = ResourceGraph(nodeid)
        newBranch = graph.append_branch(property, branchmetadataid=branchmetadataid)
        graph.save()
        return JSONResponse(newBranch)

    return HttpResponseNotFound()
Ejemplo n.º 2
0
def load_resource_graph_file(path_to_file):
    if isfile(path_to_file) and path_to_file.endswith(suffix):
        basepath = path_to_file
        name = basepath.split(os.sep)[-1]

        with open(basepath, 'rU') as f:
            file = json.load(f)
            resource_graph = ResourceGraph(file['graph'][0])
            resource_graph.save()
Ejemplo n.º 3
0
def load_resource_graph_file(path_to_file):
    if isfile(path_to_file) and path_to_file.endswith(suffix):
        basepath = path_to_file
        name = basepath.split(os.sep)[-1]

        with open(basepath, 'rU') as f:
            file = json.load(f)
            resource_graph = ResourceGraph(file['graph'][0])
            resource_graph.save()
Ejemplo n.º 4
0
def append_branch(request, nodeid, property, branchmetadataid):
    if request.method == 'POST':
        graph = ResourceGraph(nodeid)
        newBranch = graph.append_branch(property,
                                        branchmetadataid=branchmetadataid)
        graph.save()
        return JSONResponse(newBranch)

    return HttpResponseNotFound()
Ejemplo n.º 5
0
    def test_branch_append(self):
        """
        test if a branch is properly appended to a graph

        """

        nodes_count_before = models.Node.objects.count()
        edges_count_before = models.Edge.objects.count()
        nodegroups_count_before = models.NodeGroup.objects.count()

        graph = ResourceGraph(self.rootNode)
        graph.append_branch(
            'P1', branchmetadataid=self.NODE_NODETYPE_BRANCHMETADATAID)
        graph.save()

        self.assertEqual(len(graph.nodes), 3)
        self.assertEqual(len(graph.edges), 2)
        self.assertEqual(len(graph.nodegroups), 2)

        self.assertEqual(models.Node.objects.count() - nodes_count_before, 2)
        self.assertEqual(models.Edge.objects.count() - edges_count_before, 2)
        self.assertEqual(
            models.NodeGroup.objects.count() - nodegroups_count_before, 1)

        for key, edge in graph.edges.iteritems():
            self.assertIsNotNone(graph.nodes[edge.domainnode_id])
            self.assertIsNotNone(graph.nodes[edge.rangenode_id])
            self.assertEqual(edge.domainnode, graph.nodes[edge.domainnode.pk])
            self.assertEqual(edge.rangenode, graph.nodes[edge.rangenode.pk])

        for key, node in graph.nodes.iteritems():
            if node.istopnode:
                self.assertEqual(node, self.rootNode)

        appended_branch = graph.append_branch(
            'P1', branchmetadataid=self.SINGLE_NODE_BRANCHMETADATAID)
        graph.save()
        self.assertEqual(len(graph.nodes), 4)
        self.assertEqual(len(graph.edges), 3)
        self.assertEqual(len(graph.nodegroups), 2)

        self.assertEqual(models.Node.objects.count() - nodes_count_before, 3)
        self.assertEqual(models.Edge.objects.count() - edges_count_before, 3)
        self.assertEqual(
            models.NodeGroup.objects.count() - nodegroups_count_before, 1)

        self.assertEqual(appended_branch.root.nodegroup,
                         self.rootNode.nodegroup)
Ejemplo n.º 6
0
    def test_branch_append(self):
        """
        test if a branch is properly appended to a graph

        """

        nodes_count_before = models.Node.objects.count()
        edges_count_before = models.Edge.objects.count()
        nodegroups_count_before = models.NodeGroup.objects.count()

        graph = ResourceGraph(self.rootNode)
        graph.append_branch('P1', branchmetadataid=self.NODE_NODETYPE_BRANCHMETADATAID)
        graph.save()

        self.assertEqual(len(graph.nodes), 3)
        self.assertEqual(len(graph.edges), 2)
        self.assertEqual(len(graph.nodegroups), 2)

        self.assertEqual(models.Node.objects.count()-nodes_count_before, 2)
        self.assertEqual(models.Edge.objects.count()-edges_count_before, 2)
        self.assertEqual(models.NodeGroup.objects.count()-nodegroups_count_before, 1)

        for key, edge in graph.edges.iteritems():
            self.assertIsNotNone(graph.nodes[edge.domainnode_id])
            self.assertIsNotNone(graph.nodes[edge.rangenode_id])
            self.assertEqual(edge.domainnode, graph.nodes[edge.domainnode.pk])
            self.assertEqual(edge.rangenode, graph.nodes[edge.rangenode.pk])

        for key, node in graph.nodes.iteritems():
            if node.istopnode:
                self.assertEqual(node, self.rootNode)


        appended_branch = graph.append_branch('P1', branchmetadataid=self.SINGLE_NODE_BRANCHMETADATAID)
        graph.save()
        self.assertEqual(len(graph.nodes), 4)
        self.assertEqual(len(graph.edges), 3)
        self.assertEqual(len(graph.nodegroups), 2)

        self.assertEqual(models.Node.objects.count()-nodes_count_before, 3)
        self.assertEqual(models.Edge.objects.count()-edges_count_before, 3)
        self.assertEqual(models.NodeGroup.objects.count()-nodegroups_count_before, 1)

        self.assertEqual(appended_branch.root.nodegroup,self.rootNode.nodegroup)