def test_li_edit_date_person_test_is_eligible_to_modify_end_date_based_on_container_type( self): lu = LearningUnitFactory(existing_proposal_in_epc=False) learning_unit_year_without_proposal = LearningUnitYearFactory( academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=lu, learning_container_year=self.lcy) person_faculty_manager = FacultyManagerFactory() PersonEntityFactory(person=person_faculty_manager, entity=self.entity_container_yr.entity) self.context['user'] = person_faculty_manager.user self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal result = li_edit_date_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, MSG_NO_ELIGIBLE_TO_MODIFY_END_DATE)) # allowed if _is_person_central_manager or # _is_learning_unit_year_a_partim or # negation(_is_container_type_course_dissertation_or_internship), # test 1st condition true self.context['user'] = self.central_manager_person.user result = li_edit_date_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit)) # test 2nd condition true self.context['user'] = person_faculty_manager.user learning_unit_year_without_proposal.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year_without_proposal.save() self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal self.assertEqual( li_edit_date_lu(self.context, self.url_edit, ""), self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit)) # test 3rd condition true learning_unit_year_without_proposal.learning_container_year.container_type = learning_container_year_types.OTHER_COLLECTIVE learning_unit_year_without_proposal.learning_container_year.save() learning_unit_year_without_proposal.subtype = learning_unit_year_subtypes.FULL learning_unit_year_without_proposal.save() self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal self.assertEqual( li_edit_date_lu(self.context, self.url_edit, ""), self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit))
def test_can_delete_learning_unit_year_with_faculty_manager_role(self): # Faculty manager can only delete other type than COURSE/INTERNSHIP/DISSERTATION managers = [ create_person_with_permission_and_group(FACULTY_MANAGER_GROUP, 'can_delete_learningunit'), create_person_with_permission_and_group(UE_FACULTY_MANAGER_GROUP, 'can_delete_learningunit') ] entity_version = EntityVersionFactory(entity_type=entity_type.FACULTY, acronym="SST", start_date=datetime.date(year=1990, month=1, day=1), end_date=None) for manager in managers: PersonEntityFactory(person=manager, entity=entity_version.entity, with_child=True) # Creation UE learning_unit = LearningUnitFactory() l_containeryear = LearningContainerYearFactory( academic_year=self.academic_year, container_type=learning_container_year_types.COURSE, requirement_entity=entity_version.entity ) learning_unit_year = LearningUnitYearFactory(learning_unit=learning_unit, academic_year=self.academic_year, learning_container_year=l_containeryear, subtype=learning_unit_year_subtypes.FULL) # Cannot remove FULL COURSE self.assertFalse( base.business.learning_units.perms.is_eligible_to_delete_learning_unit_year( learning_unit_year, manager ) ) # Can remove PARTIM COURSE learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year.save() self.assertTrue( base.business.learning_units.perms.is_eligible_to_delete_learning_unit_year( learning_unit_year, manager ) ) # Invalidate cache_property del manager.is_central_manager del manager.is_faculty_manager # With both role, greatest is taken add_to_group(manager.user, CENTRAL_MANAGER_GROUP) learning_unit_year.subtype = learning_unit_year_subtypes.FULL learning_unit_year.save() self.assertTrue( base.business.learning_units.perms.is_eligible_to_delete_learning_unit_year( learning_unit_year, manager ) )
def test_can_delete_learning_unit_year_with_faculty_manager_role(self): # Faculty manager can only delete other type than COURSE/INTERNSHIP/DISSERTATION person = PersonFactory() add_to_group(person.user, FACULTY_MANAGER_GROUP) entity_version = EntityVersionFactory(entity_type=entity_type.FACULTY, acronym="SST", start_date=datetime.date( year=1990, month=1, day=1), end_date=None) PersonEntityFactory(person=person, entity=entity_version.entity, with_child=True) # Creation UE learning_unit = LearningUnitFactory() l_containeryear = LearningContainerYearFactory( academic_year=self.academic_year, container_type=learning_container_year_types.COURSE) EntityContainerYearFactory( learning_container_year=l_containeryear, entity=entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) learning_unit_year = LearningUnitYearFactory( learning_unit=learning_unit, academic_year=self.academic_year, learning_container_year=l_containeryear, subtype=learning_unit_year_subtypes.FULL) # Cannot remove FULL COURSE self.assertFalse( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person)) # Can remove PARTIM COURSE learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year.save() self.assertTrue( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person)) # Invalidate cache_property del person.is_central_manager del person.is_faculty_manager # With both role, greatest is taken add_to_group(person.user, CENTRAL_MANAGER_GROUP) learning_unit_year.subtype = learning_unit_year_subtypes.FULL learning_unit_year.save() self.assertTrue( base.business.learning_units.perms. is_eligible_to_delete_learning_unit_year(learning_unit_year, person))
def test_cannot_delete_learning_unit_year_with_administrative_manager_role(self): manager = AdministrativeManagerFactory() entity_version = EntityVersionFactory(entity_type=entity_type.FACULTY, acronym="SST", start_date=datetime.date(year=1990, month=1, day=1), end_date=None) PersonEntityFactory(person=manager, entity=entity_version.entity, with_child=True) # Creation UE learning_unit = LearningUnitFactory() l_containeryear = LearningContainerYearFactory(academic_year=self.academic_year, container_type=learning_container_year_types.COURSE, requirement_entity=entity_version.entity) learning_unit_year = LearningUnitYearFactory(learning_unit=learning_unit, academic_year=self.academic_year, learning_container_year=l_containeryear, subtype=learning_unit_year_subtypes.FULL) # Cannot remove FULL COURSE self.assertFalse( base.business.learning_units.perms.is_eligible_to_delete_learning_unit_year( learning_unit_year, manager ) ) # Can remove PARTIM COURSE learning_unit_year.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year.save() self.assertFalse( base.business.learning_units.perms.is_eligible_to_delete_learning_unit_year( learning_unit_year, manager ) )
def test_li_edit_date_person_test_is_eligible_to_modify_end_date_based_on_container_type( self): lu = LearningUnitFactory(existing_proposal_in_epc=False) learning_unit_year_without_proposal = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_unit=lu, ) person_faculty_managers = [ create_person_with_permission_and_group(FACULTY_MANAGER_GROUP, 'can_edit_learningunit'), create_person_with_permission_and_group(UE_FACULTY_MANAGER_GROUP, 'can_edit_learningunit') ] for manager in person_faculty_managers: manager.user.user_permissions.add( Permission.objects.get(codename='can_edit_learningunit_date')) learning_unit_year_without_proposal.subtype = learning_unit_year_subtypes.FULL learning_unit_year_without_proposal.learning_container_year = self.lcy learning_unit_year_without_proposal.learning_container_year.container_type = learning_container_year_types.COURSE learning_unit_year_without_proposal.learning_container_year.save() learning_unit_year_without_proposal.save() PersonEntityFactory( person=manager, entity=self.requirement_entity, ) self.context['user'] = manager.user self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal result = li_edit_date_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected( ID_LINK_EDIT_DATE_LU, MSG_NO_ELIGIBLE_TO_MODIFY_END_DATE)) # allowed if _is_person_central_manager or # _is_learning_unit_year_a_partim or # negation(_is_container_type_course_dissertation_or_internship), # test 1st condition true self.context['user'] = self.central_manager_person.user result = li_edit_date_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit)) # test 2nd condition true self.context['user'] = manager.user learning_unit_year_without_proposal.subtype = learning_unit_year_subtypes.PARTIM learning_unit_year_without_proposal.save() self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal self.assertEqual( li_edit_date_lu(self.context, self.url_edit, ""), self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit)) # test 3rd condition true learning_unit_year_without_proposal.learning_container_year.container_type = learning_container_year_types.OTHER_COLLECTIVE learning_unit_year_without_proposal.learning_container_year.save() learning_unit_year_without_proposal.subtype = learning_unit_year_subtypes.FULL learning_unit_year_without_proposal.save() self.context[ 'learning_unit_year'] = learning_unit_year_without_proposal self.assertEqual( li_edit_date_lu(self.context, self.url_edit, ""), self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, url=self.url_edit))