示例#1
0
class EducationGroupYearTest(TestCase):
    def setUp(self):  # No setUpTestData here, tests cannot be interrelated
        self.academic_year = AcademicYearFactory()
        self.education_group_type_training = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        self.education_group_type_minitraining = EducationGroupTypeFactory(
            category=education_group_categories.MINI_TRAINING)

        self.education_group_type_group = EducationGroupTypeFactory(
            category=education_group_categories.GROUP)

        self.education_group_type_finality = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING,
            name=education_group_types.TrainingType.MASTER_MD_120.name)

        self.education_group_year_1 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)
        self.education_group_year_2 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_minitraining)
        self.education_group_year_3 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)
        self.education_group_year_4 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_group)
        self.education_group_year_5 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_group)
        self.education_group_year_6 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)
        self.education_group_year_MD = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_finality,
            title="Complete title",
            partial_title="Partial title",
            title_english="Complete title in English",
            partial_title_english="Partial title in English")
        self.education_group_year_MD_no_partial_title = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_finality,
            partial_title="",
            partial_title_english="",
        )

        self.educ_group_year_domain = EducationGroupYearDomainFactory(
            education_group_year=self.education_group_year_2)

        self.entity_version_admin = EntityVersionFactory(
            entity=self.education_group_year_2.administration_entity,
            start_date=self.education_group_year_2.academic_year.start_date,
            parent=None)

        self.offer_year_3 = OfferYearFactory(academic_year=self.academic_year)

        self.entity_version_management = EntityVersionFactory(
            entity=self.education_group_year_3.management_entity,
            start_date=self.education_group_year_3.academic_year.start_date,
            parent=None)

        self.group_element_year_4 = GroupElementYearFactory(
            parent=self.education_group_year_3,
            child_branch=self.education_group_year_1)
        self.group_element_year_5 = GroupElementYearFactory(
            parent=self.education_group_year_6,
            child_branch=self.education_group_year_1)

    def test_verbose_type(self):
        type_of_egt = self.education_group_year_1.education_group_type.get_name_display(
        )
        self.assertEqual(type_of_egt, self.education_group_year_1.verbose_type)

    def test_verbose_credit(self):
        verbose__waiting = "{} ({} {})".format(
            self.education_group_year_1.title,
            self.education_group_year_1.credits, _("credits"))
        self.assertEqual(self.education_group_year_1.verbose_credit,
                         verbose__waiting)

    def test_search(self):
        result = search(id=[
            self.education_group_year_1.id, self.education_group_year_2.id
        ])
        self.assertEqual(len(result), 2)

        result = search(education_group_type=self.education_group_year_2.
                        education_group_type)
        self.assertEqual(result.first().education_group_type,
                         self.education_group_year_2.education_group_type)

        result = search(education_group_type=[
            self.education_group_type_training,
            self.education_group_type_minitraining
        ])
        self.assertEqual(len(result), 4)

        OfferEnrollmentFactory(
            education_group_year=self.education_group_year_2,
            enrollment_state=offer_enrollment_state.SUBSCRIBED)
        OfferEnrollmentFactory(
            education_group_year=self.education_group_year_2,
            enrollment_state=offer_enrollment_state.PENDING)
        result = search(enrollment_states=[offer_enrollment_state.SUBSCRIBED])
        self.assertEqual(len(result), 1)

    def test_domains_property(self):
        domains = self.education_group_year_1.str_domains
        self.assertEqual(domains, '')

        domains = self.education_group_year_2.str_domains
        offer_year_domain = "{}-{}\n".format(
            self.educ_group_year_domain.domain.decree,
            self.educ_group_year_domain.domain.name)
        self.assertEqual(domains, offer_year_domain)

    def test_administration_entity_version_property(self):
        self.assertEqual(
            self.education_group_year_2.administration_entity_version,
            self.entity_version_admin)

    def test_management_entity_version_property(self):
        self.assertEqual(self.education_group_year_3.management_entity_version,
                         self.entity_version_management)

    def test_parent_by_training(self):
        parent_by_training = self.education_group_year_3.is_training()
        self.assertTrue(parent_by_training)

        parent_by_training = self.education_group_year_2.parent_by_training()
        self.assertIsNone(parent_by_training)

        with self.assertRaises(MaximumOneParentAllowedException):
            self.education_group_year_1.parent_by_training()

        group = GroupFactory(academic_year=self.academic_year)
        GroupElementYearFactory(child_branch=group,
                                parent=self.education_group_year_2)
        self.assertIsNone(group.parent_by_training())

    def test_direct_parents_of_branch(self):
        GroupElementYearFactory(parent=self.education_group_year_2,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_4,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_4)

        self.assertCountEqual(
            self.education_group_year_1.direct_parents_of_branch, [
                self.education_group_year_2, self.education_group_year_3,
                self.education_group_year_4, self.education_group_year_6
            ])

    def test_ascendants_of_branch(self):
        GroupElementYearFactory(parent=self.education_group_year_2,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_4,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_4)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_1)

        self.assertCountEqual(self.education_group_year_1.ascendants_of_branch,
                              [
                                  self.education_group_year_2,
                                  self.education_group_year_3,
                                  self.education_group_year_4,
                                  self.education_group_year_5,
                                  self.education_group_year_6,
                              ])

    def test_is_mini_training(self):
        self.assertFalse(self.education_group_year_1.is_mini_training())
        self.assertTrue(self.education_group_year_2.is_mini_training())
        self.assertFalse(self.education_group_year_3.is_mini_training())
        self.assertFalse(self.education_group_year_4.is_mini_training())
        self.assertFalse(self.education_group_year_5.is_mini_training())
        self.assertFalse(self.education_group_year_6.is_mini_training())

    @override_settings(LANGUAGES=[
        ('fr-be', 'French'),
    ],
                       LANGUAGE_CODE='fr-be')
    def test_verbose_title_fr(self):
        self.assertEqual(self.education_group_year_MD.verbose_title,
                         self.education_group_year_MD.partial_title)
        self.assertEqual(self.education_group_year_1.verbose_title,
                         self.education_group_year_1.title)

    @override_settings(LANGUAGES=[
        ('en', 'English'),
    ], LANGUAGE_CODE='en')
    def test_verbose_title_en(self):
        self.assertEqual(self.education_group_year_MD.verbose_title,
                         self.education_group_year_MD.partial_title_english)
        self.assertEqual(
            self.education_group_year_1.verbose_title,
            self.education_group_year_1.title_english
            or self.education_group_year_1.title)

    @override_settings(LANGUAGES=[
        ('fr-be', 'French'),
    ],
                       LANGUAGE_CODE='fr-be')
    def test_verbose_title_fr_partial_title_empty(self):
        self.assertEqual(
            self.education_group_year_MD_no_partial_title.verbose_title, "")

    @override_settings(LANGUAGES=[
        ('en', 'English'),
    ], LANGUAGE_CODE='en')
    def test_verbose_title_en_partial_title_empty(self):
        self.assertEqual(
            self.education_group_year_MD_no_partial_title.verbose_title, "")
