def test_find_descendants_with_multiple_parent_get_without_parents(self): parent_2 = EntityFactory(country=self.country) EntityVersionFactory(entity=parent_2, parent=None, acronym="ROOT_ENTITY_2", start_date=self.start_date, end_date=self.end_date) ### Create one child entity child = EntityFactory(country=self.country) EntityVersionFactory(entity=child, parent=parent_2, acronym="CHILD_OF_ROOT_2", start_date=self.start_date, end_date=self.end_date) ### Create one child entity with parent CHILD_OF_ROOT_2 child_2 = EntityFactory(country=self.country) EntityVersionFactory(entity=child_2, parent=child, acronym="CHILD_OF_CHILD", start_date=self.start_date, end_date=self.end_date) entities_with_descendants = entity.find_descendants( [self.parent, parent_2], date=self.date_in_2015, with_entities=False) self.assertEqual(len(entities_with_descendants), 6) # 4 for parent + 2 for parent_2
def find_entities_by_person(person): person_entities = PersonEntity.objects.filter( person=person).select_related('entity') entities = set() entities |= { pers_ent.entity for pers_ent in person_entities if not pers_ent.with_child } entity_with_child = [ pers_ent.entity for pers_ent in person_entities if pers_ent.with_child ] if entity_with_child: entity_with_find_descendants = entity.find_descendants( entity_with_child, with_entities=True) entities |= set(entity_with_find_descendants ) if entity_with_find_descendants else set() return list(entities)
def test_find_descendants_without_parent(self): entities_with_descendants = entity.find_descendants( [self.parent], date=self.date_in_2015, with_entities=False) self.assertEqual(len(entities_with_descendants), 4)
def test_find_descendants_out_date(self): entities_with_descendants = entity.find_descendants( [self.parent], date=self.date_in_2017) self.assertFalse(entities_with_descendants)
def find_entities_with_descendants_from_entity_managers(entities_manager): entities = [entity_manager.entity for entity_manager in entities_manager] entities_with_descendants = entity.find_descendants(entities) return entities_with_descendants