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_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_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_when_sending_mail(self, mock_send_mail, mock_consolidate): author = PersonFactory() creation_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name) consolidate_proposal(creation_proposal, author=author, send_mail=True) mock_send_mail.assert_called_once_with([author], [creation_proposal])
def test_when_proposal_of_type_creation( self, mock_consolidate_creation_proposal): creation_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name) consolidate_proposal(creation_proposal) mock_consolidate_creation_proposal.assert_called_once_with( creation_proposal)
def test_when_proposal_of_type_creation_and_accepted( self, mock_edit_lu_end_date): creation_proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.CREATION.name) consolidate_proposal(creation_proposal) self.assertFalse( ProposalLearningUnit.objects.filter( pk=creation_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, creation_proposal.learning_unit_year.academic_year) self.assertIsNone(academic_year_arg)
def test_when_proposal_of_type_modification_and_accepted( self, mock_update_learning_unit_with_report): generatorContainer = GenerateContainer(datetime.date.today().year - 2, datetime.date.today().year) proposal = ProposalLearningUnitFactory( state=proposal_state.ProposalState.ACCEPTED.name, type=proposal_type.ProposalType.MODIFICATION.name, learning_unit_year=generatorContainer.generated_container_years[0]. learning_unit_year_full, initial_data={ "learning_unit": {}, "learning_unit_year": {}, "learning_container_year": {} }) consolidate_proposal(proposal) self.assertTrue(mock_update_learning_unit_with_report.called)
def test_when_proposal_is_not_accepted_nor_refused(self): states = (state for state, value in proposal_state.ProposalState.__members__.items() if state not in PROPOSAL_CONSOLIDATION_ELIGIBLE_STATES) for state in states: with self.subTest(state=state): proposal = ProposalLearningUnitFactory(state=state) result = consolidate_proposal(proposal) expected_result = { ERROR: [_("Proposal is neither accepted nor refused.")] } self.assertDictEqual(result, expected_result)
def test_when_proposal_is_not_accepted_nor_refused(self): states = ( state for state, _ in proposal_state.ProposalState.__members__.items() if state not in PROPOSAL_CONSOLIDATION_ELIGIBLE_STATES) for state in states: with self.subTest(state=state): proposal = ProposalLearningUnitFactory(state=state) result = consolidate_proposal(proposal) expected_result = { ERROR: [ _("error_consolidate_proposal").format( acronym=proposal.learning_unit_year.acronym, academic_year=proposal.learning_unit_year. academic_year) ] } self.assertDictEqual(result, expected_result)
def consolidate_proposal(request): learning_unit_year_id = request.POST.get("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_proposal_in_state_to_be_consolidated(proposal): raise PermissionDenied( "Proposal learning unit is neither accepted nor refused.") result = {} try: result = business_proposal.consolidate_proposal(proposal, author=user_person, send_mail=True) display_most_critical_messages(request, result) except IntegrityError as e: display_error_messages(request, e.args[0]) return _consolidate_proposal_redirection(proposal, result)