Esempio n. 1
0
    def test_partnered_other_to_female_resolves_to_female_to_other(self):
        '''
        Tests when an other gender partners a female, it resolves to females partners an other gender
        '''
        other = Person(name="other", gender="O", family_id=self.family.id)
        other.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = other.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)
        self.assertEqual(other.id, relation.to_person_id)
Esempio n. 2
0
    def test_partnered_other_to_female_resolves_to_female_to_other(self):
        '''
        Tests when an other gender partners a female, it resolves to females partners an other gender
        '''
        other = Person(name="other", gender="O", family_id=self.family.id)
        other.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = other.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)
        self.assertEqual(other.id, relation.to_person_id)
Esempio n. 3
0
    def test_partnered_male_to_female_resolves_to_female_to_male(self):
        '''
        Tests when a male partners a female, it resolves to females partners a male
        '''
        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = male.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
Esempio n. 4
0
    def test_partnered_male_to_female_resolves_to_female_to_male(self):
        '''
        Tests when a male partners a female, it resolves to females partners a male
        '''
        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        relation = Relation(from_person_id = male.id, to_person_id = female.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
Esempio n. 5
0
    def test_hierachy_score_set_for_adding_child(self):
        '''
        Ensure that hierachy score is set when adding the child of a parent
        the relation is not passed to the function
        '''

        parent = Person(name='parent', gender='M', hierarchy_score = 100, family_id=self.family.id)
        parent.save()

        child = Person(name='child', gender='M', family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = parent.id, to_person_id = child.id, relation_type = RAISED)
        relation.save()

        child.set_hierarchy_score()
        self.assertEqual(101, child.hierarchy_score)
Esempio n. 6
0
    def test_hierachy_score_set_for_adding_partner(self):
        '''
        Ensure that hierachy score is set when adding a partner
        '''

        husband = Person(name='husband', gender='M', family_id=self.family.id)
        husband.save()

        wife = Person(name='wife', gender='F', hierarchy_score = 75, family_id=self.family.id)
        wife.save()

        relation = Relation(from_person_id = husband.id, to_person_id = wife.id, relation_type = PARTNERED)
        relation.save()

        husband.set_hierarchy_score()

        self.assertEqual(75, husband.hierarchy_score)
Esempio n. 7
0
    def test_partnered_female_to_male_stays_the_same(self):
        '''
        Tests when a female partners a male, the relationship does not change
        '''

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        relation = Relation(from_person_id = female.id, to_person_id = male.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
Esempio n. 8
0
    def test_raised_by_relation_resolves_to_raised(self):
        '''
        Tests when a relation that a child is raised by parent, it resolves to parent raised child
        '''
        parent = Person(name="parent", gender="F", family_id=self.family.id)
        parent.save()

        child = Person(name="child", gender="O", family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = child.id, to_person_id = parent.id, relation_type = RAISED_BY)
        relation.normalise()


        self.assertEqual(RAISED, relation.relation_type)
        self.assertEqual(parent.id, relation.from_person_id)
        self.assertEqual(child.id, relation.to_person_id)
Esempio n. 9
0
    def test_hierachy_score_set_for_adding_child(self):
        '''
        Ensure that hierachy score is set when adding the child of a parent
        the relation is not passed to the function
        '''

        parent = Person(name='parent', gender='M', hierarchy_score = 100, family_id=self.family.id)
        parent.save()

        child = Person(name='child', gender='M', family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = parent.id, to_person_id = child.id, relation_type = RAISED)
        relation.save()

        child.set_hierarchy_score()
        self.assertEqual(101, child.hierarchy_score)
Esempio n. 10
0
    def test_hierachy_score_set_for_adding_partner(self):
        '''
        Ensure that hierachy score is set when adding a partner
        '''

        husband = Person(name='husband', gender='M', family_id=self.family.id)
        husband.save()

        wife = Person(name='wife', gender='F', hierarchy_score = 75, family_id=self.family.id)
        wife.save()

        relation = Relation(from_person_id = husband.id, to_person_id = wife.id, relation_type = PARTNERED)
        relation.save()

        husband.set_hierarchy_score()

        self.assertEqual(75, husband.hierarchy_score)
Esempio n. 11
0
    def test_partnered_female_to_male_stays_the_same(self):
        '''
        Tests when a female partners a male, the relationship does not change
        '''

        female = Person(name="female", gender="F", family_id=self.family.id)
        female.save()

        male = Person(name="male", gender="M", family_id=self.family.id)
        male.save()

        relation = Relation(from_person_id = female.id, to_person_id = male.id, relation_type = PARTNERED)
        relation.normalise()

        self.assertEqual(female.id, relation.from_person_id)

        self.assertEqual(male.id, relation.to_person_id)
Esempio n. 12
0
    def test_raised_by_relation_resolves_to_raised(self):
        '''
        Tests when a relation that a child is raised by parent, it resolves to parent raised child
        '''
        parent = Person(name="parent", gender="F", family_id=self.family.id)
        parent.save()

        child = Person(name="child", gender="O", family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = child.id, to_person_id = parent.id, relation_type = RAISED_BY)
        relation.normalise()


        self.assertEqual(RAISED, relation.relation_type)
        self.assertEqual(parent.id, relation.from_person_id)
        self.assertEqual(child.id, relation.to_person_id)
Esempio n. 13
0
    def test_existing_relations_get_replaced(self):
        '''
        Tests that when a relations is added between two people, it replaces any existing relations between them
        '''
        existing1 = Person(name="existing1", gender="F", family_id=self.family.id)
        existing1.save()

        existing2 = Person(name="existing2", gender="F", family_id=self.family.id)
        existing2.save()

        relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = RAISED)
        relation.save()

        new_relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = PARTNERED)
        new_relation.save()

        self.assertEqual(1, Relation.objects.filter(from_person_id = existing1.id, to_person_id = existing2.id).count())
        self.assertEqual(PARTNERED, Relation.objects.get(from_person_id = existing1.id, to_person_id = existing2.id).relation_type)
