def test_can_pull_relationship(self): a = Node() b = Node() alpha = Relationship(a, "TO", b, since=1999) beta = Relationship(a, "TO", b) self.graph.create(alpha) assert dict(beta) == {} beta.__remote__ = RemoteEntity(remote(alpha).uri) beta.pull() assert dict(beta) == dict(alpha)
def insertCoreRelWrap(self, rel, start_node_uuid, end_node_uuid, relid): print 'inside graph db work - relid ' +str(relid) start_node = self.entity(start_node_uuid) end_node = self.entity(end_node_uuid) #construct the relation object newrel = Relationship(start_node,rel.type,end_node) #copy the props for prop in rel.properties: newrel[prop] = rel[prop] newrel['relid'] = relid ##TODO: db work here! #in the end just copy the new relation id self.graph.create(newrel) ##create the actual graph object! newrel.pull() return newrel
def test_TwoNodesOneRelation(graph): #create nodes first = Node("Politician","Person",name="Narendra Modi",age="56") second = Node("Party","Organization",name="BJP") employee = Relationship(first,"EmployeeOf",second) create_with_cp(graph,first,second,employee) #add props first.pull() second.pull() employee.pull() first['live']='true' second['live']='true' employee['current']='true' push_with_cp(graph,first,second,employee) #add labels, you cannot add another type or delete the previous type of a relation in neo4j first.pull() second.pull() employee.pull() first.labels.add('IndianPrimeMinister') first['address']='Gujarat' second.labels.add('PoliticalParty') second['address']='Delhi' employee['workingaddress']='CP' push_with_cp(graph,first,second,employee) #add a label and remove a label in both nodes first.pull() first.labels.add('ChiefMinister') first.labels.remove('IndianPrimeMinister') second.pull() second.labels.add('NationalParty') second.labels.remove('PoliticalParty') #doing no chnage to the relationship to see if nodes are updated and the relation old push_with_cp(graph,first,second) #change a prop first.pull() first['name']='Narendra Damodar Modi' second.pull() second['name']='Bhartiya Janta Party' employee.pull() employee['workingaddress']='Connaught Palace' push_with_cp(graph,first,second,employee) #remove a property first.pull() first.properties['live']=None second.pull() second.properties['live']=None employee.pull() employee.properties['current']=None push_with_cp(graph,first,second,employee) #delete both nodes and rels ##EVEN BEFORE DELETING A RELATION, you will have to pull ##this we can fix : TODO in delete method employee.pull() delete_with_cp(graph,first,second,employee) third=Node("Person",name="Abhishek Agarwal") create_with_cp(graph,third)
def test_TwoNodesOneRelation(graph): #create nodes first = Node("Politician", "Person", name="Narendra Modi", age="56") second = Node("Party", "Organization", name="BJP") employee = Relationship(first, "EmployeeOf", second) create_with_cp(graph, first, second, employee) #add props first.pull() second.pull() employee.pull() first['live'] = 'true' second['live'] = 'true' employee['current'] = 'true' push_with_cp(graph, first, second, employee) #add labels, you cannot add another type or delete the previous type of a relation in neo4j first.pull() second.pull() employee.pull() first.labels.add('IndianPrimeMinister') first['address'] = 'Gujarat' second.labels.add('PoliticalParty') second['address'] = 'Delhi' employee['workingaddress'] = 'CP' push_with_cp(graph, first, second, employee) #add a label and remove a label in both nodes first.pull() first.labels.add('ChiefMinister') first.labels.remove('IndianPrimeMinister') second.pull() second.labels.add('NationalParty') second.labels.remove('PoliticalParty') #doing no chnage to the relationship to see if nodes are updated and the relation old push_with_cp(graph, first, second) #change a prop first.pull() first['name'] = 'Narendra Damodar Modi' second.pull() second['name'] = 'Bhartiya Janta Party' employee.pull() employee['workingaddress'] = 'Connaught Palace' push_with_cp(graph, first, second, employee) #remove a property first.pull() first.properties['live'] = None second.pull() second.properties['live'] = None employee.pull() employee.properties['current'] = None push_with_cp(graph, first, second, employee) #delete both nodes and rels ##EVEN BEFORE DELETING A RELATION, you will have to pull ##this we can fix : TODO in delete method employee.pull() delete_with_cp(graph, first, second, employee) third = Node("Person", name="Abhishek Agarwal") create_with_cp(graph, third)