class TestSearch(TestCase): def setUp(self): self.proposal_learning_unit = ProposalLearningUnitFactory() def test_find_by_learning_unit_year(self): a_proposal_learning_unit = proposal_learning_unit.find_by_learning_unit_year( self.proposal_learning_unit.learning_unit_year) self.assertEqual(a_proposal_learning_unit, self.proposal_learning_unit) def test_have_a_proposal(self): a_learning_unit_year = self.proposal_learning_unit.learning_unit_year self.assertTrue( proposal_learning_unit.have_a_proposal(a_learning_unit_year)) self.proposal_learning_unit.delete() self.assertFalse( proposal_learning_unit.have_a_proposal(a_learning_unit_year)) def test_find_by_folder(self): folder = self.proposal_learning_unit.folder self.assertTrue(proposal_learning_unit.find_by_folder(folder)) self.proposal_learning_unit.delete() self.assertFalse(proposal_learning_unit.find_by_folder(folder))
def setUp(self): self.current_academic_year = AcademicYearFactory(year=2017) self.learning_container_luy1 = LearningContainerYearFactory( academic_year=self.current_academic_year) self.learning_unit_yr_1 = LearningUnitYearFactory( academic_year=self.current_academic_year, learning_container_year=self.learning_container_luy1, credits=50) self.learning_unit_yr_2 = LearningUnitYearFactory() self.proposal_creation_1 = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name, ) self.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) self.an_education_group_parent = EducationGroupYearFactory( academic_year=self.current_academic_year, education_group_type=direct_parent_type, acronym=ROOT_ACRONYM) self.group_element_child = GroupElementYearFactory( parent=self.an_education_group_parent, child_branch=None, child_leaf=self.learning_unit_yr_1) self.an_education_group = EducationGroupYearFactory( academic_year=self.current_academic_year, acronym=PARENT_ACRONYM, title=PARENT_TITLE, partial_acronym=PARENT_PARTIAL_ACRONYM) self.group_element_child2 = GroupElementYearFactory( parent=self.an_education_group, child_branch=self.group_element_child.parent, ) generatorContainer = GenerateContainer(datetime.date.today().year - 2, datetime.date.today().year) self.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) ] self.learning_unit_year_with_entities.entities = { 'REQUIREMENT_ENTITY': entities[0], 'ALLOCATION_ENTITY': entities[1] } self.proposal_creation_3 = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year_with_entities, state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name, )
def setUp(self): self.proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, learning_unit_year__learning_container_year__academic_year=self. current_academic_year, learning_unit_year__learning_unit__start_year=self. current_academic_year.year)
def test_change_new_state(self): proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.FACULTY.name) new_state = proposal_state.ProposalState.SUSPENDED.name modify_proposal_state(new_state, proposal) proposal.refresh_from_db() self.assertEqual(proposal.state, new_state)
def test_get_optional_has_proposition(self): optional_data = initialize_optional_data() optional_data['has_proposition'] = True self.assertCountEqual( _get_optional_data([], self.luy, optional_data, self.gey), ['', '']) proposal = ProposalLearningUnitFactory(learning_unit_year=self.luy) self.assertCountEqual( _get_optional_data([], self.luy, optional_data, self.gey), [proposal.get_type_display(), proposal.get_state_display()])
def setUp(self): self.learning_unit = LearningUnitFactory() self.previous_learning_unit = LearningUnitFactory() self.current_academic_year = create_current_academic_year() self.previous_academic_year = AcademicYearFactory( year=settings.YEAR_LIMIT_LUE_MODIFICATION - 1) 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.client.force_login(user=self.central_manager_person.user) 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.previous_proposal = ProposalLearningUnitFactory( learning_unit_year=self.previous_luy_2) self.url_edit = reverse('edit_learning_unit', args=[self.learning_unit_year.id]) self.url_edit_non_editable = reverse( 'edit_learning_unit', args=[self.previous_learning_unit_year.id]) self.context = { "learning_unit_year": self.learning_unit_year, "request": self.request, "user": self.central_manager_person.user, "proposal": self.proposal }
def test_is_not_eligible_for_cancel_of_proposal(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) an_entity = EntityFactory() luy.learning_container_year.requirement_entity = an_entity luy.learning_container_year.save() a_person = create_person_with_permission_and_group() a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.SUPPRESSION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "learning_container_year": { "requirement_entity": an_entity.id, } }) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.type = proposal_type.ProposalType.MODIFICATION.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person))
def test_is_not_eligible_for_cancel_of_proposal(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) an_entity_container_year = EntityContainerYearFactory( learning_container_year=luy.learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) a_person = self.create_person_with_permission_and_group() a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.SUPPRESSION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_entity_container_year.entity.id, } }) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.state = proposal_state.ProposalState.FACULTY.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person)) a_proposal.type = proposal_type.ProposalType.MODIFICATION.name a_proposal.save() self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person))
def setUp(self): self.l_unit_yr_1 = LearningUnitYearFactory(acronym="LBIR1212", learning_container_year=self.l_container_year, academic_year=self.academic_year, subtype=learning_unit_year_subtypes.FULL, credits=10) 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._set_entities()
def test_valid_post_request_with_postponement_and_existing_proposal(self): luy_next_year = LearningUnitYearFactory( learning_unit=self.learning_unit_year.learning_unit, academic_year=AcademicYearFactory(year=self.an_academic_year.year + 1), learning_container_year=self.learning_container_year, acronym="LOSIS4512", subtype=learning_unit_year_subtypes.FULL, attribution_procedure=attribution_procedure.INTERNAL_TEAM, credits=15, campus=CampusFactory(organization=OrganizationFactory(type=organization_type.MAIN)), internship_subtype=None, ) ProposalLearningUnitFactory( learning_unit_year=luy_next_year ) credits = 17 form_data = self._get_valid_form_data() form_data['credits'] = credits form_data['container_type'] = learning_container_year_types.COURSE form_data['postponement'] = 1 # This values triggers postponement switch in view response = self.client.post(self.url, data=form_data) expected_redirection = reverse("learning_unit", args=[self.learning_unit_year.id]) self.assertRedirects(response, expected_redirection) self.learning_unit_year.refresh_from_db() self.assertEqual(self.learning_unit_year.credits, credits) msg = [m.message for m in get_messages(response.wsgi_request) if m.level == messages.SUCCESS] self.assertEqual( msg[0], _('The learning unit has been updated (the report has not been done from %(year)s because the learning ' 'unit is in proposal).') % {'year': luy_next_year.academic_year} )
def test_return_modification_when_no_data_changed(self): proposal = ProposalLearningUnitFactory( type=ProposalType.MODIFICATION.name, initial_data={}) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.MODIFICATION.name, actual_proposal_type)
def setUpTestData(cls): cls.current_academic_year = create_current_academic_year() cls.proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, learning_unit_year__subtype=learning_unit_year_subtypes.FULL, learning_unit_year__academic_year=cls.current_academic_year, learning_unit_year__learning_container_year__academic_year=cls. current_academic_year) cls.learning_unit_year = cls.proposal.learning_unit_year cls.person = PersonFactory() cls.person.user.user_permissions.add( Permission.objects.get(codename="can_access_learningunit")) cls.person.user.user_permissions.add( Permission.objects.get( codename="can_consolidate_learningunit_proposal")) person_entity = PersonEntityFactory( person=cls.person, entity=EntityContainerYearFactory( learning_container_year=cls.learning_unit_year. learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY).entity ) EntityVersionFactory(entity=person_entity.entity) cls.url = reverse("learning_unit_consolidate_proposal") cls.post_data = {"learning_unit_year_id": cls.learning_unit_year.id}
def test_when_person_has_right_to_consolidate_but_proposal_state_is_neither_accepted_nor_refused(self): states = (state.name for state in proposal_state.ProposalState if state not in (proposal_state.ProposalState.ACCEPTED, proposal_state.ProposalState.REFUSED)) for state in states: with self.subTest(state=state): proposal = ProposalLearningUnitFactory(state=state) self.assertFalse(is_eligible_to_consolidate_proposal(proposal, self.person_with_right_to_consolidate))
def test_find_distinct_folder_entities(self): entity_2 = EntityFactory() ProposalLearningUnitFactory(entity=entity_2) entities_result = proposal_learning_unit.find_distinct_folder_entities( ) self.assertCountEqual(entities_result, [self.entity_1, entity_2])
def step_impl(context, acronym, year, entity): ac = AcademicYear.objects.get(year=year[:4]) luy = LearningUnitYearFactory(acronym=acronym, academic_year=ac) entity = Entity.objects.filter(entityversion__acronym=entity).last() ProposalLearningUnitFactory(learning_unit_year=luy, entity=entity, folder_id=12)
def test_when_person_has_no_right_to_consolidate(self): proposal_in_state_accepted = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name) self.assertFalse( is_eligible_to_consolidate_proposal( proposal_in_state_accepted, self.person_without_right_to_consolidate))
def test_when_proposal_of_type_modification_and_accepted_with_partim(self): old_academic_year = AcademicYearFactory( year=datetime.date.today().year - 2) current_academic_year = AcademicYearFactory( year=datetime.date.today().year) generator_container = GenerateContainer(old_academic_year, current_academic_year) generator_container.generated_container_years[ 0].learning_unit_year_full.learning_unit.end_year = None LearningUnitYearPartimFactory( learning_container_year=generator_container. generated_container_years[0].learning_unit_year_full. learning_container_year, academic_year=generator_container.generated_container_years[0]. learning_unit_year_full.academic_year) proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.MODIFICATION.name, learning_unit_year=generator_container. generated_container_years[0].learning_unit_year_full, initial_data=copy_learning_unit_data( generator_container.generated_container_years[0]. learning_unit_year_full)) consolidate_proposal(proposal) partim = proposal.learning_unit_year.get_partims_related() self.assertEqual(proposal.learning_unit_year.acronym, partim[0].acronym[:-1])
def test_is_eligible_for_cancel_of_proposal_wrong_state(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year.entity luy = generated_container_first_year.learning_unit_year_full a_person = self.create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit') a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "entities": { entity_container_year_link_type.REQUIREMENT_ENTITY: an_requirement_entity.id, } }) PersonEntityFactory(person=a_person, entity=an_requirement_entity) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, a_person))
def setUp(self): self.user = UserFactory() generatorContainer = GenerateContainer(datetime.date.today().year, datetime.date.today().year) self.partim = generatorContainer.generated_container_years[ 0].learning_unit_year_partim self.learning_unit_year_1 = generatorContainer.generated_container_years[ 0].learning_unit_year_full self.entity_1 = generatorContainer.entities[0] self.entity_version_1 = EntityVersionFactory(entity=self.entity_1, acronym="AGRO") self.entity_2 = generatorContainer.entities[0] self.entity_version_2 = EntityVersionFactory(entity=self.entity_2, acronym="DRT") self.learning_unit_year_1.entities = { REQUIREMENT_ENTITY: self.entity_version_1, ALLOCATION_ENTITY: self.entity_version_1, ADDITIONAL_REQUIREMENT_ENTITY_1: self.entity_version_2 } self.academic_year = self.learning_unit_year_1.academic_year self.proposal = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year_1, initial_data={"learning_unit": { "faculty_remark": "First remark" }})
def test_postponement_with_proposal(self): next_academic_year = AcademicYear.objects.get( year=self.learning_unit_year_full.academic_year.year + 2) luy = LearningUnitYear.objects.filter( academic_year=next_academic_year, learning_unit=self.learning_unit_year_full.learning_unit).get() ProposalLearningUnitFactory(learning_unit_year=luy) msg_proposal = _("learning_unit_in_proposal_cannot_save") % { 'luy': luy.acronym, 'academic_year': next_academic_year } expected_result = OrderedDict({ next_academic_year: [msg_proposal], }) instance_luy_base_form = _instantiate_base_learning_unit_form( self.learning_unit_year_full, self.person) form = _instanciate_postponement_form( self.person, self.learning_unit_year_full.academic_year, learning_unit_instance=instance_luy_base_form. learning_unit_instance, data=instance_luy_base_form.data) self.assertTrue(form.is_valid(), form.errors) result = form.consistency_errors self.assertIsInstance( result, OrderedDict) # Need to be ordered by academic_year self.assertEqual(expected_result[next_academic_year], result[next_academic_year])
def test_when_proposal_of_type_suppression_and_accepted( self, mock_edit_lu_end_date): academic_years = create_academic_years() initial_end_year_index = 2 suppression_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.SUPPRESSION.name, initial_data={ "learning_unit": { "end_year": academic_years[initial_end_year_index].year } }) random_end_acad_year_index = fuzzy.FuzzyInteger( initial_end_year_index + 1, len(academic_years) - 1).fuzz() suppression_proposal.learning_unit_year.learning_unit.end_year = academic_years[ random_end_acad_year_index].year suppression_proposal.learning_unit_year.learning_unit.save() consolidate_proposal(suppression_proposal) self.assertFalse( ProposalLearningUnit.objects.filter( pk=suppression_proposal.pk).exists()) self.assertTrue(mock_edit_lu_end_date.called) lu_arg, academic_year_arg = mock_edit_lu_end_date.call_args[0] self.assertEqual( lu_arg.end_year, suppression_proposal.initial_data["learning_unit"]["end_year"]) suppression_proposal.learning_unit_year.learning_unit.refresh_from_db() self.assertEqual( academic_year_arg.year, suppression_proposal.learning_unit_year.learning_unit.end_year)
def test_when_proposal_is_refused(self, mock_cancel_proposal): proposal_refused = ProposalLearningUnitFactory( state=proposal_state.ProposalState.REFUSED.name) consolidate_proposal(proposal_refused) mock_cancel_proposal.assert_called_once_with(proposal_refused)
def test_is_eligible_for_cancel_of_proposal_wrong_state(self): generated_container = GenerateContainer( start_year=self.academic_yr.year, end_year=self.academic_yr.year) generated_container_first_year = generated_container.generated_container_years[ 0] an_requirement_entity = generated_container_first_year.requirement_entity_container_year luy = generated_container_first_year.learning_unit_year_full faculty_managers = [ create_person_with_permission_and_group( FACULTY_MANAGER_GROUP, 'can_propose_learningunit'), create_person_with_permission_and_group( UE_FACULTY_MANAGER_GROUP, 'can_propose_learningunit') ] a_proposal = ProposalLearningUnitFactory( learning_unit_year=luy, type=proposal_type.ProposalType.MODIFICATION.name, state=proposal_state.ProposalState.CENTRAL.name, initial_data={ "learning_container_year": { "requirement_entity": an_requirement_entity.id, } }) for manager in faculty_managers: PersonEntityFactory(person=manager, entity=an_requirement_entity) self.assertFalse( perms.is_eligible_for_cancel_of_proposal(a_proposal, manager))
def test_cannot_modify_learning_unit_on_modification_proposal(self): ProposalLearningUnitFactory(learning_unit_year=self.learning_unit_year) response = self.client.get(self.url) self.assertTemplateUsed(response, "access_denied.html") self.assertEqual(response.status_code, HttpResponseForbidden.status_code)
def test_learning_unit_proposal_form_get_as_central_manager_with_instance(self): self.person.user.groups.add(Group.objects.get(name=CENTRAL_MANAGER_GROUP)) proposal = ProposalLearningUnitFactory( learning_unit_year=self.learning_unit_year, state=ProposalState.FACULTY.name, entity=self.entity_version.entity) form = ProposalBaseForm(self.form_data, self.person, self.learning_unit_year, proposal=proposal) self.assertFalse(form.fields['state'].disabled) self.assertEqual(form.fields['state'].initial, ProposalState.FACULTY.name)
def test_template_used_for_get_request_learning_unit_on_modification_proposal( self): ProposalLearningUnitFactory(learning_unit_year=self.learning_unit_year) response = self.client.get(self.url) self.assertTemplateUsed(response, "learning_unit/simple/update.html") self.assertEqual(response.status_code, HttpResponse.status_code)
def setUp(self): self.author = PersonFactory() self.proposals = [ProposalLearningUnitFactory() for _ in range(2)] person_entity = PersonEntityFactory(person=self.author) for proposal in self.proposals: container_year = proposal.learning_unit_year.learning_container_year container_year.requirement_entity = person_entity.entity container_year.save()
def test_return_suppression_type_when_suppresion_is_initial_proposal_type( self): proposal = ProposalLearningUnitFactory( type=ProposalType.SUPPRESSION.name) actual_proposal_type = compute_proposal_type( proposal, proposal.learning_unit_year) self.assertEqual(proposal_type.ProposalType.SUPPRESSION.name, actual_proposal_type)
def test_can_only_propose_modification_for_lu_which_is_not_in_proposition_on_different_year(self): past_luy_with_proposal = LearningUnitYearFakerFactory( learning_container_year__academic_year=self.past_academic_year, learning_unit=self.luy.learning_unit ) ProposalLearningUnitFactory(learning_unit_year=past_luy_with_proposal) self.assertFalse(is_eligible_to_create_modification_proposal(self.luy, self.person))
def test_access_edit_learning_unit_proposal_as_central_manager(self): luy = LearningUnitYearFactory(academic_year=self.academic_yr) a_person = self.create_person_with_permission_and_group(CENTRAL_MANAGER_GROUP) self.assertFalse(perms.is_eligible_to_edit_proposal(None, a_person)) a_proposal = ProposalLearningUnitFactory(learning_unit_year=luy) self.assertTrue(perms.is_eligible_to_edit_proposal(a_proposal, a_person))