def test_postpone_with_terminated_child_branches(self): sub_group = GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch__academic_year=self.current_academic_year, child_branch__education_group__end_year=self.current_academic_year, ) self.postponer = PostponeContent(self.current_education_group_year) self.postponer.postpone() self.assertTrue(self.postponer.warnings) self.assertEqual( _("%(education_group_year)s is closed in %(end_year)s. This element will not be copied " "in %(academic_year)s.") % { "education_group_year": "{} - {}".format(sub_group.child_branch.partial_acronym, sub_group.child_branch.acronym), "end_year": sub_group.child_branch.education_group.end_year, "academic_year": self.next_academic_year, }, str(self.postponer.warnings[0]))
def test_should_reuse_past_partial_acronym(self): previous_academic_year = AcademicYearFactory( year=self.egy.academic_year.year - 1) previous_egy = EducationGroupYearFactory( education_group_type=self.master_type, acronym="TEST2M", partial_acronym="LTEST100B", academic_year=previous_academic_year, education_group=self.egy.education_group, ) previous_child = EducationGroupYearFactory( education_group_type=self.finality_type, partial_acronym="LTEST503G", academic_year=previous_academic_year, ) previous_grp_ele = GroupElementYearFactory(parent=previous_egy, child_branch=previous_child) children_egys = create_initial_group_element_year_structure([self.egy]) self.assertEqual( previous_child.partial_acronym, children_egys[self.egy.id][0].child_branch.partial_acronym)
def setUpTestData(cls): cls.academic_year = AcademicYearFactory(year=get_current_year() + 1) cls.education_group_year = EducationGroupYearFactory(academic_year=cls.academic_year, education_group__end_year=cls.academic_year.year + 2) cls.education_group_year_child = EducationGroupYearFactory(academic_year=cls.academic_year, education_group__end_year=cls.academic_year.year + 2) cls.group_element_year = GroupElementYearFactory(parent=cls.education_group_year, child_branch=cls.education_group_year_child) AuthorizedRelationshipFactory( parent_type=cls.education_group_year.education_group_type, child_type=cls.group_element_year.child_branch.education_group_type, ) cls.person = CentralManagerFactory() cls.url = reverse( "group_element_year_update", kwargs={ "root_id": cls.education_group_year.id, "education_group_year_id": cls.education_group_year.id, "group_element_year_id": cls.group_element_year.id } ) cls.post_valid_data = {'action': 'edit'}
def test_is_case_attach_finality_which_child_branch_duplicate(self): master_120_didactic = TrainingFactory( education_group_type__name=TrainingType.MASTER_MD_120.name, academic_year=self.academic_year_2018, education_group__end_year=self.academic_year_2019 ) ge = GroupElementYearFactory(parent=self.finality_group, child_branch=master_120_didactic) duplicate = AttachEducationGroupYearStrategy( parent=self.finality_group, child=master_120_didactic ) with self.assertRaises(ValidationError): self.assertTrue(duplicate.is_valid()) update = AttachEducationGroupYearStrategy( parent=self.finality_group, child=master_120_didactic, instance=ge ) self.assertTrue(update.is_valid())
def test_post_invalid_when_max_limit_reached(self): GroupElementYearFactory( parent=self.parent_education_group_year, child_branch__academic_year=self.academic_year, child_branch__education_group_type=self.education_group_types[0]) expected_error_msg = _( "The number of children of type \"%(child_type)s\" for \"%(parent)s\" " "has already reached the limit.") % { 'child_type': self.education_group_types[0], 'parent': self.parent_education_group_year } response = self.client.post( reverse("select_education_group_type", args=[ self.test_categories[0], self.parent_education_group_year.pk, self.parent_education_group_year.pk ]), data={"name": self.education_group_types[0].pk}) self.assertEqual(response.status_code, HttpResponse.status_code) self.assertDictEqual(response.context["form"].errors, {"name": [expected_error_msg]})
def test_delete_case_remove_mandatory_structure(self): education_group_year = TrainingFactory( academic_year=self.academic_year) child_mandatory = GroupFactory( academic_year=self.academic_year, education_group_type__name=GroupType.COMMON_CORE.name) AuthorizedRelationshipFactory( parent_type=education_group_year.education_group_type, child_type=child_mandatory.education_group_type, min_count_authorized=1, ) link_parent_child = GroupElementYearFactory( parent=education_group_year, child_branch=child_mandatory) delete.start(education_group_year) with self.assertRaises(EducationGroupYear.DoesNotExist): EducationGroupYear.objects.get(pk=education_group_year.pk) with self.assertRaises(EducationGroupYear.DoesNotExist): EducationGroupYear.objects.get(pk=child_mandatory.pk) with self.assertRaises(GroupElementYear.DoesNotExist): GroupElementYear.objects.get(pk=link_parent_child.pk)
def test_when_prerequisite_item_does_not_exist_in_formation(self): prerequisite = PrerequisiteFactory( learning_unit_year__academic_year=self.current_academic_year, education_group_year=self.current_education_group_year) item_luy = LearningUnitYearFactory( academic_year=self.current_academic_year) PrerequisiteItemFactory(prerequisite=prerequisite, learning_unit=item_luy.learning_unit) LearningUnitYearFactory( learning_unit=prerequisite.learning_unit_year.learning_unit, academic_year=self.next_academic_year, ) GroupElementYearFactory(parent=self.current_education_group_year, child_branch=None, child_leaf=prerequisite.learning_unit_year) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual( _("%(prerequisite_item)s is not anymore contained in " "%(education_group_year_root)s " "=> the prerequisite for %(learning_unit_year)s " "having %(prerequisite_item)s as prerequisite is not copied.") % { "education_group_year_root": "{} - {}".format(new_root.partial_acronym, new_root.acronym), "learning_unit_year": prerequisite.learning_unit_year.acronym, "prerequisite_item": item_luy.acronym }, str(self.postponer.warnings[0]), )
def setUp(self): self.next_academic_year = AcademicYearFactory(current=True) self.group_element_year = GroupElementYearFactory( parent__academic_year=self.next_academic_year) self.selected_egy = EducationGroupYearFactory( academic_year=self.next_academic_year) self.url = reverse("education_group_attach", args=[ self.group_element_year.parent.id, self.group_element_year.child_branch.id ]) self.person = PersonFactory() self.client.force_login(self.person.user) self.perm_patcher = mock.patch( "base.business.education_groups.perms.is_eligible_to_change_education_group", return_value=True) self.mocked_perm = self.perm_patcher.start() self.addCleanup(self.mocked_perm.stop) self.addCleanup(cache.clear)
def setUpTestData(cls): cls.academic_year = AcademicYearFactory() cls.education_group_year_parents = [ TrainingFactory(academic_year=cls.academic_year) for _ in range(0, 2) ] cls.learning_unit_year_child = LearningUnitYearFakerFactory( learning_container_year__academic_year=cls.academic_year) cls.group_element_years = [ GroupElementYearFactory(parent=cls.education_group_year_parents[i], child_leaf=cls.learning_unit_year_child, child_branch=None) for i in range(0, 2) ] cls.prerequisite = PrerequisiteFactory( learning_unit_year=cls.learning_unit_year_child, education_group_year=cls.education_group_year_parents[0]) cls.person = PersonWithPermissionsFactory("can_access_education_group") cls.url = reverse("learning_unit_prerequisite", args=[ cls.education_group_year_parents[0].id, cls.learning_unit_year_child.id ])
def test_update_with_parent_when_existing_group_element_year( self, mock_find_authorized_types): parent = EducationGroupYearFactory( academic_year=self.expected_educ_group_year.academic_year) entity_version = MainEntityVersionFactory() initial_educ_group_year = EducationGroupYearFactory( management_entity=entity_version.entity, academic_year=self.expected_educ_group_year.academic_year) GroupElementYearFactory(parent=parent, child_branch=initial_educ_group_year) initial_count = GroupElementYear.objects.all().count() form = self.form_class(data=self.post_data, instance=initial_educ_group_year, parent=parent) self.assertTrue(form.is_valid(), form.errors) updated_education_group_year = form.save() # Assert existing GroupElementYear is reused. self.assertEqual(initial_count, GroupElementYear.objects.all().count()) self._assert_all_fields_correctly_saved(updated_education_group_year) self.assertTrue(form.forms[ModelForm].fields["academic_year"].disabled)
def test_clean_link_type_reference_between_eg_without_authorized_relationship( self): AuthorizedRelationshipFactory( parent_type=self.parent.education_group_type, child_type=self.child_branch.education_group_type, ) ref_group = GroupElementYearFactory( parent=self.child_branch, child_branch=EducationGroupYearFactory( academic_year=self.academic_year)) form = GroupElementYearForm( data={'link_type': LinkTypes.REFERENCE.name}, parent=self.parent, child_branch=self.child_branch) self.assertFalse(form.is_valid()) self.assertEqual(form.errors["link_type"], [ _("You cannot attach \"%(child_types)s\" to \"%(parent)s\" (type \"%(parent_type)s\")" ) % { "parent_type": self.parent.education_group_type, "parent": self.parent, "child_types": ref_group.child_branch.education_group_type, } ])
def test_raise_permission_denied_when_minor_or_major_list_choice_and_person_is_faculty_manager( self): OpenAcademicCalendarFactory(reference=EDUCATION_GROUP_EDITION, academic_year=self.previous_acy) egys = [ GroupFactory( education_group_type__name=GroupType.MINOR_LIST_CHOICE.name, academic_year=self.current_acy), GroupFactory( education_group_type__name=GroupType.MAJOR_LIST_CHOICE.name, academic_year=self.current_acy) ] person_entity = PersonEntityFactory( entity=self.group_element_year.parent.management_entity, person=FacultyManagerFactory()) for egy in egys: with self.subTest(type=egy.education_group_type): with self.assertRaises(PermissionDenied): group_element_year = GroupElementYearFactory( parent=self.group_element_year.parent, child_branch=egy) can_update_group_element_year(person_entity.person.user, group_element_year)
def setUpTestData(cls): cls.academic_year = AcademicYearFactory(year=2020) cls.education_group_year_parents = [ TrainingFactory(academic_year=cls.academic_year) for _ in range(0, 2) ] cls.learning_unit_year_child = LearningUnitYearFakerFactory( learning_container_year__academic_year=cls.academic_year) cls.group_element_years = [ GroupElementYearFactory(parent=cls.education_group_year_parents[i], child_leaf=cls.learning_unit_year_child, child_branch=None) for i in range(0, 2) ] cls.person = CentralManagerFactory("change_educationgroup", 'can_access_education_group') PersonEntityFactory( person=cls.person, entity=cls.education_group_year_parents[0].management_entity) cls.url = reverse("learning_unit_prerequisite_update", args=[ cls.education_group_year_parents[0].id, cls.learning_unit_year_child.id ])
def setUpTestData(cls): cls.current_acy, cls.previous_acy = AcademicYearFactory.produce_in_past( quantity=2) cls.group_element_year = GroupElementYearFactory( parent=TrainingFactory(academic_year=cls.current_acy), child_branch=MiniTrainingFactory(academic_year=cls.current_acy))
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)
class TestBuildTree(TestCase): def setUp(self): self.academic_year = AcademicYearFactory() self.parent = EducationGroupYearFactory(academic_year=self.academic_year) self.group_element_year_1 = GroupElementYearFactory( parent=self.parent, child_branch=EducationGroupYearFactory(academic_year=self.academic_year) ) self.group_element_year_1_1 = GroupElementYearFactory( parent=self.group_element_year_1.child_branch, child_branch=EducationGroupYearFactory(academic_year=self.academic_year) ) self.group_element_year_2 = GroupElementYearFactory( parent=self.parent, child_branch=EducationGroupYearFactory(academic_year=self.academic_year) ) self.learning_unit_year_1 = LearningUnitYearFactory() self.group_element_year_2_1 = GroupElementYearFactory( parent=self.group_element_year_2.child_branch, child_branch=None, child_leaf=self.learning_unit_year_1 ) def test_init_tree(self): node = EducationGroupHierarchy(self.parent) self.assertEqual(node.education_group_year, self.parent) self.assertEqual(len(node.children), 2) self.assertEqual(node.children[0].group_element_year, self.group_element_year_1) self.assertEqual(node.children[1].group_element_year, self.group_element_year_2) self.assertEqual(node.children[0].children[0].group_element_year, self.group_element_year_1_1) self.assertEqual(node.children[1].children[0].group_element_year, self.group_element_year_2_1) self.assertEqual(node.children[0].children[0].education_group_year, self.group_element_year_1_1.child_branch) self.assertEqual(node.children[1].children[0].education_group_year, None) self.assertEqual(node.children[1].children[0].learning_unit_year, self.group_element_year_2_1.child_leaf) def test_tree_to_json(self): node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEqual(json['text'], self.parent.verbose) self.assertEqual(json['a_attr']['href'], reverse('education_group_read', args=[ self.parent.pk, self.parent.pk]) + "?group_to_parent=0") self.assertEqual( json['children'][1]['children'][0]['a_attr']['href'], reverse( 'learning_unit_utilization', args=[self.parent.pk, self.group_element_year_2_1.child_leaf.pk] ) + "?group_to_parent={}".format(self.group_element_year_2_1.pk) ) def test_tree_get_url(self): test_cases = [ {'name': 'with tab', 'node': EducationGroupHierarchy(self.parent, tab_to_show='show_identification'), 'correct_url': reverse('education_group_read', args=[self.parent.pk, self.parent.pk]) + "?group_to_parent=0&tab_to_show=show_identification"}, {'name': 'without tab', 'node': EducationGroupHierarchy(self.parent), 'correct_url': reverse('education_group_read', args=[self.parent.pk, self.parent.pk]) + "?group_to_parent=0"}, {'name': 'with wrong tab', 'node': EducationGroupHierarchy(self.parent, tab_to_show='not_existing'), 'correct_url': reverse('education_group_read', args=[self.parent.pk, self.parent.pk]) + "?group_to_parent=0"}, ] for case in test_cases: with self.subTest(type=case['name']): self.assertEqual(case['correct_url'], case['node'].get_url()) def test_tree_luy_has_prerequisite(self): # self.learning_unit_year_1 has prerequisite PrerequisiteItemFactory( prerequisite=PrerequisiteFactory( learning_unit_year=self.learning_unit_year_1, education_group_year=self.parent ) ) node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEqual( json['children'][1]['children'][0]['a_attr']['title'], "{}\n{}".format(self.learning_unit_year_1.complete_title, _("The learning unit has prerequisites")) ) self.assertEqual( json['children'][1]['children'][0]['icon'], 'fa fa-arrow-left' ) def test_tree_luy_is_prerequisite(self): # self.learning_unit_year_1 is prerequisite PrerequisiteItemFactory( learning_unit=self.learning_unit_year_1.learning_unit, prerequisite=PrerequisiteFactory(education_group_year=self.parent) ) node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEqual( json['children'][1]['children'][0]['a_attr']['title'], "{}\n{}".format(self.learning_unit_year_1.complete_title, _("The learning unit is a prerequisite")) ) self.assertEqual( json['children'][1]['children'][0]['icon'], 'fa fa-arrow-right' ) def test_tree_luy_has_and_is_prerequisite(self): # self.learning_unit_year_1 is prerequisite PrerequisiteItemFactory( learning_unit=self.learning_unit_year_1.learning_unit, prerequisite=PrerequisiteFactory(education_group_year=self.parent) ) # self.learning_unit_year_1 has prerequisite PrerequisiteItemFactory( prerequisite=PrerequisiteFactory( learning_unit_year=self.learning_unit_year_1, education_group_year=self.parent ) ) node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEqual( json['children'][1]['children'][0]['a_attr']['title'], "{}\n{}".format( self.learning_unit_year_1.complete_title, _("The learning unit has prerequisites and is a prerequisite") ) ) self.assertEqual( json['children'][1]['children'][0]['icon'], 'fa fa-exchange-alt' ) def test_tree_to_json_a_attr(self): """In this test, we ensure that a attr contains some url for tree contextual menu""" node = EducationGroupHierarchy(self.parent) json = node.to_json() child = self.group_element_year_1.child_branch expected_modify_url = reverse('group_element_year_update', args=[ self.parent.pk, child.pk, self.group_element_year_1.pk ]) self.assertEqual(json['children'][0]['a_attr']['modify_url'], expected_modify_url) expected_attach_url = reverse('education_group_attach', args=[self.parent.pk, child.pk]) self.assertEqual(json['children'][0]['a_attr']['attach_url'], expected_attach_url) expected_detach_url = reverse('group_element_year_delete', args=[ self.parent.pk, child.pk, self.group_element_year_1.pk ]) self.assertEqual(json['children'][0]['a_attr']['detach_url'], expected_detach_url) def test_build_tree_reference(self): """ This tree contains a reference link. """ self.group_element_year_1.link_type = LinkTypes.REFERENCE.name self.group_element_year_1.save() node = EducationGroupHierarchy(self.parent) self.assertEqual(node.children[0]._get_icon(), static('img/reference.jpg')) list_children = node.to_list() self.assertEqual(list_children, [ self.group_element_year_1_1, self.group_element_year_2, [self.group_element_year_2_1] ]) def test_node_to_list_flat(self): node = EducationGroupHierarchy(self.parent) list_children = node.to_list(flat=True) self.assertCountEqual(list_children, [ self.group_element_year_1, self.group_element_year_1_1, self.group_element_year_2, self.group_element_year_2_1 ]) def test_node_to_list_with_pruning_function(self): """ This test ensure that if the parameter pruning function is specified we only get the tree without node which has been pruned """ node = EducationGroupHierarchy(self.parent) list_children = node.to_list( flat=True, pruning_function=lambda child: child.group_element_year.pk == self.group_element_year_2.pk ) self.assertCountEqual(list_children, [self.group_element_year_2])
def test_when_options_in_finalities_are_not_consistent(self): root_grp = GroupElementYearFactory( parent=EducationGroupYearFactory( education_group_type__category=Categories.TRAINING.name, education_group_type__name=TrainingType.PGRM_MASTER_120.name, academic_year=self.current_academic_year, education_group__end_year=None), child_branch=EducationGroupYearFactory( education_group_type__category=Categories.GROUP.name, education_group_type__name=GroupType.FINALITY_120_LIST_CHOICE. name, academic_year=self.current_academic_year, education_group__end_year=None)) child_grp = GroupElementYearFactory( parent=root_grp.child_branch, child_branch=EducationGroupYearFactory( education_group_type__category=Categories.TRAINING.name, education_group_type__name=TrainingType.MASTER_MA_120.name, academic_year=self.current_academic_year, education_group__end_year=None)) child_child_grp = GroupElementYearFactory( parent=child_grp.child_branch, child_branch=EducationGroupYearFactory( education_group_type__category=Categories.MINI_TRAINING.name, education_group_type__name=MiniTrainingType.OPTION.name, academic_year=self.current_academic_year, education_group__end_year=None)) root_egy_n1 = EducationGroupYearFactory( education_group_type=root_grp.parent.education_group_type, education_group=root_grp.parent.education_group, academic_year=self.next_academic_year) EducationGroupYearFactory( acronym=child_grp.child_branch.acronym, partial_acronym=child_grp.child_branch.partial_acronym, education_group_type=child_grp.child_branch.education_group_type, education_group=child_grp.child_branch.education_group, academic_year=self.next_academic_year, ) EducationGroupYearFactory( acronym=child_child_grp.child_branch.acronym, partial_acronym=child_child_grp.child_branch.partial_acronym, education_group_type=child_child_grp.child_branch. education_group_type, education_group=child_child_grp.child_branch.education_group, academic_year=self.next_academic_year, ) self.postponer = PostponeContent(root_grp.parent) self.postponer.postpone() self.assertEqual( _("The option %(education_group_year_option)s is not anymore accessible in " "%(education_group_year_root)s " "in %(academic_year)s => It is retired of the finality %(education_group_year_finality)s." ) % { "education_group_year_option": "{}".format(child_child_grp.child_branch.partial_acronym), "education_group_year_root": "{} - {}".format(root_egy_n1.partial_acronym, root_egy_n1.acronym), "education_group_year_finality": "{} - {}".format(child_grp.child_branch.partial_acronym, child_grp.child_branch.acronym), "academic_year": self.next_academic_year }, str(self.postponer.warnings[0]))
def test_get_absolute_credits_empty(self): luy = LearningUnitYearFactory(credits=None) GroupElementYearFactory(child_branch=None, child_leaf=luy) self.assertEqual(_get_absolute_credits(luy), '')
def test_with_kwarg_parents_as_instances_is_true(self): group_element = GroupElementYearFactory(child_branch=None, child_leaf=self.child_leaf) result = group_element_year.find_learning_unit_formations( [self.child_leaf], parents_as_instances=True) self.assertEqual(result[self.child_leaf.id], [group_element.parent])
def test_check_related_partims_deletion(self): l_container_year = LearningContainerYearFactory() LearningUnitYearFactory( acronym="LBIR1212", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.learning_unit) msg = deletion._check_related_partims_deletion(l_container_year) self.assertEqual(len(msg.values()), 0) l_unit_2 = LearningUnitYearFactory(acronym="LBIR1213", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.PARTIM) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2) group_1 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2) group_2 = GroupElementYearFactory(child_branch=None, child_leaf=l_unit_2) component = LearningComponentYearFactory(learning_unit_year=l_unit_2) attribution_1 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year) attribution_2 = AttributionNewFactory(learning_container_year=l_unit_2.learning_container_year) AttributionChargeNewFactory(learning_component_year=component, attribution=attribution_1) AttributionChargeNewFactory(learning_component_year=component, attribution=attribution_1) AttributionChargeNewFactory(learning_component_year=component, attribution=attribution_2) msg = deletion._check_related_partims_deletion(l_container_year) msg = list(msg.values()) self.assertEqual(len(msg), 5) self.assertIn(_("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s") % {'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'count': 3}, msg) msg_delete_tutor = _("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s") self.assertIn(msg_delete_tutor % {'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'tutor': attribution_1.tutor}, msg) self.assertIn(msg_delete_tutor % {'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'year': l_unit_2.academic_year, 'tutor': attribution_2.tutor}, msg) msg_delete_offer_type = _('%(subtype)s %(acronym)s is included in the group %(group)s for the year %(year)s') self.assertIn(msg_delete_offer_type % {'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'group': group_1.parent.partial_acronym, 'year': l_unit_2.academic_year}, msg) self.assertIn(msg_delete_offer_type % {'subtype': _('The partim'), 'acronym': l_unit_2.acronym, 'group': group_2.parent.partial_acronym, 'year': l_unit_2.academic_year}, msg)
class TestBuildPDFTree(TestCase): def setUp(self): self.academic_year = AcademicYearFactory() self.education_group_year_1 = EducationGroupYearFactory(credits=10, academic_year=self.academic_year) self.education_group_year_2 = EducationGroupYearFactory(credits=20, academic_year=self.academic_year) self.learning_unit_year_1 = LearningUnitYearFactory() self.learning_unit_year_2 = LearningUnitYearFactory(periodicity=BIENNIAL_ODD) self.learning_unit_year_3 = LearningUnitYearFactory(status=False) self.learning_unit_year_4 = LearningUnitYearFactory(periodicity=BIENNIAL_EVEN) self.group_element_year_1 = GroupElementYearFactory(parent=self.education_group_year_1, child_branch=self.education_group_year_2, is_mandatory=True) self.group_element_year_2 = GroupElementYearFactory(parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_1, is_mandatory=True) self.group_element_year_3 = GroupElementYearFactory(parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_2, is_mandatory=True) self.group_element_year_4 = GroupElementYearFactory(parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_3, is_mandatory=True) self.learning_component_year_1 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_1, type=LECTURING ) self.learning_component_year_2 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_1, type=PRACTICAL_EXERCISES ) self.learning_component_year_3 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_2, type=LECTURING ) self.learning_component_year_4 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_2, type=PRACTICAL_EXERCISES ) self.learning_component_year_5 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_3, type=LECTURING ) self.learning_component_year_6 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_3, type=PRACTICAL_EXERCISES ) self.learning_component_year_7 = LearningComponentYearFactory( learning_unit_year=self.learning_unit_year_4, type=LECTURING ) def test_build_pdf_tree_with_mandatory(self): tree = EducationGroupHierarchy(self.education_group_year_1).to_list() out = Template( "{% load education_group_pdf %}" "{{ tree|pdf_tree_list }}" ).render(Context({ 'tree': tree })) self.assertEqual(out, _build_correct_tree_list(tree)) def test_build_pdf_tree_with_optional(self): self.group_element_year_1.is_mandatory = False self.group_element_year_1.save() self.group_element_year_2.is_mandatory = False self.group_element_year_2.save() tree = EducationGroupHierarchy(self.education_group_year_1).to_list() out = Template( "{% load education_group_pdf %}" "{{ tree|pdf_tree_list }}" ).render(Context({ 'tree': tree })) self.assertEqual(out, _build_correct_tree_list(tree)) def test_tree_list_with_none(self): out = Template( "{% load education_group_pdf %}" "{{ tree|pdf_tree_list }}" ).render(Context({ 'tree': None })) self.assertEqual(out, "") def test_tree_list_with_empty(self): out = Template( "{% load education_group_pdf %}" "{{ tree|pdf_tree_list }}" ).render(Context({ 'tree': [] })) self.assertEqual(out, "")
def create_group_element_years_of_child_type(self, parent=None, link_type=None): return GroupElementYearFactory( parent=parent or self.parent_egy, link_type=link_type, child_branch__education_group_type=self.child_type )
class TestPostpone(TestCase): def setUp(self): self.current_academic_year = create_current_academic_year() self.next_academic_year = AcademicYearFactory( year=self.current_academic_year.year + 1) self.person = CentralManagerFactory() self.person.user.user_permissions.add( Permission.objects.get(codename="change_educationgroup")) self.person.user.user_permissions.add( Permission.objects.get(codename="can_access_education_group")) self.client.force_login(self.person.user) self.education_group = EducationGroupFactory( end_year=self.next_academic_year.year) self.education_group_year = TrainingFactory( academic_year=self.current_academic_year, education_group=self.education_group) self.next_education_group_year = TrainingFactory( academic_year=self.next_academic_year, education_group=self.education_group, management_entity=self.education_group_year.management_entity) PersonEntityFactory(person=self.person, entity=self.education_group_year.management_entity) self.group_element_year = GroupElementYearFactory( parent=self.education_group_year, child_branch__academic_year=self.education_group_year.academic_year ) self.url = reverse("postpone_education_group", kwargs={ "root_id": self.next_education_group_year.pk, "education_group_year_id": self.next_education_group_year.pk, }) self.redirect_url = reverse("education_group_read", args=[ self.next_education_group_year.pk, self.next_education_group_year.pk ]) def test_postpone_case_user_not_logged(self): self.client.logout() response = self.client.get(self.url) self.assertRedirects(response, '/login/?next={}'.format(self.url)) def test_get(self): response = self.client.get(self.url) self.assertEqual(response.status_code, 200) self.assertEqual( response.context["warning_message"], _("Are you sure you want to postpone the content in %(root)s?") % {"root": self.next_education_group_year}) def test_post_with_error(self): self.group_element_year.delete() self.education_group_year.delete() response = self.client.post(self.url, follow=True) message = list(get_messages(response.wsgi_request))[0] self.assertEqual(message.tags, "error") def test_post_with_success(self): response = self.client.post(self.url, follow=True) message = list(get_messages(response.wsgi_request))[0] count = 1 msg = ngettext( "%(count)d education group has been postponed with success.", "%(count)d education groups have been postponed with success.", count) % { 'count': count } self.assertEqual(message.tags, "success") self.assertTrue(msg in message.message)
def setUp(self): self.education_group_year_1 = EducationGroupYearFactory(credits=10) self.education_group_year_2 = EducationGroupYearFactory(credits=20) self.learning_unit_year_1 = LearningUnitYearFactory() self.learning_unit_year_2 = LearningUnitYearFactory( periodicity=BIENNIAL_ODD) self.learning_unit_year_3 = LearningUnitYearFactory(status=False) self.learning_unit_year_4 = LearningUnitYearFactory( periodicity=BIENNIAL_EVEN) self.group_element_year_1 = GroupElementYearFactory( parent=self.education_group_year_1, child_branch=self.education_group_year_2, is_mandatory=True) self.group_element_year_2 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_1, is_mandatory=True) self.group_element_year_3 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_2, is_mandatory=True) self.group_element_year_4 = GroupElementYearFactory( parent=self.education_group_year_2, child_branch=None, child_leaf=self.learning_unit_year_3, is_mandatory=True) self.learning_component_year_1 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, type=LECTURING) self.learning_component_year_2 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_1. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_3 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_2. learning_container_year, type=LECTURING) self.learning_component_year_4 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_2. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_5 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_3. learning_container_year, type=LECTURING) self.learning_component_year_6 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_3. learning_container_year, type=PRACTICAL_EXERCISES) self.learning_component_year_7 = LearningComponentYearFactory( learning_container_year=self.learning_unit_year_4. learning_container_year, type=LECTURING) self.learning_unit_component_1 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_1, learning_component_year=self.learning_component_year_1) self.learning_unit_component_2 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_1, learning_component_year=self.learning_component_year_2) self.learning_unit_component_3 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_2, learning_component_year=self.learning_component_year_3) self.learning_unit_component_4 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_2, learning_component_year=self.learning_component_year_4) self.learning_unit_component_5 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_3, learning_component_year=self.learning_component_year_5) self.learning_unit_component_6 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_3, learning_component_year=self.learning_component_year_6) self.learning_unit_component_7 = LearningUnitComponentFactory( learning_unit_year=self.learning_unit_year_4, learning_component_year=self.learning_component_year_7)
def setUp(self): self.group_element_year = GroupElementYearFactory( parent__academic_year=self.academic_year, child_branch__academic_year=self.academic_year)
class TestValidationOnEducationGroupYearBlockField(TestCase): @classmethod def setUpTestData(cls): cls.academic_year = AcademicYearFactory() def setUp(self): self.group_element_year = GroupElementYearFactory( parent__academic_year=self.academic_year, child_branch__academic_year=self.academic_year) def test_when_value_is_higher_than_max_authorized(self): self.group_element_year.block = 7 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_more_than_6_digits_are_submitted(self): self.group_element_year.block = 1234567 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_values_are_duplicated(self): self.group_element_year.block = 1446 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_values_are_not_ordered(self): self.group_element_year.block = 54 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_0(self): self.group_element_year.block = 0 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_value_is_negative(self): self.group_element_year.block = -124 with self.assertRaises(ValidationError): self.group_element_year.full_clean() def test_when_academic_year_diff_of_2_education_group(self): egy1 = EducationGroupYearFactory(academic_year=self.academic_year) egy2 = EducationGroupYearFactory( academic_year__year=self.academic_year.year + 1) with self.assertRaises(ValidationError): GroupElementYearFactory( parent=egy1, child_branch=egy2, child_leaf=None, )
class TestPostponeContent(TestCase): @classmethod def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.previous_academic_year = AcademicYearFactory( year=cls.current_academic_year.year - 1) cls.next_academic_year = AcademicYearFactory( year=cls.current_academic_year.year + 1) def setUp(self): self.education_group = EducationGroupFactory( end_year=self.next_academic_year) self.current_education_group_year = TrainingFactory( education_group=self.education_group, academic_year=self.current_academic_year) self.current_group_element_year = GroupElementYearFactory( parent=self.current_education_group_year, child_branch__academic_year=self.current_academic_year, child_branch__education_group__end_year=None) self.next_education_group_year = TrainingFactory( education_group=self.education_group, academic_year=self.next_academic_year, education_group_type=self.current_education_group_year. education_group_type) def test_init_postponement(self): self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual(self.postponer.instance, self.current_education_group_year) def test_init_not_postponed_root(self): self.next_education_group_year.delete() with self.assertRaises(NotPostponeError) as cm: self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual( str(cm.exception), _("The root does not exist in the next academic year.")) def test_init_already_postponed_content(self): gr = GroupElementYearFactory(parent=self.next_education_group_year, child_branch__academic_year=self. next_education_group_year.academic_year) with self.assertRaises(NotPostponeError) as cm: self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual(str(cm.exception), _("The content has already been postponed.")) AuthorizedRelationshipFactory( parent_type=self.next_education_group_year.education_group_type, child_type=gr.child_branch.education_group_type, min_count_authorized=1) self.postponer = PostponeContent(self.current_education_group_year) GroupElementYearFactory( parent=gr.child_branch, child_branch__academic_year=gr.child_branch.academic_year) with self.assertRaises(NotPostponeError) as cm: self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual(str(cm.exception), _("The content has already been postponed.")) def test_init_already_postponed_content_with_child_leaf(self): GroupElementYearFactory(parent=self.next_education_group_year, child_branch=None, child_leaf=LearningUnitYearFactory()) with self.assertRaises(NotPostponeError) as cm: self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual(str(cm.exception), _("The content has already been postponed.")) def test_init_old_education_group(self): self.education_group.end_year = AcademicYearFactory(year=2000) with self.assertRaises(NotPostponeError) as cm: self.postponer = PostponeContent(self.current_education_group_year) self.assertEqual( str(cm.exception), _("The end date of the education group is smaller than the year of postponement." )) def test_postpone_with_child_branch(self): self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual(new_root, self.next_education_group_year) self.assertEqual(new_root.groupelementyear_set.count(), 1) new_child_branch = new_root.groupelementyear_set.get().child_branch self.assertEqual(new_child_branch.acronym, self.current_group_element_year.child_branch.acronym) self.assertEqual(new_child_branch.academic_year, self.next_academic_year) def test_postpone_with_child_branch_existing_in_N1(self): n1_child_branch = EducationGroupYearFactory( education_group=self.current_group_element_year.child_branch. education_group, academic_year=self.next_academic_year) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual(new_root, self.next_education_group_year) self.assertEqual(new_root.groupelementyear_set.count(), 1) new_child_branch = new_root.groupelementyear_set.get().child_branch self.assertEqual(new_child_branch, n1_child_branch) self.assertEqual(new_child_branch.academic_year, self.next_academic_year) def test_postpone_with_same_child_branch_existing_in_N1(self): n1_child_branch = EducationGroupYearFactory( academic_year=self.next_academic_year, education_group=self.current_group_element_year.child_branch. education_group, ) n_child_branch = GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch__academic_year=self.current_academic_year, child_branch__education_group__end_year=None) GroupElementYearFactory(parent=self.next_education_group_year, child_branch=n1_child_branch) AuthorizedRelationshipFactory( parent_type=self.next_education_group_year.education_group_type, child_type=n1_child_branch.education_group_type, min_count_authorized=1) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual(new_root, self.next_education_group_year) self.assertEqual(new_root.groupelementyear_set.count(), 1) new_child_branch = new_root.groupelementyear_set.get().child_branch self.assertEqual( new_child_branch.groupelementyear_set.get().child_branch. education_group, n_child_branch.child_branch.education_group) def test_postpone_with_same_child_branch_existing_in_N1_without_relationship( self): """ When the postponed child has a min_count_authorized relation to 1, we have to check if the link to the existing egy is correctly created. """ n1_gr = GroupElementYearFactory( parent=self.next_education_group_year, child_branch__education_group=self.current_group_element_year. child_branch.education_group, child_branch__academic_year=self.next_academic_year, ) AuthorizedRelationshipFactory( parent_type=self.next_education_group_year.education_group_type, child_type=n1_gr.child_branch.education_group_type, min_count_authorized=1) n_1_gr = GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch__academic_year=self.current_academic_year) n1_1_child = EducationGroupYearFactory( education_group=n_1_gr.child_branch.education_group, academic_year=self.next_academic_year, ) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual( new_root.groupelementyear_set.first().child_branch. groupelementyear_set.first().child_branch, n1_1_child) def test_postpone_attach_an_existing_mandatory_group_with_existing_children( self): """ We have to postpone the mandatory children, but if they are already postponed, we have to reuse them. But the copy of the structure must be stopped if these mandatory children are not empty. """ AuthorizedRelationshipFactory( parent_type=self.current_education_group_year.education_group_type, child_type=self.current_group_element_year.child_branch. education_group_type, min_count_authorized=1) self.current_group_element_year.child_branch.acronym = "mandatory_child_n" self.current_group_element_year.child_branch.education_group_type = GroupEducationGroupTypeFactory( ) self.current_group_element_year.child_branch.save() n1_mandatory_egy = EducationGroupYearFactory( academic_year=self.next_academic_year, acronym='mandatory_child_n1', education_group=self.current_group_element_year.child_branch. education_group, education_group_type=self.current_group_element_year.child_branch. education_group_type, ) n1_child_gr = GroupElementYearFactory( parent=n1_mandatory_egy, child_branch__academic_year=self.next_academic_year, ) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_mandatory_child = new_root.groupelementyear_set.first( ).child_branch self.assertEqual(new_mandatory_child, n1_mandatory_egy) self.assertEqual(new_mandatory_child.groupelementyear_set.first(), n1_child_gr) self.assertEqual( _("%(education_group_year)s has already been copied in %(academic_year)s in another program. " "It may have been already modified.") % { "education_group_year": n1_mandatory_egy.partial_acronym, "academic_year": n1_mandatory_egy.academic_year }, str(self.postponer.warnings[0])) def test_postpone_with_child_branches(self): sub_group = GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch__academic_year=self.current_academic_year, child_branch__education_group__end_year=None, ) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual(new_root, self.next_education_group_year) self.assertEqual(new_root.groupelementyear_set.count(), 1) new_child_branch = new_root.groupelementyear_set.get().child_branch self.assertEqual(new_child_branch.acronym, self.current_group_element_year.child_branch.acronym) self.assertEqual(new_child_branch.academic_year, self.next_academic_year) self.assertEqual(new_child_branch.groupelementyear_set.count(), 1) new_child_branch_2 = new_child_branch.groupelementyear_set.get( ).child_branch self.assertEqual(new_child_branch_2.acronym, sub_group.child_branch.acronym) self.assertEqual(new_child_branch_2.academic_year, self.next_academic_year) def test_postpone_with_old_child_leaf(self): n_minus_1_luy = LearningUnitYearFactory( academic_year=self.previous_academic_year) LearningUnitYearFactory(learning_unit=n_minus_1_luy.learning_unit, academic_year=self.current_academic_year) group_leaf = GroupElementYearFactory( parent=self.current_education_group_year, child_branch=None, child_leaf=n_minus_1_luy) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_child_leaf = new_root.groupelementyear_set.last().child_leaf self.assertEqual(new_child_leaf.acronym, group_leaf.child_leaf.acronym) # If the luy does not exist in N+1, it should attach N instance self.assertEqual(new_child_leaf.academic_year, self.previous_academic_year) self.assertTrue(self.postponer.warnings) self.assertIsInstance(self.postponer.warnings[0], ReuseOldLearningUnitYearWarning) self.assertEqual( str(self.postponer.warnings[0]), _("Learning unit %(learning_unit_year)s does not exist in %(academic_year)s => " "Learning unit is postponed with academic year of %(learning_unit_academic_year)s." ) % { "learning_unit_year": n_minus_1_luy.acronym, "academic_year": self.next_academic_year, "learning_unit_academic_year": n_minus_1_luy.academic_year }) def test_postpone_with_new_child_leaf(self): luy = LearningUnitYearFactory(academic_year=self.current_academic_year) new_luy = LearningUnitYearFactory( academic_year=self.next_academic_year, learning_unit=luy.learning_unit) GroupElementYearFactory(parent=self.current_education_group_year, child_branch=None, child_leaf=luy) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_child_leaf = new_root.groupelementyear_set.last().child_leaf self.assertEqual(new_child_leaf, new_luy) self.assertEqual(new_child_leaf.academic_year, self.next_academic_year) def test_when_prerequisite_learning_unit_does_not_exist_in_n1(self): prerequisite = PrerequisiteFactory( learning_unit_year__academic_year=self.current_academic_year, education_group_year=self.current_education_group_year) PrerequisiteItemFactory(prerequisite=prerequisite, ) LearningUnitYearFactory( learning_unit=prerequisite.learning_unit_year.learning_unit, academic_year=self.next_academic_year, ) GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch=None, child_leaf=prerequisite.learning_unit_year) GroupElementYearFactory(parent=EducationGroupYearFactory( education_group=self.current_group_element_year.child_branch. education_group, academic_year=self.next_academic_year), child_branch=None, child_leaf=LearningUnitYearFactory( academic_year=self.next_academic_year)) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertIn( _("%(learning_unit_year)s is not anymore contained in " "%(education_group_year_root)s " "=> the prerequisite for %(learning_unit_year)s is not copied.") % { "education_group_year_root": "{} - {}".format(new_root.partial_acronym, new_root.acronym), "learning_unit_year": prerequisite.learning_unit_year.acronym, }, [str(warning) for warning in self.postponer.warnings]) def test_when_prerequisite_item_does_not_exist_in_formation(self): prerequisite = PrerequisiteFactory( learning_unit_year__academic_year=self.current_academic_year, education_group_year=self.current_education_group_year) item_luy = LearningUnitYearFactory( academic_year=self.current_academic_year) PrerequisiteItemFactory(prerequisite=prerequisite, learning_unit=item_luy.learning_unit) LearningUnitYearFactory( learning_unit=prerequisite.learning_unit_year.learning_unit, academic_year=self.next_academic_year, ) GroupElementYearFactory(parent=self.current_education_group_year, child_branch=None, child_leaf=prerequisite.learning_unit_year) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() self.assertEqual( _("%(prerequisite_item)s is not anymore contained in " "%(education_group_year_root)s " "=> the prerequisite for %(learning_unit_year)s " "having %(prerequisite_item)s as prerequisite is not copied.") % { "education_group_year_root": "{} - {}".format(new_root.partial_acronym, new_root.acronym), "learning_unit_year": prerequisite.learning_unit_year.acronym, "prerequisite_item": item_luy.acronym }, str(self.postponer.warnings[0]), ) def test_postpone_with_prerequisite(self): prerequisite = PrerequisiteFactory( learning_unit_year__academic_year=self.current_academic_year, education_group_year=self.current_education_group_year) item_luy = LearningUnitYearFactory( academic_year=self.current_academic_year) LearningUnitYearFactory(academic_year=self.previous_academic_year, learning_unit=item_luy.learning_unit) n1_item_luy = LearningUnitYearFactory( academic_year=self.next_academic_year, learning_unit=item_luy.learning_unit, ) PrerequisiteItemFactory(prerequisite=prerequisite, learning_unit=item_luy.learning_unit) n1_luy = LearningUnitYearFactory( learning_unit=prerequisite.learning_unit_year.learning_unit, academic_year=self.next_academic_year, ) GroupElementYearFactory(parent=self.current_education_group_year, child_branch=None, child_leaf=item_luy) GroupElementYearFactory(parent=self.current_education_group_year, child_branch=None, child_leaf=prerequisite.learning_unit_year) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_child_leaf = new_root.groupelementyear_set.last().child_leaf self.assertEqual(new_child_leaf.acronym, n1_luy.acronym) # If the luy does not exist in N+1, it should attach N instance self.assertEqual(new_child_leaf.academic_year, self.next_academic_year) self.assertFalse(self.postponer.warnings) self.assertEqual( new_child_leaf.prerequisite_set.first().prerequisiteitem_set.first( ).learning_unit, n1_item_luy.learning_unit) def test_postpone_with_terminated_child_branches(self): sub_group = GroupElementYearFactory( parent=self.current_group_element_year.child_branch, child_branch__academic_year=self.current_academic_year, child_branch__education_group__end_year=self.current_academic_year, ) self.postponer = PostponeContent(self.current_education_group_year) self.postponer.postpone() self.assertTrue(self.postponer.warnings) self.assertEqual( _("%(education_group_year)s is closed in %(end_year)s. This element will not be copied " "in %(academic_year)s.") % { "education_group_year": "{} - {}".format(sub_group.child_branch.partial_acronym, sub_group.child_branch.acronym), "end_year": sub_group.child_branch.education_group.end_year, "academic_year": self.next_academic_year, }, str(self.postponer.warnings[0])) def test_when_education_group_year_exists_in_n1_has_no_child_and_is_reference_link( self): self.current_group_element_year.link_type = LinkTypes.REFERENCE.name self.current_group_element_year.save() n1_referenced_egy = EducationGroupYearFactory( academic_year=self.next_academic_year, education_group=self.current_group_element_year.child_branch. education_group, education_group_type=self.current_education_group_year. education_group_type, ) self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_referenced_egy = new_root.groupelementyear_set.first().child_branch self.assertEqual(new_referenced_egy, n1_referenced_egy) self.assertFalse(new_referenced_egy.groupelementyear_set.all()) self.assertEqual( _("%(education_group_year)s (reference link) has not been copied. Its content is empty." ) % { "education_group_year": "{} - {}".format(new_referenced_egy.partial_acronym, new_referenced_egy.acronym) }, str(self.postponer.warnings[0]), ) def test_when_education_group_year_does_not_exist_in_n1_and_is_reference_link( self): self.current_group_element_year.link_type = LinkTypes.REFERENCE.name self.current_group_element_year.save() self.postponer = PostponeContent(self.current_education_group_year) new_root = self.postponer.postpone() new_referenced_egy = new_root.groupelementyear_set.first().child_branch self.assertEqual(new_referenced_egy.acronym, new_referenced_egy.acronym) self.assertEqual(new_referenced_egy.academic_year, self.next_academic_year) self.assertEqual( _("%(education_group_year)s (reference link) has not been copied. Its content is empty." ) % { "education_group_year": "{} - {}".format(new_referenced_egy.partial_acronym, new_referenced_egy.acronym) }, str(self.postponer.warnings[0]), ) def test_when_options_in_finalities_are_not_consistent(self): root_grp = GroupElementYearFactory( parent=EducationGroupYearFactory( education_group_type__category=Categories.TRAINING.name, education_group_type__name=TrainingType.PGRM_MASTER_120.name, academic_year=self.current_academic_year, education_group__end_year=None), child_branch=EducationGroupYearFactory( education_group_type__category=Categories.GROUP.name, education_group_type__name=GroupType.FINALITY_120_LIST_CHOICE. name, academic_year=self.current_academic_year, education_group__end_year=None)) child_grp = GroupElementYearFactory( parent=root_grp.child_branch, child_branch=EducationGroupYearFactory( education_group_type__category=Categories.TRAINING.name, education_group_type__name=TrainingType.MASTER_MA_120.name, academic_year=self.current_academic_year, education_group__end_year=None)) child_child_grp = GroupElementYearFactory( parent=child_grp.child_branch, child_branch=EducationGroupYearFactory( education_group_type__category=Categories.MINI_TRAINING.name, education_group_type__name=MiniTrainingType.OPTION.name, academic_year=self.current_academic_year, education_group__end_year=None)) root_egy_n1 = EducationGroupYearFactory( education_group_type=root_grp.parent.education_group_type, education_group=root_grp.parent.education_group, academic_year=self.next_academic_year) EducationGroupYearFactory( acronym=child_grp.child_branch.acronym, partial_acronym=child_grp.child_branch.partial_acronym, education_group_type=child_grp.child_branch.education_group_type, education_group=child_grp.child_branch.education_group, academic_year=self.next_academic_year, ) EducationGroupYearFactory( acronym=child_child_grp.child_branch.acronym, partial_acronym=child_child_grp.child_branch.partial_acronym, education_group_type=child_child_grp.child_branch. education_group_type, education_group=child_child_grp.child_branch.education_group, academic_year=self.next_academic_year, ) self.postponer = PostponeContent(root_grp.parent) self.postponer.postpone() self.assertEqual( _("The option %(education_group_year_option)s is not anymore accessible in " "%(education_group_year_root)s " "in %(academic_year)s => It is retired of the finality %(education_group_year_finality)s." ) % { "education_group_year_option": "{}".format(child_child_grp.child_branch.partial_acronym), "education_group_year_root": "{} - {}".format(root_egy_n1.partial_acronym, root_egy_n1.acronym), "education_group_year_finality": "{} - {}".format(child_grp.child_branch.partial_acronym, child_grp.child_branch.acronym), "academic_year": self.next_academic_year }, str(self.postponer.warnings[0])) def test_faculty_cannot_copy_into_future(self): eg = EducationGroupFactory(end_year=AcademicYearFactory( year=self.current_academic_year.year + 4)) egy = EducationGroupYearFactory( education_group=eg, academic_year__year=self.current_academic_year.year + 2) EducationGroupYearFactory( education_group=eg, academic_year__year=self.current_academic_year.year + 3) with self.assertRaises( NotPostponeError, msg= _('You are not allowed to postpone this training in the future.' )): self.postponer = PostponeContent(egy, FacultyManagerFactory()) def test_central_can_copy_into_future(self): central_manager = CentralManagerFactory() eg = EducationGroupFactory(end_year=AcademicYearFactory( year=self.current_academic_year.year + 4)) egy = EducationGroupYearFactory( education_group=eg, academic_year__year=self.current_academic_year.year + 2) GroupElementYearFactory(parent=egy, child_branch__academic_year=egy.academic_year, child_branch__education_group__end_year=None) EducationGroupYearFactory( education_group=eg, academic_year__year=self.current_academic_year.year + 3) self.postponer = PostponeContent(egy, central_manager) self.assertIsNone(self.postponer.check_instance(central_manager))
class TestBuildTree(TestCase): def setUp(self): self.parent = EducationGroupYearFactory() self.group_element_year_1 = GroupElementYearFactory( parent=self.parent ) self.group_element_year_1_1 = GroupElementYearFactory( parent=self.group_element_year_1.child_branch ) self.group_element_year_2 = GroupElementYearFactory( parent=self.parent ) self.group_element_year_2_1 = GroupElementYearFactory( parent=self.group_element_year_2.child_branch, child_branch=None, child_leaf=LearningUnitYearFactory() ) def test_init_tree(self): node = EducationGroupHierarchy(self.parent) self.assertEqual(node.education_group_year, self.parent) self.assertEqual(len(node.children), 2) self.assertEqual(node.children[0].group_element_year, self.group_element_year_1) self.assertEqual(node.children[1].group_element_year, self.group_element_year_2) self.assertEqual(node.children[0].children[0].group_element_year, self.group_element_year_1_1) self.assertEqual(node.children[1].children[0].group_element_year, self.group_element_year_2_1) self.assertEqual(node.children[0].children[0].education_group_year, self.group_element_year_1_1.child_branch) self.assertEqual(node.children[1].children[0].education_group_year, None) self.assertEqual(node.children[1].children[0].learning_unit_year, self.group_element_year_2_1.child_leaf) def test_tree_to_json(self): node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEqual(json['text'], self.parent.verbose) self.assertEqual(json['a_attr']['href'], reverse('education_group_read', args=[ self.parent.pk, self.parent.pk]) + "?group_to_parent=0") self.assertEqual( json['children'][1]['children'][0]['a_attr']['href'], reverse( 'learning_unit_utilization', args=[self.parent.pk, self.group_element_year_2_1.child_leaf.pk] ) + "?group_to_parent={}".format(self.group_element_year_2_1.pk)) def test_tree_to_json_ids(self): node = EducationGroupHierarchy(self.parent) json = node.to_json() self.assertEquals( json['children'][1]['id'], "id_{}_{}".format( node.children[1].education_group_year.pk, node.children[1].group_element_year.pk if node.children[1].group_element_year else '#' ) ) self.assertEquals( json['children'][1]['children'][0]['id'], "id_{}_{}".format( node.children[1].children[0].learning_unit_year.pk, node.children[1].children[0].group_element_year.pk if node.children[1].group_element_year else '#' ) ) def test_build_tree_reference(self): """ This tree contains a reference link. """ self.group_element_year_1.link_type = LinkTypes.REFERENCE.name self.group_element_year_1.save() node = EducationGroupHierarchy(self.parent) self.assertEqual(node.children[0]._get_icon(), static('img/reference.jpg')) list_children = node.to_list() self.assertEqual(list_children, [ self.group_element_year_1_1, self.group_element_year_2, [self.group_element_year_2_1] ])
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, ])
def setUpTestData(cls): cls.academic_year = AcademicYearFactory(year=2017) cls.learning_container_luy1 = LearningContainerYearFactory( academic_year=cls.academic_year) cls.learning_unit_yr_1 = LearningUnitYearFactory( academic_year=cls.academic_year, learning_container_year=cls.learning_container_luy1, credits=50) cls.learning_unit_yr_2 = LearningUnitYearFactory() cls.proposal_creation_1 = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name, ) cls.proposal_creation_2 = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name, ) direct_parent_type = EducationGroupTypeFactory( name='Bachelor', category=education_group_categories.TRAINING) cls.an_education_group_parent = EducationGroupYearFactory( academic_year=cls.academic_year, education_group_type=direct_parent_type, acronym=ROOT_ACRONYM) cls.group_element_child = GroupElementYearFactory( parent=cls.an_education_group_parent, child_branch=None, child_leaf=cls.learning_unit_yr_1) cls.an_education_group = EducationGroupYearFactory( academic_year=cls.academic_year, acronym=PARENT_ACRONYM, title=PARENT_TITLE, partial_acronym=PARENT_PARTIAL_ACRONYM) cls.group_element_child2 = GroupElementYearFactory( parent=cls.an_education_group, child_branch=cls.group_element_child.parent, ) cls.old_academic_year = AcademicYearFactory( year=datetime.date.today().year - 2) cls.current_academic_year = AcademicYearFactory( year=datetime.date.today().year) generatorContainer = GenerateContainer(cls.old_academic_year, cls.current_academic_year) cls.learning_unit_year_with_entities = generatorContainer.generated_container_years[ 0].learning_unit_year_full entities = [ EntityVersionFactory( start_date=datetime.datetime(1900, 1, 1), end_date=None, entity_type=entity_type.FACULTY, entity__organization__type=organization_type.MAIN) for _ in range(4) ] cls.learning_unit_year_with_entities.entity_requirement = entities[0] cls.learning_unit_year_with_entities.entity_allocation = entities[1] cls.proposal_creation_3 = ProposalLearningUnitFactory( learning_unit_year=cls.learning_unit_year_with_entities, state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name, ) cls.learning_container_luy = LearningContainerYearFactory( academic_year=cls.academic_year) cls.luy_with_attribution = LearningUnitYearFactory( academic_year=cls.academic_year, learning_container_year=cls.learning_container_luy, periodicity=learning_unit_year_periodicity.ANNUAL, status=True, language=None, ) cls.luy_with_attribution.entity_requirement = entities[0] cls.luy_with_attribution.entity_allocation = entities[1] cls.component_lecturing = LearningComponentYearFactory( learning_unit_year=cls.luy_with_attribution, type=learning_component_year_type.LECTURING, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) cls.component_practical = LearningComponentYearFactory( learning_unit_year=cls.luy_with_attribution, type=learning_component_year_type.PRACTICAL_EXERCISES, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1) a_person_tutor_1 = PersonFactory(last_name='Dupuis', first_name='Tom', email="*****@*****.**") cls.a_tutor_1 = TutorFactory(person=a_person_tutor_1) cls.an_attribution_1 = AttributionNewFactory(tutor=cls.a_tutor_1, start_year=2017, function=COORDINATOR) cls.attribution_charge_new_lecturing_1 = AttributionChargeNewFactory( learning_component_year=cls.component_lecturing, attribution=cls.an_attribution_1, allocation_charge=15.0) cls.attribution_charge_new_practical_1 = AttributionChargeNewFactory( learning_component_year=cls.component_practical, attribution=cls.an_attribution_1, allocation_charge=5.0) cls.a_tutor_2 = TutorFactory( person=PersonFactory(last_name='Maréchal', first_name='Didier')) cls.an_attribution_2 = AttributionNewFactory(tutor=cls.a_tutor_2, start_year=2017) cls.attribution_charge_new_lecturing_2 = AttributionChargeNewFactory( learning_component_year=cls.component_lecturing, attribution=cls.an_attribution_2, allocation_charge=15.0) cls.attribution_charge_new_practical_2 = AttributionChargeNewFactory( learning_component_year=cls.component_practical, attribution=cls.an_attribution_2, allocation_charge=5.0) cls.entity_requirement = EntityVersion.objects.filter(entity=OuterRef( 'learning_container_year__requirement_entity'), ).current( OuterRef('academic_year__start_date')).values('acronym')[:1] cls.entity_allocation = EntityVersion.objects.filter(entity=OuterRef( 'learning_container_year__allocation_entity'), ).current( OuterRef('academic_year__start_date')).values('acronym')[:1]