def test_is_education_group_creation_period_opened(self): person = PersonFactory() education_group = EducationGroupYearFactory() today = datetime.date.today() current_ac = create_current_academic_year() closed_period = AcademicCalendarFactory( start_date=today + datetime.timedelta(days=1), end_date=today + datetime.timedelta(days=3), academic_year=current_ac, reference=academic_calendar_type.EDUCATION_GROUP_EDITION) next_ac = AcademicYearFactory(year=current_ac.year + 1) # The period is closed self.assertFalse( is_education_group_creation_period_opened(education_group)) opened_period = closed_period opened_period.start_date = today opened_period.save() # It is open the academic_year does not match self.assertFalse( is_education_group_creation_period_opened(education_group)) # It is open and the education_group is in N+1 academic_year education_group.academic_year = next_ac education_group.save() self.assertTrue( is_education_group_creation_period_opened(education_group, raise_exception=True))
class TestGroupElementYearProperty(TestCase): @classmethod def setUpTestData(cls): cls.academic_year = AcademicYearFactory() def setUp(self): self.egy = EducationGroupYearFactory(academic_year=self.academic_year, title="Title FR", credits=15) self.group_element_year = GroupElementYearFactory( parent__academic_year=self.academic_year, child_branch=self.egy, relative_credits=10) def test_verbose_credit(self): self.assertEqual( self.group_element_year.verbose, "{} ({} {})".format(self.group_element_year.child.title, self.group_element_year.relative_credits, _("credits"))) self.group_element_year.relative_credits = None self.group_element_year.save() self.assertEqual( self.group_element_year.verbose, "{} ({} {})".format(self.group_element_year.child.title, self.group_element_year.child_branch.credits, _("credits"))) self.egy.credits = None self.egy.save() self.assertEqual(self.group_element_year.verbose, "{}".format(self.group_element_year.child.title))
def test_case_one_egy_one_parent_no_entity_on_child(self): education_group_year_child = EducationGroupYearFactory() education_group_year_parent = EducationGroupYearFactory() GroupElementYearFactory(parent=education_group_year_parent, child_branch=education_group_year_child) education_group_year_child.management_entity = None education_group_year_child.save() self.assertEquals( get_education_group_year_eligible_management_entities( education_group_year_child), [education_group_year_parent.management_entity])
def test_case_one_egy_two_parent_no_entity_on_child(self): education_group_year_child = EducationGroupYearFactory( academic_year=self.academic_year) education_group_year_parent1 = EducationGroupYearFactory( academic_year=self.academic_year) GroupElementYearFactory(parent=education_group_year_parent1, child_branch=education_group_year_child) education_group_year_parent2 = EducationGroupYearFactory( academic_year=self.academic_year) GroupElementYearFactory(parent=education_group_year_parent2, child_branch=education_group_year_child) education_group_year_child.management_entity = None education_group_year_child.save() self.assertCountEqual( get_education_group_year_eligible_management_entities( education_group_year_child), [ education_group_year_parent1.management_entity, education_group_year_parent2.management_entity, ])
def test_case_complex_hierarchy(self): education_group_year_child = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_child.management_entity, acronym="CHILD") education_group_year_parent1 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent1.management_entity, acronym="PARENT1") GroupElementYearFactory(parent=education_group_year_parent1, child_branch=education_group_year_child) education_group_year_parent2 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent2.management_entity, acronym="PARENT2") GroupElementYearFactory(parent=education_group_year_parent2, child_branch=education_group_year_child) education_group_year_parent3 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent3.management_entity, acronym="PARENT3") GroupElementYearFactory(parent=education_group_year_parent3, child_branch=education_group_year_parent1) education_group_year_parent4 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent4.management_entity, acronym="PARENT4") GroupElementYearFactory(parent=education_group_year_parent4, child_branch=education_group_year_parent1) education_group_year_parent5 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent5.management_entity, acronym="PARENT5") GroupElementYearFactory(parent=education_group_year_parent5, child_branch=education_group_year_child) GroupElementYearFactory(parent=education_group_year_parent5, child_branch=education_group_year_parent2) education_group_year_parent6 = EducationGroupYearFactory() EntityVersionFactory( entity=education_group_year_parent6.management_entity, acronym="PARENT6") GroupElementYearFactory(parent=education_group_year_parent6, child_branch=education_group_year_parent5) education_group_year_child.management_entity = None education_group_year_child.save() education_group_year_parent1.management_entity = None education_group_year_parent1.save() education_group_year_parent5.management_entity = None education_group_year_parent5.save() self.assertCountEqual( get_education_group_year_eligible_management_entities( education_group_year_child), [ education_group_year_parent2.management_entity, education_group_year_parent3.management_entity, education_group_year_parent4.management_entity, education_group_year_parent6.management_entity, ])
class TestContent(TestCase): def setUp(self): self.current_academic_year = create_current_academic_year() self.person = PersonFactory() self.education_group_year_1 = EducationGroupYearFactory() self.education_group_year_2 = EducationGroupYearFactory() self.education_group_year_3 = EducationGroupYearFactory() self.learning_unit_year_1 = LearningUnitYearFactory() self.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) self.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, hourly_volume_partial_q1=10, hourly_volume_partial_q2=10) self.learning_unit_component_1 = LearningUnitComponentFactory( learning_component_year=self.learning_component_year_1, learning_unit_year=self.learning_unit_year_1) self.learning_unit_component_2 = LearningUnitComponentFactory( learning_component_year=self.learning_component_year_2, learning_unit_year=self.learning_unit_year_1) self.learning_unit_year_without_container = LearningUnitYearFactory( learning_container_year=None) self.group_element_year_1 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_2) self.group_element_year_2 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=None, child_leaf=self.learning_unit_year_1) self.group_element_year_3 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_3) self.group_element_year_without_container = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=None, child_leaf=self.learning_unit_year_without_container) self.user = UserFactory() self.person = PersonFactory(user=self.user) self.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) self.url = reverse("education_group_content", args=[ self.education_group_year_1.id, self.education_group_year_1.id, ]) self.client.force_login(self.user) def test_context(self): response = self.client.get(self.url) self.assertTemplateUsed(response, "education_group/tab_content.html") geys = response.context["group_element_years"] self.assertIn(self.group_element_year_1, geys) self.assertIn(self.group_element_year_2, geys) self.assertIn(self.group_element_year_3, geys) self.assertNotIn(self.group_element_year_without_container, geys) def test_show_minor_major_option_table_case_right_type(self): minor_major_option_types = [ GroupType.MINOR_LIST_CHOICE.name, GroupType.MAJOR_LIST_CHOICE.name, GroupType.OPTION_LIST_CHOICE.name, ] for group_type_name in minor_major_option_types: education_group_type = GroupEducationGroupTypeFactory( name=group_type_name) self.education_group_year_1.education_group_type = education_group_type self.education_group_year_1.save() response = self.client.get(self.url) self.assertTrue(response.context["show_minor_major_option_table"]) def test_show_minor_major_option_table_case_not_right_type(self): self.education_group_year_1.education_group_type = MiniTrainingEducationGroupTypeFactory( ) self.education_group_year_1.save() response = self.client.get(self.url) self.assertFalse(response.context["show_minor_major_option_table"])