def test_put_elts(self): """ Test put elts method. """ vertice = Vertice() def assertVertice(): """ Assert vertice exists in DB """ # get vertice _vertice = self.manager.get_elts(ids=vertice.id) # check ids self.assertEqual(_vertice.id, vertice.id) # delete vertice self.manager.del_elts() self.manager.put_elts(elts=vertice) assertVertice() self.manager.put_elts(elts=vertice.to_dict()) assertVertice() self.manager.put_elts(elts=[vertice]) assertVertice() self.manager.put_elts(elts=[vertice.to_dict()]) assertVertice()
def test_get_neighbourhood(self): """ Test get_neighbourhood method. """ # test empty result neighbourhood = self.manager.get_neighbourhood(ids='') self.assertFalse(neighbourhood) # test all vertices neighbourhood = set(self.manager.get_neighbourhood()) self.assertEqual(len(neighbourhood), len(self.elts)) # let's play with few vertices, edges and graphs v0, v1, v2 = Vertice(type='0'), Vertice(type='1'), Vertice(type='2') e0, e1, e2 = Edge(type='0'), Edge(type='1'), Edge(type='2') g0, g1, g2 = Graph(type='0'), Graph(type='1'), Graph(type='2') # connect v0 to v1 e0.directed = True e0.sources = [v0.id, v1.id, v2.id] e0.targets = [g0.id, g1.id, g2.id] # save all elements v0.save(self.manager), v1.save(self.manager), v2.save(self.manager) e0.save(self.manager), e1.save(self.manager), e2.save(self.manager) g0.save(self.manager), g1.save(self.manager), g2.save(self.manager) # test ids neighbourhood = set(self.manager.get_neighbourhood(ids=v0.id)) self.assertEqual(neighbourhood, {g0, g1, g2}) # test sources neighbourhood = set(self.manager.get_neighbourhood( ids=v0.id, sources=True)) self.assertEqual(neighbourhood, {g0, g1, g2, v0, v1, v2}) # test not targets neighbourhood = set(self.manager.get_neighbourhood( ids=v0.id, targets=False)) self.assertEqual(neighbourhood, set()) # test not directed e0.directed = False e0.save(self.manager) neighbourhood = set(self.manager.get_neighbourhood( ids=v0.id)) self.assertEqual(neighbourhood, {g0, g1, g2, v0, v1, v2})