def test_ancestors_descendants(self):
        create_subjecttypes()
        create_subjects()

        klaus = DBSession.query(Subject).filter_by(name="Klaus").first()
        clara = DBSession.query(Subject).filter_by(name="Clara").first()
        liam = DBSession.query(Subject).filter_by(name="Liam").first()

        bielefeld = DBSession.query(Subject).filter_by(
            name="Bielefeld").first()
        paderborn = DBSession.query(Subject).filter_by(
            name="Paderborn").first()
        germany = DBSession.query(Subject).filter_by(name="Germany").first()
        france = DBSession.query(Subject).filter_by(name="France").first()

        dev_team_bielefeld = DBSession.query(Subject).filter_by(
            name="Developer Team Bielefeld").first()
        junior_developer = DBSession.query(Subject).filter_by(
            name="Junior Developer").first()

        user_type = DBSession.query(SubjectType).filter_by(name="User").first()
        team_type = DBSession.query(SubjectType).filter_by(name="Team").first()
        country_type = DBSession.query(SubjectType).filter_by(
            name="Country").first()

        klaus_ancestors = Subject.get_ancestor_subjects(
            subject_id=klaus.id,
            of_type_id=None,
            from_date=default_dt(),
            to_date=default_dt(),
            whole_time_required=False)

        self.assertIn(bielefeld.id, klaus_ancestors.keys())
        self.assertIn(germany.id, klaus_ancestors.keys())
        self.assertIn(dev_team_bielefeld.id, klaus_ancestors.keys())
        self.assertIn(junior_developer.id, klaus_ancestors.keys())
        self.assertNotIn(france.id, klaus_ancestors.keys())

        germany_descendants = Subject.get_descendent_subjects(
            subject_id=germany.id,
            of_type_id=team_type.id,
            from_date=default_dt(),
            to_date=default_dt(),
            whole_time_required=False)

        self.assertIn(dev_team_bielefeld.id, germany_descendants.keys())
        self.assertNotIn(klaus.id, germany_descendants.keys())
Ejemplo n.º 2
0
    def forward(cls, subjecttype_id, context_subject_id, from_date, to_date, whole_time_required=False):
        # We are comparing all subjects of type subject_type which have been part of context_subject_id between from_date and to_date
        # By default, they don't have to be member all the time (whole_time_required).

        #print("Looking for descendents of %s of type %s" % (context_subject_id, subjecttype_id))
        #print("From Date: %s, To Date: %s, whole_time_required: %s" % (from_date, to_date, whole_time_required))

        ancestor_subjects = Subject.get_descendent_subjects(
            subject_id=context_subject_id,
            of_type_id=subjecttype_id,
            from_date=from_date if from_date else dt_now(),
            to_date=to_date if to_date else dt_now(),
            whole_time_required=whole_time_required
        )

        subjects = [x for x in ancestor_subjects.keys()]

        return subjects