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_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_when_person_not_linked_to_entity(self): proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, learning_unit_year__learning_container_year__requirement_entity= EntityFactory(), ) self.assertFalse( is_eligible_to_consolidate_proposal( proposal, self.person_with_right_to_consolidate))
def test_when_person_is_linked_to_entity(self): states = (state.name for state in proposal_state.ProposalState if state in (proposal_state.ProposalState.ACCEPTED, proposal_state.ProposalState.REFUSED)) for state in states: with self.subTest(state=state): proposal = ProposalLearningUnitFactory(state=state) entity_container = EntityContainerYearFactory( learning_container_year=proposal.learning_unit_year. learning_container_year, type=entity_container_year_link_type.REQUIREMENT_ENTITY) PersonEntityFactory( person=self.person_with_right_to_consolidate, entity=entity_container.entity) self.assertTrue( is_eligible_to_consolidate_proposal( proposal, self.person_with_right_to_consolidate))
def consolidate_proposal(request, learning_unit_year_id): proposal = get_object_or_404(ProposalLearningUnit, learning_unit_year__id=learning_unit_year_id) user_person = get_object_or_404(Person, user=request.user) if not perms.is_eligible_to_consolidate_proposal(proposal, user_person): raise PermissionDenied("Proposal cannot be consolidated") messages_by_level = {} try: messages_by_level = business_proposal.consolidate_proposals_and_send_report( [proposal], user_person, {}) display_messages_by_level(request, messages_by_level) except IntegrityError as e: display_error_messages(request, e.args[0]) if proposal.type == proposal_type.ProposalType.CREATION.name and \ proposal.state == proposal_state.ProposalState.REFUSED.name and not messages_by_level.get(ERROR, []): return redirect('learning_units') return redirect('learning_unit', learning_unit_year_id=proposal.learning_unit_year.id)
def test_when_person_is_linked_to_entity(self): states = (state.name for state in proposal_state.ProposalState if state in (proposal_state.ProposalState.ACCEPTED, proposal_state.ProposalState.REFUSED)) for state in states: with self.subTest(state=state): proposal = ProposalLearningUnitFactory(state=state) container_year = proposal.learning_unit_year.learning_container_year container_year.requirement_entity = EntityFactory() container_year.save() PersonEntityFactory( person=self.person_with_right_to_consolidate, entity=container_year.requirement_entity) # Refresh permissions self.person_with_right_to_consolidate = Person.objects.get( pk=self.person_with_right_to_consolidate.pk) self.assertTrue( is_eligible_to_consolidate_proposal( proposal, self.person_with_right_to_consolidate))
def test_when_person_not_linked_to_entity(self): proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name) self.assertFalse( is_eligible_to_consolidate_proposal( proposal, self.person_with_right_to_consolidate))