Esempio n. 14
0
    def test_create_inverted_relation(self):
        '''
        Tests an inverted relationship is correctly created when using manager function
        '''
        from_person = Person(name="from_person", gender="F", family_id=self.family.id)
        from_person.save()

        to_person = Person(name="to_person", gender="F", family_id=self.family.id)
        to_person.save()

        relation = Relation(from_person_id = from_person.id, to_person_id = to_person.id, relation_type = RAISED)

        inverted = Relation.objects._create_inverted_relation(relation)

        self.assertEqual(from_person.id, inverted.to_person_id)
        self.assertEqual(to_person.id, inverted.from_person_id)
        self.assertEqual(RAISED_BY, inverted.relation_type)
Esempio n. 15
0
    def test_hierachy_score_set_for_adding_parent_with_relation_as_param(self):
        '''
        Ensure that hierachy score is set when adding the parent of a child
        the relation is passed to the function
        '''

        parent = Person(name='parent', gender='M', family_id=self.family.id)
        parent.save()

        child = Person(name='child', gender='M', hierarchy_score = 100, family_id=self.family.id)
        child.save()

        relation = Relation(from_person_id = parent.id, to_person_id = child.id, relation_type = RAISED)

        parent.set_hierarchy_score(relation)

        self.assertEqual(99, parent.hierarchy_score)
Esempio n. 16
0
    def test_existing_relations_get_replaced(self):
        '''
        Tests that when a relations is added between two people, it replaces any existing relations between them
        '''
        existing1 = Person(name="existing1", gender="F", family_id=self.family.id)
        existing1.save()

        existing2 = Person(name="existing2", gender="F", family_id=self.family.id)
        existing2.save()

        relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = RAISED)
        relation.save()

        new_relation = Relation(from_person_id = existing1.id, to_person_id = existing2.id, relation_type = PARTNERED)
        new_relation.save()

        self.assertEqual(1, Relation.objects.filter(from_person_id = existing1.id, to_person_id = existing2.id).count())
        self.assertEqual(PARTNERED, Relation.objects.get(from_person_id = existing1.id, to_person_id = existing2.id).relation_type)