def test_empty_results_and_errors(self): result_dict = LearningUnitAutomaticPostponementToN6().serialize_postponement_results() self.assertDictEqual(result_dict, { "msg": LearningUnitAutomaticPostponementToN6.msg_result % { "number_extended": 0, "number_error": 0 }, "errors": [] })
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 = LearningUnitAutomaticPostponementToN6().postpone() self.assertEqual(len(result), 1) self.assertFalse(errors)
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 = LearningUnitAutomaticPostponementToN6().postpone() self.assertEqual(errors, [luy_with_error.learning_unit]) self.assertEqual(len(result), 0)
def test_with_errors_and_results(self): postponement = LearningUnitAutomaticPostponementToN6() postponement.result = self.luys[:5] postponement.errors = [str(luy) for luy in self.luys[5:]] result_dict = postponement.serialize_postponement_results() self.assertDictEqual(result_dict, { "msg": postponement.msg_result % { "number_extended": len(self.luys[:5]), "number_error": len(self.luys[5:]) }, "errors": [str(luy) for luy in self.luys[5:]] })
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 = LearningUnitAutomaticPostponementToN6().postpone() self.assertEqual(len(result), 0) 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 = LearningUnitAutomaticPostponementToN6().postpone() self.assertEqual(len(result), 0) self.assertFalse(errors)
def test_empty_errors(self): postponement = LearningUnitAutomaticPostponementToN6() postponement.result = self.luys result_dict = postponement.serialize_postponement_results() self.assertDictEqual(result_dict, { "msg": postponement.msg_result % { "number_extended": len(self.luys), "number_error": 0 }, "errors": [] })
def apply_learning_unit_year_postponement(self, request, queryset): # Potential circular imports from base.business.learning_units.automatic_postponement import LearningUnitAutomaticPostponementToN6 from base.views.common import display_success_messages, display_error_messages result, errors = LearningUnitAutomaticPostponementToN6(queryset).postpone() count = len(result) display_success_messages( request, ngettext( '%(count)d learning unit has been postponed with success', '%(count)d learning units have been postponed with success', count ) % {'count': count} ) if errors: display_error_messages(request, "{} : {}".format( _("The following learning units ended with error"), ", ".join([str(error) for error in errors]) ))
def extend_learning_units(): process = LearningUnitAutomaticPostponementToN6() process.postpone() return process.serialize_postponement_results()