def test_call_method_consolidate_proposal(self, mock_mail, mock_consolidate_proposal, mock_perm): result = consolidate_proposals_and_send_report(self.proposals, self.author, []) consolidate_args_list = [((self.proposals[0], ), ), ((self.proposals[1], ), )] self.assertListEqual(mock_consolidate_proposal.call_args_list, consolidate_args_list) self.assertDictEqual( result, { INFO: [_("A report has been sent.")], ERROR: [], SUCCESS: [ _("Proposal %(acronym)s (%(academic_year)s) successfully consolidated." ) % { "acronym": proposal.learning_unit_year.acronym, "academic_year": proposal.learning_unit_year.academic_year } for proposal in self.proposals ] }) self.assertTrue(mock_mail.called) self.assertTrue(mock_perm.called)
def apply_action_on_proposals(proposals, author, post_data, research_criteria): if not bool(proposals): return {WARNING: [_("No proposals was selected.")]} action = post_data.get("action", "") messages_by_level = {} if action == ACTION_BACK_TO_INITIAL: messages_by_level = proposal_business.cancel_proposals_and_send_report(proposals, author, research_criteria) elif action == ACTION_CONSOLIDATE: messages_by_level = proposal_business.consolidate_proposals_and_send_report(proposals, author, research_criteria) elif action == ACTION_FORCE_STATE: form = ProposalStateModelForm(post_data) if form.is_valid(): new_state = form.cleaned_data.get("state") messages_by_level = proposal_business.force_state_of_proposals(proposals, author, new_state) return messages_by_level
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)