示例#2
0
class EducationGroupYearTest(TestCase):
    def setUp(self):
        self.academic_year = AcademicYearFactory()
        self.education_group_type_training = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        self.education_group_type_minitraining = EducationGroupTypeFactory(
            category=education_group_categories.MINI_TRAINING)

        self.education_group_type_group = EducationGroupTypeFactory(
            category=education_group_categories.GROUP)

        self.education_group_year_1 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)
        self.education_group_year_2 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_minitraining)

        self.education_group_year_3 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)
        self.education_group_year_4 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_group)
        self.education_group_year_5 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_group)
        self.education_group_year_6 = EducationGroupYearFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type_training)

        self.educ_group_year_domain = EducationGroupYearDomainFactory(
            education_group_year=self.education_group_year_2)

        self.entity_version_admin = EntityVersionFactory(
            entity=self.education_group_year_2.administration_entity,
            start_date=self.education_group_year_2.academic_year.start_date,
            parent=None)

        self.offer_year_3 = OfferYearFactory(academic_year=self.academic_year)

        self.entity_version_management = EntityVersionFactory(
            entity=self.education_group_year_3.management_entity,
            start_date=self.education_group_year_3.academic_year.start_date,
            parent=None)

        self.group_element_year_4 = GroupElementYearFactory(
            parent=self.education_group_year_3,
            child_branch=self.education_group_year_1)
        self.group_element_year_5 = GroupElementYearFactory(
            parent=self.education_group_year_6,
            child_branch=self.education_group_year_1)

    def test_verbose_type(self):
        type_of_egt = self.education_group_year_1.education_group_type.get_name_display(
        )
        self.assertEqual(type_of_egt, self.education_group_year_1.verbose_type)

    def test_verbose_credit(self):
        verbose__waiting = "{} ({} {})".format(
            self.education_group_year_1.title,
            self.education_group_year_1.credits, _("credits"))
        self.assertEqual(self.education_group_year_1.verbose_credit,
                         verbose__waiting)

    def test_search(self):
        result = search(id=[
            self.education_group_year_1.id, self.education_group_year_2.id
        ])
        self.assertEqual(len(result), 2)

        result = search(education_group_type=self.education_group_year_2.
                        education_group_type)
        self.assertEqual(result.first().education_group_type,
                         self.education_group_year_2.education_group_type)

        result = search(education_group_type=[
            self.education_group_type_training,
            self.education_group_type_minitraining
        ])
        self.assertEqual(len(result), 4)

    def test_domains_property(self):
        domains = self.education_group_year_1.str_domains
        self.assertEqual(domains, '')

        domains = self.education_group_year_2.str_domains
        offer_year_domain = "{}-{}\n".format(
            self.educ_group_year_domain.domain.decree,
            self.educ_group_year_domain.domain.name)
        self.assertEqual(domains, offer_year_domain)

    def test_administration_entity_version_property(self):
        self.assertEqual(
            self.education_group_year_2.administration_entity_version,
            self.entity_version_admin)

    def test_management_entity_version_property(self):
        self.assertEqual(self.education_group_year_3.management_entity_version,
                         self.entity_version_management)

    def test_parent_by_training(self):
        parent_by_training = self.education_group_year_3.is_training()
        self.assertTrue(parent_by_training)

        parent_by_training = self.education_group_year_2.parent_by_training()
        self.assertIsNone(parent_by_training)

        with self.assertRaises(MaximumOneParentAllowedException):
            self.education_group_year_1.parent_by_training()

        group = GroupFactory(academic_year=self.academic_year)
        GroupElementYearFactory(child_branch=group,
                                parent=self.education_group_year_2)
        self.assertIsNone(group.parent_by_training())

    def test_children_group_element_years_property(self):
        children_group_element_years = self.education_group_year_1.children_group_element_years
        self.assertListEqual(list(children_group_element_years), [])

    def test_direct_parents_of_branch(self):
        GroupElementYearFactory(parent=self.education_group_year_2,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_4,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_4)

        self.assertCountEqual(
            self.education_group_year_1.direct_parents_of_branch, [
                self.education_group_year_2, self.education_group_year_3,
                self.education_group_year_4, self.education_group_year_6
            ])

    def test_ascendants_of_branch(self):
        GroupElementYearFactory(parent=self.education_group_year_2,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_4,
                                child_branch=self.education_group_year_1)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_4)
        GroupElementYearFactory(parent=self.education_group_year_5,
                                child_branch=self.education_group_year_1)

        self.assertCountEqual(self.education_group_year_1.ascendants_of_branch,
                              [
                                  self.education_group_year_2,
                                  self.education_group_year_3,
                                  self.education_group_year_4,
                                  self.education_group_year_5,
                                  self.education_group_year_6,
                              ])

    def test_is_mini_training(self):
        self.assertFalse(self.education_group_year_1.is_mini_training())
        self.assertTrue(self.education_group_year_2.is_mini_training())
        self.assertFalse(self.education_group_year_3.is_mini_training())
        self.assertFalse(self.education_group_year_4.is_mini_training())
        self.assertFalse(self.education_group_year_5.is_mini_training())
        self.assertFalse(self.education_group_year_6.is_mini_training())