Exemplo n.º 1
0
 def test_graph_clone(self):
     """
     Tests graph clonation
     """
     cloneGraphName = "graphCloneTest"
     mySchema_clone = Schema.objects.create()
     nt = NodeType(id=2, name="test", schema=mySchema_clone)
     nt.save()
     clone_graph = Graph.objects.create(name=cloneGraphName, schema=mySchema_clone, owner=self.u)
     self.assertIsNotNone(clone_graph)
     self.assertNotEqual(self.graph.name, clone_graph.name)
     self.graph.clone(clone_graph, clone_data=True)
     self.assertNotEqual(self.graph, clone_graph)
     self.assertEqual(self.graph.nodes.count(), clone_graph.nodes.count())
     Graph.objects.get(name=self.graphName).destroy()
     Graph.objects.get(name=cloneGraphName).destroy()
Exemplo n.º 2
0
 def setUp(self):
     self.factory = RequestFactory()
     self.c = Client()
     self.u = User.objects.create(username="******", password="******", is_active=True, is_staff=True)
     self.u.set_password("hello")
     self.u.save()
     mySchema = Schema.objects.create()
     nt = NodeType(id=1, name="test", schema=mySchema)
     nt.save()
     # If label is not a number, it fires an exception
     self.label = "1"
     self.properties = {"property": "value with spaces"}
     self.unicode_label = u"1"
     self.unicode_properties = {u"property": u"value with spaces"}
     self.graphName = "graphTest"
     self.graph = Graph.objects.create(name=self.graphName, schema=mySchema, owner=self.u)
Exemplo n.º 3
0
 def test_graph_clone(self):
     """
     Tests graph clonation
     """
     cloneGraphName = "graphCloneTest"
     mySchema_clone = Schema.objects.create()
     nt = NodeType(id=2, name="test", schema=mySchema_clone)
     nt.save()
     clone_graph = Graph.objects.create(name=cloneGraphName,
         schema=mySchema_clone, owner=self.u)
     self.assertIsNotNone(clone_graph)
     self.assertNotEqual(self.graph.name, clone_graph.name)
     self.graph.clone(clone_graph, clone_data=True)
     self.assertNotEqual(self.graph, clone_graph)
     self.assertEqual(self.graph.nodes.count(), clone_graph.nodes.count())
     Graph.objects.get(name=self.graphName).destroy()
     Graph.objects.get(name=cloneGraphName).destroy()
Exemplo n.º 4
0
 def setUp(self):
     self.factory = RequestFactory()
     self.c = Client()
     self.u = User.objects.create(username='******', password='******', is_active=True, is_staff=True)
     self.u.set_password('hello')
     self.u.save()
     mySchema = Schema.objects.create()
     nt = NodeType(id=1, name="test", schema=mySchema)
     nt.save()
     # If label is not a number, it fires an exception
     self.label = "1"
     self.properties = {"property": "value with spaces"}
     self.unicode_label = u"1"
     self.unicode_properties = {u"property": u"value with spaces"}
     self.graphName = "graphTest"
     self.graph = Graph.objects.create(name=self.graphName,
         schema=mySchema, owner=self.u)
Exemplo n.º 5
0
 def _clone_schema(self, schema, new_schema):
     nodetypes_map = {}  # map old/new nodetypes IDs
     relationtypes_map = {}  # map old/new relationtypes IDs
     nodetypes = schema.nodetype_set.all()
     for nt in nodetypes:
         new_nt = NodeType(schema=new_schema,
                           name=nt.name,
                           plural_name=nt.plural_name,
                           description=nt.description,
                           order=nt.order,
                           total=0,
                           validation=nt.validation)
         new_nt.save()
         nodetypes_map[nt.id] = new_nt.id
         properties = nt.properties.all()
         for np in properties:
             new_np = NodeProperty(node=new_nt,
                                   key=np.key,
                                   value=np.value,
                                   default=np.default,
                                   datatype=np.datatype,
                                   required=np.required,
                                   display=np.display,
                                   description=np.description,
                                   validation=np.validation,
                                   order=np.order)
             new_np.save()
     relationtypes = schema.relationshiptype_set.all()
     for rt in relationtypes:
         source = NodeType.objects.get(schema=new_schema,
                                       name=rt.source.name)
         target = NodeType.objects.get(schema=new_schema,
                                       name=rt.target.name)
         new_rt = RelationshipType(schema=new_schema,
                                   source=source,
                                   target=target,
                                   name=rt.name,
                                   plural_name=rt.plural_name,
                                   description=rt.description,
                                   order=rt.order,
                                   total=0,
                                   validation=rt.validation,
                                   inverse=rt.inverse,
                                   plural_inverse=rt.plural_inverse,
                                   arity_source=rt.arity_source,
                                   arity_target=rt.arity_target)
         new_rt.save()
         relationtypes_map[rt.id] = new_rt.id
         properties = rt.properties.all()
         for rp in properties:
             new_rp = RelationshipProperty(relationship=new_rt,
                                           key=rp.key,
                                           value=rp.value,
                                           default=rp.default,
                                           datatype=rp.datatype,
                                           required=rp.required,
                                           display=rp.display,
                                           description=rp.description,
                                           validation=rp.validation,
                                           order=rp.order)
             new_rp.save()
     return nodetypes_map, relationtypes_map
Exemplo n.º 6
0
 def _clone_schema(self, schema, new_schema):
     nodetypes_map = {}      # map old/new nodetypes IDs
     relationtypes_map = {}  # map old/new relationtypes IDs
     nodetypes = schema.nodetype_set.all()
     for nt in nodetypes:
         new_nt = NodeType(schema=new_schema,
                           name=nt.name,
                           plural_name=nt.plural_name,
                           description=nt.description,
                           order=nt.order,
                           total=0,
                           validation=nt.validation)
         new_nt.save()
         nodetypes_map[nt.id] = new_nt.id
         properties = nt.properties.all()
         for np in properties:
             new_np = NodeProperty(node=new_nt,
                                   key=np.key,
                                   value=np.value,
                                   default=np.default,
                                   datatype=np.datatype,
                                   required=np.required,
                                   display=np.display,
                                   description=np.description,
                                   validation=np.validation,
                                   order=np.order)
             new_np.save()
     relationtypes = schema.relationshiptype_set.all()
     for rt in relationtypes:
         source = NodeType.objects.get(schema=new_schema,
                                       name=rt.source.name)
         target = NodeType.objects.get(schema=new_schema,
                                       name=rt.target.name)
         new_rt = RelationshipType(schema=new_schema,
                                   source=source,
                                   target=target,
                                   name=rt.name,
                                   plural_name=rt.plural_name,
                                   description=rt.description,
                                   order=rt.order,
                                   total=0,
                                   validation=rt.validation,
                                   inverse=rt.inverse,
                                   plural_inverse=rt.plural_inverse,
                                   arity_source=rt.arity_source,
                                   arity_target=rt.arity_target)
         new_rt.save()
         relationtypes_map[rt.id] = new_rt.id
         properties = rt.properties.all()
         for rp in properties:
             new_rp = RelationshipProperty(relationship=new_rt,
                                           key=rp.key,
                                           value=rp.value,
                                           default=rp.default,
                                           datatype=rp.datatype,
                                           required=rp.required,
                                           display=rp.display,
                                           description=rp.description,
                                           validation=rp.validation,
                                           order=rp.order)
             new_rp.save()
     return nodetypes_map, relationtypes_map