def setUpTestData(cls): cls.learning_unit = LearningUnitFactory() cls.current_academic_year = create_current_academic_year() cls.next_academic_yr = AcademicYearFactory( year=cls.current_academic_year.year + 1) academic_years = [cls.current_academic_year, cls.next_academic_yr] cls.lcy = LearningContainerYearFactory( academic_year=cls.current_academic_year, container_type=learning_container_year_types.COURSE, requirement_entity=EntityVersionFactory().entity) cls.central_manager = CentralManagerFactory( 'can_edit_learningunit_pedagogy') cls.luy = LearningUnitYearFactory( learning_unit=cls.learning_unit, academic_year=cls.current_academic_year, learning_container_year=cls.lcy, ) cls.central_manager.linked_entities = [cls.lcy.requirement_entity.id] generate_creation_or_end_date_proposal_calendars(academic_years) generate_modification_transformation_proposal_calendars(academic_years)
def create_learning_unit_years_and_dependencies(self): l1 = LearningUnitFactory(start_year=2015) learning_unit_years = [] for year in range(4): ac_year = AcademicYearFactory(year=2000 + year) l_containeryear = LearningContainerYearFactory(academic_year=ac_year) EntityContainerYearFactory(learning_container_year=l_containeryear, entity=self.entity_version.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) learning_unit_year = LearningUnitYearFactory(learning_unit=l1, academic_year=ac_year, learning_container_year=l_containeryear) learning_unit_years.append(learning_unit_year) learning_unit_years[1].subtype = learning_unit_year_subtypes.FULL learning_unit_years[1].save() lcomponent = LearningComponentYearFactory() LearningClassYearFactory(learning_component_year=lcomponent) LearningClassYearFactory(learning_component_year=lcomponent) LearningUnitComponentFactory(learning_unit_year=learning_unit_years[1], learning_component_year=lcomponent) return learning_unit_years
def test_li_delete_all_lu_cannot_delete_learning_unit_year_according_type( self): a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_delete_learningunit') self.context['user'] = a_person.user lcy_master = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy_master) self.context['learning_unit_year'] = learning_unit_yr result = li_delete_all_lu(self.context, self.url_edit, '', "#modalDeleteLuy") expected = self._get_result_data_expected_delete( "link_delete_lus", MSG_CAN_DELETE_ACCORDING_TO_TYPE) self.assertEqual(result, expected)
def setUp(self): self.academic_year = create_current_academic_year() self.learning_unit = LearningUnitFactory(start_year=1900) l_container_year = LearningContainerYearFactory( acronym="LBIR1212", academic_year=self.academic_year) self.l_unit_yr_1 = LearningUnitYearFactory( acronym="LBIR1212", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL) entity_requirement_ver = EntityVersionFactory( acronym=ACRONYM_REQUIREMENT, entity=EntityFactory()) self.l_unit_yr_1.entity_requirement = entity_requirement_ver.acronym entity_allocation_ver = EntityVersionFactory( acronym=ACRONYM_ALLOCATION, entity=EntityFactory()) self.l_unit_yr_1.entity_allocation = entity_allocation_ver.acronym entity_vr = EntityVersionFactory(acronym='ESPO') self.proposal_1 = ProposalLearningUnitFactory( learning_unit_year=self.l_unit_yr_1, entity=entity_vr.entity) self.user = UserFactory()
def setUp(self): self.person = PersonFactory() starting_year = YEAR_LIMIT_LUE_MODIFICATION academic_years = GenerateAcademicYear(starting_year, starting_year + 6).academic_years self.academic_year = academic_years[1] self.language = LanguageFactory(code='FR') organization = OrganizationFactory(type=organization_type.MAIN) campus = CampusFactory(organization=organization) language = LanguageFactory(code='FR') container_year = LearningContainerYearFactory( academic_year=self.academic_year, container_type=EXTERNAL) self.learning_unit = LearningUnitFactory( start_year=self.academic_year.year) self.learning_unit_year = LearningUnitYearFactory( acronym='EOSIS1111', academic_year=self.academic_year, learning_unit=self.learning_unit, learning_container_year=container_year, subtype=learning_unit_year_subtypes.FULL, campus=campus, language=language, internship_subtype=None)
def test_new(self): learning_unit = LearningUnitFactory(acronym='DEMO') speciality = SpecialityFactory.build(learning_unit=learning_unit) url = reverse('speciality_new', kwargs={ 'cohort_id': self.cohort.id, }) response = self.client.post(url, data={ 'learning_unit': learning_unit.acronym, 'mandatory': True, 'name': speciality.name, 'order_position': speciality.order_position, 'acronym': speciality.acronym, }) self.assertRedirects( response, reverse('internships_specialities', kwargs={ 'cohort_id': self.cohort.id, }))
def setUp(self): self.academic_year = create_current_academic_year() self.learning_unit = LearningUnitFactory(start_year=1900) l_container_year = LearningContainerYearFactory( acronym="LBIR1212", academic_year=self.academic_year) self.l_unit_yr_1 = LearningUnitYearFactory( acronym="LBIR1212", learning_container_year=l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL) self.l_unit_yr_1.entities = { entity_container_year_link_type.REQUIREMENT_ENTITY: EntityVersionFactory(acronym=ACRONYM_REQUIREMENT, entity=EntityFactory()), entity_container_year_link_type.ALLOCATION_ENTITY: EntityVersionFactory(acronym=ACRONYM_ALLOCATION, entity=EntityFactory()) } entity_vr = EntityVersionFactory(acronym='ESPO') self.proposal_1 = ProposalLearningUnitFactory( learning_unit_year=self.l_unit_yr_1, entity=entity_vr.entity) self.user = UserFactory()
def test_apply_learning_unit_year_postponement(self): """ Postpone to N+6 in Learning Unit Admin """ current_year = get_current_year() start_year = AcademicYearFactory(year=current_year) end_year = AcademicYearFactory(year=current_year + 6) academic_years = GenerateAcademicYear(start_year, end_year) lu = LearningUnitFactory(end_year=None) LearningUnitYearFactory( academic_year=academic_years[0], learning_unit=lu ) postpone_url = reverse('admin:base_learningunit_changelist') self.client.force_login(SuperUserFactory()) response = self.client.post(postpone_url, data={'action': 'apply_learning_unit_year_postponement', '_selected_action': [lu.pk]}) msg = [m.message for m in get_messages(response.wsgi_request)] self.assertEqual(msg[0], ngettext( "%(count)d learning unit has been postponed with success", "%(count)d learning units have been postponed with success", 1 ) % {'count': 1})
def setUp(self): self.central_manager = PersonFactory() self.central_manager.user.groups.add( Group.objects.get(name=CENTRAL_MANAGER_GROUP)) self.faculty_manager = PersonFactory() self.faculty_manager.user.groups.add( Group.objects.get(name=FACULTY_MANAGER_GROUP)) self.current_academic_year = create_current_academic_year() self.learning_container = LearningContainerFactory() self.learning_unit = LearningUnitFactory( learning_container=self.learning_container) self.learning_container_year = LearningContainerYearFactory( learning_container=self.learning_container, academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) self.form = LearningUnitYearModelForm(data=None, person=self.central_manager, subtype=FULL) campus = CampusFactory(organization=OrganizationFactory( type=organization_type.MAIN)) self.language = LanguageFactory(code='FR') self.post_data = { 'acronym_0': 'L', 'acronym_1': 'OSIS9001', 'academic_year': self.current_academic_year.pk, 'specific_title': 'The hobbit', 'specific_title_english': 'An Unexpected Journey', 'credits': 3, 'session': '3', 'status': True, 'quadrimester': 'Q1', 'internship_subtype': PROFESSIONAL_INTERNSHIP, 'attribution_procedure': INTERNAL_TEAM, 'campus': campus.pk, 'language': self.language.pk, 'periodicity': ANNUAL, # Learning component year data model form 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-MAX_NUM_FORMS': '2', 'form-0-hourly_volume_total_annual': 20, 'form-0-hourly_volume_partial_q1': 10, 'form-0-hourly_volume_partial_q2': 10, 'form-1-hourly_volume_total_annual': 20, 'form-1-hourly_volume_partial_q1': 10, 'form-1-hourly_volume_partial_q2': 10, } self.requirement_entity = EntityContainerYearFactory( type=REQUIREMENT_ENTITY, learning_container_year=self.learning_container_year) self.allocation_entity = EntityContainerYearFactory( type=ALLOCATION_ENTITY, learning_container_year=self.learning_container_year) self.additional_requirement_entity_1 = EntityContainerYearFactory( type=ADDITIONAL_REQUIREMENT_ENTITY_1, learning_container_year=self.learning_container_year) self.additional_requirement_entity_2 = EntityContainerYearFactory( type=ADDITIONAL_REQUIREMENT_ENTITY_2, learning_container_year=self.learning_container_year) EntityVersionFactory( entity=self.additional_requirement_entity_1.entity, start_date=self.learning_container_year.academic_year.start_date, end_date=self.learning_container_year.academic_year.end_date) EntityVersionFactory( entity=self.additional_requirement_entity_2.entity, start_date=self.learning_container_year.academic_year.start_date, end_date=self.learning_container_year.academic_year.end_date) self.allocation_entity_version = EntityVersionFactory( entity=self.allocation_entity.entity, start_date=self.learning_container_year.academic_year.start_date, end_date=self.learning_container_year.academic_year.end_date) self.requirement_entity_version = EntityVersionFactory( entity=self.requirement_entity.entity, start_date=self.learning_container_year.academic_year.start_date, end_date=self.learning_container_year.academic_year.end_date) self.entity_container_years = [ self.requirement_entity, self.allocation_entity, self.additional_requirement_entity_1, self.additional_requirement_entity_2 ]
def setUp(self): self.title = "Title" self.acronym = "Acronym" self.learning_unit = LearningUnitFactory(title=self.title, acronym=self.acronym)
def get_valid_form_data(academic_year, person, learning_unit_year=None): entities = create_entities_hierarchy() PersonEntityFactory(person=person, entity=entities['root_entity'], with_child=True) requirement_entity_version = entities['child_one_entity_version'] organization = OrganizationFactory(type=organization_type.MAIN) campus = CampusFactory(organization=organization) language = LanguageFactory(code='FR') if not learning_unit_year: learning_container = LearningContainerFactory() container_year = LearningContainerYearFactory( academic_year=academic_year, learning_container=learning_container) learning_unit_full = LearningUnitFactory( learning_container=learning_container, start_year=academic_year.year, end_year=academic_year.year, ) learning_unit_year = LearningUnitYearFactory.build( academic_year=academic_year, learning_unit=learning_unit_full, learning_container_year=container_year, subtype=learning_unit_year_subtypes.FULL, campus=campus, language=language, periodicity=learning_unit_year_periodicity.ANNUAL) cm_lcy = LearningComponentYear.objects.filter( learning_unit_year=learning_unit_year).first() pp_lcy = LearningComponentYear.objects.filter( learning_unit_year=learning_unit_year).last() return { # Learning unit year data model form 'acronym': learning_unit_year.acronym, 'acronym_0': learning_unit_year.acronym[0], 'acronym_1': learning_unit_year.acronym[1:], 'subtype': learning_unit_year.subtype, 'academic_year': learning_unit_year.academic_year.id, 'specific_title': learning_unit_year.specific_title, 'specific_title_english': learning_unit_year.specific_title_english, 'credits': learning_unit_year.credits, 'session': learning_unit_year.session, 'quadrimester': learning_unit_year.quadrimester, 'status': learning_unit_year.status, 'internship_subtype': None, 'attribution_procedure': learning_unit_year.attribution_procedure, 'campus': learning_unit_year.campus.id, 'language': learning_unit_year.language.pk, 'periodicity': learning_unit_year.periodicity, # Learning unit data model form 'faculty_remark': learning_unit_year.learning_unit.faculty_remark, 'other_remark': learning_unit_year.learning_unit.other_remark, # Learning container year data model form 'common_title': learning_unit_year.learning_container_year.common_title, 'common_title_english': learning_unit_year.learning_container_year.common_title_english, 'container_type': learning_unit_year.learning_container_year.container_type, 'type_declaration_vacant': learning_unit_year.learning_container_year.type_declaration_vacant, 'team': learning_unit_year.learning_container_year.team, 'is_vacant': learning_unit_year.learning_container_year.is_vacant, 'requirement_entity-entity': requirement_entity_version.id, 'allocation_entity-entity': requirement_entity_version.id, 'additional_requirement_entity_1-entity': '', # Learning component year data model form 'component-0-id': cm_lcy and cm_lcy.pk, 'component-1-id': pp_lcy and pp_lcy.pk, 'component-TOTAL_FORMS': '2', 'component-INITIAL_FORMS': '0' if not cm_lcy else '2', 'component-MAX_NUM_FORMS': '2', 'component-0-hourly_volume_total_annual': 20, 'component-0-hourly_volume_partial_q1': 10, 'component-0-hourly_volume_partial_q2': 10, 'component-1-hourly_volume_total_annual': 20, 'component-1-hourly_volume_partial_q1': 10, 'component-1-hourly_volume_partial_q2': 10, }
class TestFetchLearningUnitToPostpone(TestCase): def setUp(self): current_year = get_current_year() self.academic_years = [ AcademicYearFactory(year=i) for i in range(current_year, current_year + 7) ] self.learning_unit = LearningUnitFactory(end_year=None) def test_fetch_learning_unit_to_postpone_to_N6(self): LearningUnitYearFactory( learning_unit=self.learning_unit, academic_year=self.academic_years[-2], ) self.assertEqual(LearningUnitYear.objects.count(), 1) result, errors = LearningUnitAutomaticPostponement().postpone() self.assertEqual(len(result), 1) self.assertFalse(errors) def test_luy_to_not_duplicated(self): # The learning unit is over self.learning_unit.end_year = self.academic_years[-2].year self.learning_unit.save() LearningUnitYearFactory( learning_unit=self.learning_unit, academic_year=self.academic_years[-2], ) self.assertEqual(LearningUnitYear.objects.count(), 1) result, errors = LearningUnitAutomaticPostponement().postpone() self.assertEqual(len(result), 0) self.assertFalse(errors) def test_luy_already_duplicated(self): LearningUnitYearFactory( learning_unit=self.learning_unit, academic_year=self.academic_years[-2], ) LearningUnitYearFactory( learning_unit=self.learning_unit, academic_year=self.academic_years[-1], ) self.assertEqual(LearningUnitYear.objects.count(), 2) result, errors = LearningUnitAutomaticPostponement().postpone() self.assertEqual(len(result), 0) self.assertFalse(errors) @mock.patch( 'base.business.learning_units.automatic_postponement.LearningUnitAutomaticPostponement.extend_obj' ) def test_luy_to_duplicate_with_error(self, mock_method): mock_method.side_effect = Mock(side_effect=Error("test error")) luy_with_error = LearningUnitYearFactory( learning_unit=self.learning_unit, academic_year=self.academic_years[-2], ) self.assertEqual(LearningUnitYear.objects.count(), 1) result, errors = LearningUnitAutomaticPostponement().postpone() self.assertEqual(errors, [luy_with_error.learning_unit]) self.assertEqual(len(result), 0)
def create_learning_unit(acronym, title): return LearningUnitFactory(acronym=acronym, title=title, start_year=2010)
def test_find_by_id(self): l_unit_1 = LearningUnitFactory() LearningUnitFactory() LearningUnitFactory() self.assertEqual(l_unit_1, learning_unit.find_by_id(l_unit_1.id))
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))
def test_properties_acronym_and_title(self): a_learning_unit = LearningUnitFactory() a_learning_unit_year = LearningUnitYearFactory(learning_unit=a_learning_unit) self.assertEqual(a_learning_unit.title, a_learning_unit_year.specific_title) self.assertEqual(a_learning_unit.acronym, a_learning_unit_year.acronym)
def setUp(self): self.learning_unit = LearningUnitFactory() self.previous_learning_unit = LearningUnitFactory( existing_proposal_in_epc=False) self.academic_year = create_current_academic_year() self.previous_academic_year = AcademicYearFactory( year=self.academic_year.year - 1) self.later_academic_year = AcademicYearFactory( year=self.academic_year.year + 5) self.lcy = LearningContainerYearFactory( academic_year=self.academic_year, container_type=learning_container_year_types.COURSE) self.learning_unit_year = LearningUnitYearFactory( academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.learning_unit, learning_container_year=self.lcy) self.previous_learning_unit_year = LearningUnitYearFactory( academic_year=self.previous_academic_year, learning_unit=self.learning_unit) self.previous_luy_2 = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.previous_learning_unit, learning_container_year=LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE)) self.previous_proposal = ProposalLearningUnitFactory( learning_unit_year=self.previous_luy_2) self.user = UserFactory() self.central_manager_person = CentralManagerFactory() self.person_entity = PersonEntityFactory( person=self.central_manager_person) self.requirement_entity = self.person_entity.entity self.proposal = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year, initial_data={ 'learning_container_year': { 'common_title': self.lcy.common_title }, 'entities': { 'REQUIREMENT_ENTITY': self.requirement_entity.id } }, ) self.entity_container_yr = EntityContainerYearFactory( learning_container_year=self.learning_unit_year. learning_container_year, entity=self.person_entity.entity, type=entity_container_year_link_type.REQUIREMENT_ENTITY) self.client.force_login(user=self.central_manager_person.user) self.url_edit = reverse('edit_learning_unit', args=[self.learning_unit_year.id]) self.url = self.client.get( reverse( "learning_unit", kwargs={"learning_unit_year_id": self.learning_unit_year.id})) self.request = RequestFactory().get("") self.context = { "learning_unit_year": self.learning_unit_year, "request": self.request, "user": self.central_manager_person.user, "proposal": self.proposal }
def test_find_by_ids(self): l_unit_1 = LearningUnitFactory() l_unit_2 = LearningUnitFactory() LearningUnitFactory() LearningUnitFactory() self.assertEqual(2, len( learning_unit.find_by_ids( (l_unit_1.id, l_unit_2.id) )))
def setup_learning_unit(start_year, end_year=None): result = None if start_year: result = LearningUnitFactory(start_year=start_year, end_year=end_year) return result
def setUp(self): self.academic_year = create_current_academic_year() self.learning_unit = LearningUnitFactory(start_year=1900)
def setUp(self): current_year = get_current_year() self.academic_years = [AcademicYearFactory(year=i) for i in range(current_year, current_year + 7)] self.learning_unit = LearningUnitFactory(end_year=None)
def test_create_learning_unit_with_start_year_higher_than_end_year(self): l_unit = LearningUnitFactory.build(start_year=2000, end_year=1999) with self.assertRaises(AttributeError): l_unit.save()
def setUp(self): self.user = UserFactory() self.central_manager_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_edit_learningunit') self.central_manager_person.user.user_permissions.add( Permission.objects.get(codename='can_propose_learningunit'), Permission.objects.get(codename='can_edit_learningunit_date'), Permission.objects.get(codename='can_delete_learningunit')) self.person_entity = PersonEntityFactory( person=self.central_manager_person) self.learning_unit = LearningUnitFactory() self.previous_learning_unit = LearningUnitFactory( existing_proposal_in_epc=False) self.current_academic_year = create_current_academic_year() self.previous_academic_year = AcademicYearFactory( year=self.current_academic_year.year - 1) self.next_academic_yr = AcademicYearFactory( year=self.current_academic_year.year + 1) AcademicYearFactory(year=self.current_academic_year.year + 2) AcademicYearFactory(year=self.current_academic_year.year + 3) AcademicYearFactory(year=self.current_academic_year.year + 4) self.later_academic_year = AcademicYearFactory( year=self.current_academic_year.year + 5) self.lcy = LearningContainerYearFactory( academic_year=self.next_academic_yr, container_type=learning_container_year_types.COURSE, requirement_entity=self.person_entity.entity) self.learning_unit_year = LearningUnitYearFactory( academic_year=self.next_academic_yr, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.learning_unit, learning_container_year=self.lcy) self.previous_learning_unit_year = LearningUnitYearFactory( academic_year=self.previous_academic_year, learning_unit=self.learning_unit, learning_container_year__requirement_entity=self.person_entity. entity) self.previous_luy_2 = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.previous_learning_unit, learning_container_year=LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE)) self.previous_proposal = ProposalLearningUnitFactory( learning_unit_year=self.previous_luy_2) self.requirement_entity = self.person_entity.entity self.proposal = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year, initial_data={ 'learning_container_year': { 'common_title': self.lcy.common_title }, 'entities': { 'REQUIREMENT_ENTITY': self.requirement_entity.id } }, ) self.client.force_login(user=self.central_manager_person.user) self.url_edit = reverse('edit_learning_unit', args=[self.learning_unit_year.id]) self.request = RequestFactory().get("") self.context = { "learning_unit_year": self.learning_unit_year, "request": self.request, "user": self.central_manager_person.user, "proposal": self.proposal }
def test_search_by_acronym(self): LearningUnitFactory(acronym="LT49786") LearningUnitFactory() LearningUnitFactory() self.assertEqual(1, len(learning_unit.search(acronym="LT49786")))
class LearningUnitTagLiEditTest(TestCase): def setUp(self): self.user = UserFactory() self.central_manager_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_edit_learningunit') self.central_manager_person.user.user_permissions.add( Permission.objects.get(codename='can_propose_learningunit'), Permission.objects.get(codename='can_edit_learningunit_date'), Permission.objects.get(codename='can_delete_learningunit')) self.person_entity = PersonEntityFactory( person=self.central_manager_person) self.learning_unit = LearningUnitFactory() self.previous_learning_unit = LearningUnitFactory( existing_proposal_in_epc=False) self.current_academic_year = create_current_academic_year() self.previous_academic_year = AcademicYearFactory( year=self.current_academic_year.year - 1) self.next_academic_yr = AcademicYearFactory( year=self.current_academic_year.year + 1) AcademicYearFactory(year=self.current_academic_year.year + 2) AcademicYearFactory(year=self.current_academic_year.year + 3) AcademicYearFactory(year=self.current_academic_year.year + 4) self.later_academic_year = AcademicYearFactory( year=self.current_academic_year.year + 5) self.lcy = LearningContainerYearFactory( academic_year=self.next_academic_yr, container_type=learning_container_year_types.COURSE, requirement_entity=self.person_entity.entity) self.learning_unit_year = LearningUnitYearFactory( academic_year=self.next_academic_yr, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.learning_unit, learning_container_year=self.lcy) self.previous_learning_unit_year = LearningUnitYearFactory( academic_year=self.previous_academic_year, learning_unit=self.learning_unit, learning_container_year__requirement_entity=self.person_entity. entity) self.previous_luy_2 = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=self.previous_learning_unit, learning_container_year=LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE)) self.previous_proposal = ProposalLearningUnitFactory( learning_unit_year=self.previous_luy_2) self.requirement_entity = self.person_entity.entity self.proposal = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year, initial_data={ 'learning_container_year': { 'common_title': self.lcy.common_title }, 'entities': { 'REQUIREMENT_ENTITY': self.requirement_entity.id } }, ) self.client.force_login(user=self.central_manager_person.user) self.url_edit = reverse('edit_learning_unit', args=[self.learning_unit_year.id]) self.request = RequestFactory().get("") self.context = { "learning_unit_year": self.learning_unit_year, "request": self.request, "user": self.central_manager_person.user, "proposal": self.proposal } @override_settings(YEAR_LIMIT_LUE_MODIFICATION=2018) def test_li_edit_lu_year_non_editable_for_faculty_managers(self): 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 faculty_managers: self.context[ "learning_unit_year"] = self.previous_learning_unit_year self.context["user"] = manager.user result = li_edit_lu(self.context, self.url_edit, "") self.assertEqual( result, { 'load_modal': False, 'id_li': ID_LINK_EDIT_LU, 'url': "#", 'title': "{}. {}".format( "You can't modify learning unit under year : %(year)d" % {"year": settings.YEAR_LIMIT_LUE_MODIFICATION}, "Modifications should be made in EPC for year %(year)d" % { "year": self.previous_learning_unit_year.academic_year.year }), 'class_li': DISABLED, 'text': "", 'data_target': "" }) def test_li_edit_lu_year_is_editable_but_existing_proposal_in_epc(self): self.learning_unit.existing_proposal_in_epc = True self.learning_unit.save() self.context["learning_unit_year"] = self.learning_unit_year result = li_edit_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_LU, MSG_EXISTING_PROPOSAL_IN_EPC)) result = li_edit_date_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_DATE_LU, MSG_EXISTING_PROPOSAL_IN_EPC)) result = li_delete_all_lu(self.context, self.url_edit, '', "#modalDeleteLuy") expected = self._get_result_data_expected_delete( "link_delete_lus", MSG_EXISTING_PROPOSAL_IN_EPC) self.assertEqual(result, expected) self.proposal.learning_unit_year = self.learning_unit_year self.proposal.save() self.context["proposal"] = self.proposal result = li_suppression_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal_suppression( "link_proposal_suppression", MSG_EXISTING_PROPOSAL_IN_EPC, DISABLED)) result = li_modification_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected( "link_proposal_modification", MSG_EXISTING_PROPOSAL_IN_EPC, )) def test_li_edit_lu_year_is_learning_unit_year_not_in_range_to_be_modified( self): 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'), ] later_luy = LearningUnitYearFactory( academic_year=self.later_academic_year, learning_unit=LearningUnitFactory(existing_proposal_in_epc=False)) self.context["learning_unit_year"] = later_luy for manager in managers: self.context["user"] = manager.user result = li_edit_lu( self.context, reverse('edit_learning_unit', args=[later_luy.id]), "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_LU, MSG_NOT_GOOD_RANGE_OF_YEARS)) def test_li_edit_lu_year_person_is_not_linked_to_entity_in_charge_of_lu( self): a_person = create_person_with_permission_and_group( CENTRAL_MANAGER_GROUP, 'can_edit_learningunit') self.context['user'] = a_person.user result = li_edit_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected( ID_LINK_EDIT_LU, MSG_ONLY_IF_YOUR_ARE_LINK_TO_ENTITY)) def test_li_edit_lu_everything_ok(self): self.proposal.delete() result = li_edit_lu(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected(ID_LINK_EDIT_LU, url=self.url_edit)) 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)) 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)) def test_is_not_valid_not_proposal(self): self.context['proposal'] = None permission_denied_message, disabled = is_valid_proposal(self.context) self.assertEqual(permission_denied_message, MSG_IS_NOT_A_PROPOSAL) self.assertEqual(disabled, DISABLED) def test_is_not_valid_not_same_lu(self): self.context['learning_unit_year'] = self.previous_learning_unit_year self.context['proposal'] = self.proposal permission_denied_message, disabled = is_valid_proposal(self.context) self.assertEqual(permission_denied_message, MSG_PROPOSAL_NOT_ON_CURRENT_LU) self.assertEqual(disabled, DISABLED) def test_is_valid(self): self.context['learning_unit_year'] = self.learning_unit_year self.context['proposal'] = self.proposal permission_denied_message, disabled = is_valid_proposal(self.context) self.assertEqual(permission_denied_message, "") self.assertEqual(disabled, "") @override_settings(YEAR_LIMIT_LUE_MODIFICATION=2018) def test_li_edit_proposal_as_faculty_manager(self): person_faculty_manager = FacultyManagerFactory() self.context['user'] = person_faculty_manager.user self.context['proposal'] = self.proposal self.context['learning_unit_year'] = self.proposal.learning_unit_year result = li_edit_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_proposal_edit', MSG_CAN_EDIT_PROPOSAL_NO_LINK_TO_ENTITY, DISABLED)) faculty_manager_person = FacultyManagerFactory() PersonEntityFactory(person=faculty_manager_person, entity=self.requirement_entity) self.context['user'] = faculty_manager_person.user self.context['person'] = faculty_manager_person self.proposal.state = ProposalState.CENTRAL.name self.proposal.save() self.context['proposal'] = self.proposal result = li_edit_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_proposal_edit', MSG_NOT_PROPOSAL_STATE_FACULTY, DISABLED)) self.proposal.state = ProposalState.FACULTY.name self.proposal.save() self.context['proposal'] = self.proposal result = li_edit_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_proposal_edit', MSG_NOT_ELIGIBLE_TO_EDIT_PROPOSAL, DISABLED)) def test_li_cancel_proposal_not_accordance_with_proposal_state(self): person_faculty_manager = FacultyManagerFactory() self.context['user'] = person_faculty_manager.user self.proposal.state = ProposalState.CENTRAL.name self.proposal.save() self.context['proposal'] = self.proposal result = li_cancel_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_cancel_proposal', MSG_PERSON_NOT_IN_ACCORDANCE_WITH_PROPOSAL_STATE, DISABLED)) self.proposal.state = ProposalState.FACULTY.name self.proposal.save() result = li_cancel_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_cancel_proposal', MSG_CAN_EDIT_PROPOSAL_NO_LINK_TO_ENTITY, DISABLED)) def test_li_consolidate_proposal_no_rights_to_consolidate(self): person = PersonFactory() self.context['user'] = person.user result = li_consolidate_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_consolidate_proposal', MSG_NO_RIGHTS_TO_CONSOLIDATE, DISABLED)) def test_li_consolidate_proposal_not_good_proposal_state(self): self.context['user'] = self._build_user_with_permission_to_consolidate( ) self.proposal.state = ProposalState.SUSPENDED.name self.proposal.save() self.context['proposal'] = self.proposal result = li_consolidate_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_consolidate_proposal', MSG_PROPOSAL_NOT_IN_CONSOLIDATION_ELIGIBLE_STATES, DISABLED)) def test_li_consolidate_proposal_not_attached_to_entity(self): self.context['user'] = self._build_user_with_permission_to_consolidate( ) self.proposal.state = ProposalState.ACCEPTED.name self.proposal.save() self.context['proposal'] = self.proposal result = li_consolidate_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_consolidate_proposal', MSG_CAN_EDIT_PROPOSAL_NO_LINK_TO_ENTITY, DISABLED)) def test_li_consolidate_proposal(self): self.central_manager_person.user.user_permissions \ .add(Permission.objects.get(codename="can_consolidate_learningunit_proposal")) self.context['user'] = self.central_manager_person.user self.proposal.state = ProposalState.ACCEPTED.name self.proposal.save() self.context['proposal'] = self.proposal result = li_consolidate_proposal(self.context, self.url_edit, "") self.assertEqual( result, self._get_result_data_expected_for_proposal( 'link_consolidate_proposal', "", "")) def test_li_delete_all_lu_cannot_delete_learning_unit_year_according_type( self): a_person = create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_delete_learningunit') self.context['user'] = a_person.user lcy_master = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy_master) self.context['learning_unit_year'] = learning_unit_yr result = li_delete_all_lu(self.context, self.url_edit, '', "#modalDeleteLuy") expected = self._get_result_data_expected_delete( "link_delete_lus", MSG_CAN_DELETE_ACCORDING_TO_TYPE) self.assertEqual(result, expected) def test_li_delete_all_lu_everything_ok(self): result = li_delete_all_lu(self.context, self.url_edit, '', "#modalDeleteLuy") expected = { 'class_li': 'disabled', 'load_modal': False, 'url': '#', 'id_li': 'link_delete_lus', 'title': "Vous ne pouvez pas supprimer une unité d'enseignement existant avant 2018", 'text': '', 'data_target': '' } self.assertEqual(result, expected) def test_can_modify_end_year_by_proposal_undefined_group(self): faculty_no_faculty_no_central = PersonFactory() lcy = LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self.assertFalse( can_modify_end_year_by_proposal(learning_unit_yr, faculty_no_faculty_no_central, False)) def test_can_modify_end_year_by_proposal_previous_n_year(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self._end_year_permission_assert(faculty_person, learning_unit_yr) central_person = CentralManagerFactory() self.assertFalse( can_modify_end_year_by_proposal(learning_unit_yr, central_person, False)) def test_can_modify_end_year_by_proposal_n_year(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self._end_year_permission_assert(faculty_person, learning_unit_yr) central_person = CentralManagerFactory() self.assertTrue( can_modify_end_year_by_proposal(learning_unit_yr, central_person, True)) def test_can_modify_end_year_by_proposal_n_year_plus_one(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.next_academic_yr, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.next_academic_yr, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self.assertTrue( can_modify_end_year_by_proposal(learning_unit_yr, faculty_person, True)) central_person = CentralManagerFactory() self.assertTrue( can_modify_end_year_by_proposal(learning_unit_yr, central_person, True)) def test_can_modify_by_proposal_previous_n_year(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.previous_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.previous_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self._modify_permission_assert(faculty_person, learning_unit_yr) central_person = CentralManagerFactory() self.assertFalse( can_modify_by_proposal(learning_unit_yr, central_person, False)) def test_can_modify_by_proposal_n_year(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.current_academic_year, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.current_academic_year, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self._modify_permission_assert(faculty_person, learning_unit_yr) central_person = CentralManagerFactory() self.assertTrue( can_modify_by_proposal(learning_unit_yr, central_person, True)) def test_can_modify_by_proposal_n_year_plus_one(self): faculty_person = FacultyManagerFactory() lcy = LearningContainerYearFactory( academic_year=self.next_academic_yr, container_type=learning_container_year_types.COURSE) learning_unit_yr = LearningUnitYearFactory( academic_year=self.next_academic_yr, subtype=learning_unit_year_subtypes.FULL, learning_unit=LearningUnitFactory(), learning_container_year=lcy) self.assertTrue( can_modify_by_proposal(learning_unit_yr, faculty_person, True)) central_person = CentralManagerFactory() self.assertTrue( can_modify_by_proposal(learning_unit_yr, central_person, True)) def _build_user_with_permission_to_consolidate(self): a_person = PersonFactory() a_person.user.user_permissions.add( Permission.objects.get( codename="can_consolidate_learningunit_proposal")) return a_person.user def _get_result_data_expected_for_proposal(self, id_li, title, class_li): if class_li != "": url = "#" else: url = self.url_edit return { 'load_modal': False, 'id_li': id_li, 'url': url, 'title': title, 'class_li': class_li, 'text': "", 'js_script': "" } def _get_result_data_expected(self, id_li, title='', url="#"): return { 'load_modal': False, 'id_li': id_li, 'url': url, 'title': title, 'class_li': self._get_class(title), 'text': '', 'data_target': '', } def _get_result_data_expected_delete(self, id_li, title='', load_modal=False, data_target='', url="#"): return { 'load_modal': load_modal, 'id_li': id_li, 'url': url, 'title': title, 'class_li': self._get_class(title), 'text': '', 'data_target': data_target, } def _get_class(self, title): return DISABLED if title != '' else '' def _get_result_data_expected_for_proposal_suppression( self, id_li, title, class_li): if class_li != "": url = "#" else: url = self.url_edit return { 'load_modal': False, 'id_li': id_li, 'url': url, 'title': title, 'class_li': class_li, 'text': "", 'data_target': "", } def _end_year_permission_assert(self, a_person, luy): self.assertFalse(can_modify_end_year_by_proposal(luy, a_person, False)) with self.assertRaises(PermissionDenied) as perm_ex: can_modify_end_year_by_proposal(luy, a_person, True) self.assertEqual( '{}'.format(perm_ex.exception), MSG_NOT_ELIGIBLE_TO_MODIFY_END_YEAR_PROPOSAL_ON_THIS_YEAR) def _modify_permission_assert(self, a_person, luy): self.assertFalse(can_modify_by_proposal(luy, a_person, False)) with self.assertRaises(PermissionDenied) as perm_ex: can_modify_by_proposal(luy, a_person, True) self.assertEqual('{}'.format(perm_ex.exception), MSG_NOT_ELIGIBLE_TO_PUT_IN_PROPOSAL_ON_THIS_YEAR)