def test_do_not_duplicate_11BA(self):
        TrainingFactory(education_group_type__name=TrainingType.BACHELOR.name,
                        acronym="OSIS11BA")

        postponement = EducationGroupAutomaticPostponementToN6()

        self.assertQuerysetEqual(postponement.queryset, [])
    def test_if_structure_is_postponed(self):
        parent = EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-2],
        )
        mandatory_child = GroupFactory(academic_year=self.academic_years[-2], )
        not_mandatory_child = GroupFactory(
            academic_year=self.academic_years[-2], )
        GroupElementYearFactory(parent=parent, child_branch=mandatory_child)
        GroupElementYearFactory(parent=parent,
                                child_branch=not_mandatory_child)
        AuthorizedRelationshipFactory(
            parent_type=parent.education_group_type,
            child_type=mandatory_child.education_group_type,
            min_count_authorized=1)
        AuthorizedRelationshipFactory(
            parent_type=parent.education_group_type,
            child_type=not_mandatory_child.education_group_type,
            min_count_authorized=0)

        self.assertEqual(EducationGroupYear.objects.count(), 3)

        result, errors = EducationGroupAutomaticPostponementToN6().postpone()

        self.assertEqual(len(result), 1)
        self.assertFalse(errors)

        self.assertEqual(result[0].education_group, self.education_group)
        self.assertEqual(result[0].groupelementyear_set.count(), 1)
    def test_education_group_wrong_mini_training(self):
        egt = EducationGroupTypeFactory(name=MiniTrainingType.OPTION.name,
                                        category=MINI_TRAINING)
        EducationGroupYearFactory(education_group=self.education_group,
                                  academic_year=self.academic_years[-2],
                                  education_group_type=egt)
        queryset = EducationGroupAutomaticPostponementToN6().get_queryset()

        self.assertQuerysetEqual(queryset, [])
 def test_empty_results_and_errors(self):
     result_dict = EducationGroupAutomaticPostponementToN6(
     ).serialize_postponement_results()
     self.assertDictEqual(
         result_dict, {
             "msg": EducationGroupAutomaticPostponementToN6.msg_result % {
                 "number_extended": 0,
                 "number_error": 0
             },
             "errors": []
         })
 def test_with_errors_and_results(self):
     postponement = EducationGroupAutomaticPostponementToN6()
     postponement.result = self.egys[:5]
     postponement.errors = [str(egy) for egy in self.egys[5:]]
     result_dict = postponement.serialize_postponement_results()
     self.assertDictEqual(
         result_dict, {
             "msg": postponement.msg_result % {
                 "number_extended": len(self.egys[:5]),
                 "number_error": len(self.egys[5:])
             },
             "errors": [str(egy) for egy in self.egys[5:]]
         })
    def test_egy_to_duplicate_with_error(self, mock_method):
        mock_method.side_effect = Mock(side_effect=Error("test error"))

        egy_with_error = EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-2],
        )
        self.assertEqual(EducationGroupYear.objects.count(), 1)

        result, errors = EducationGroupAutomaticPostponementToN6().postpone()
        self.assertTrue(mock_method.called)
        self.assertEqual(errors, [egy_with_error.education_group])
        self.assertEqual(len(result), 0)
 def test_egy_already_duplicated(self):
     EducationGroupYearFactory(
         education_group=self.education_group,
         academic_year=self.academic_years[-2],
     )
     EducationGroupYearFactory(
         education_group=self.education_group,
         academic_year=self.academic_years[-1],
     )
     self.assertEqual(EducationGroupYear.objects.count(), 2)
     result, errors = EducationGroupAutomaticPostponementToN6().postpone()
     self.assertEqual(len(result), 0)
     self.assertFalse(errors)
Пример #8
0
    def test_egy_to_not_duplicated(self):
        # The learning unit is over
        self.education_group.end_year = self.academic_years[-2].year
        self.education_group.save()

        EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-2],
        )
        self.assertEqual(EducationGroupYear.objects.count(), 1)
        result, errors = EducationGroupAutomaticPostponementToN6().postpone()
        self.assertEqual(len(result), 0)
        self.assertFalse(errors)
    def test_empty_errors(self):
        postponement = EducationGroupAutomaticPostponementToN6()

        postponement.result = self.egys

        result_dict = postponement.serialize_postponement_results()
        self.assertDictEqual(
            result_dict, {
                "msg": postponement.msg_result % {
                    "number_extended": len(self.egys),
                    "number_error": 0
                },
                "errors": []
            })
Пример #10
0
    def test_fetch_education_group_to_postpone_to_N6(self):
        education_group_years_to_postpone = EducationGroupYearFactory.create_batch(
            2,
            education_group__end_year=None,
            academic_year=self.academic_years[-4])

        result, errors = EducationGroupAutomaticPostponementToN6().postpone()

        self.assertFalse(errors)

        self.assertCountEqual([egy.academic_year for egy in result],
                              [self.academic_years[6]] * 2)
        self.assertCountEqual(
            [egy.education_group for egy in result],
            [egy.education_group for egy in education_group_years_to_postpone])

        self.assertEqual(EducationGroupYear.objects.count(), 8)
Пример #11
0
    def test_egy_to_not_duplicated(self):
        # The education group is over
        self.education_group.end_year = self.academic_years[-2]
        self.education_group.save()

        EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-2],
        )
        self.assertEqual(EducationGroupYear.objects.count(), 1)
        postponement = EducationGroupAutomaticPostponementToN6()

        self.assertQuerysetEqual(postponement.to_duplicate, [])

        result, errors = postponement.postpone()
        self.assertEqual(len(result), 0)
        self.assertFalse(errors)
Пример #12
0
    def apply_education_group_year_postponement(self, request, queryset):
        # Potential circular imports
        from base.business.education_groups.automatic_postponement import EducationGroupAutomaticPostponementToN6
        from base.views.common import display_success_messages, display_error_messages

        result, errors = EducationGroupAutomaticPostponementToN6(queryset).postpone()
        count = len(result)
        display_success_messages(
            request, ngettext(
                "%(count)d education group has been postponed with success.",
                "%(count)d education groups have been postponed with success.", count
            ) % {'count': count}
        )
        if errors:
            display_error_messages(request, "{} : {}".format(
                _("The following education groups ended with error"),
                ", ".join([str(error) for error in errors])
            ))
Пример #13
0
    def test_fetch_education_group_to_postpone_to_N6(self):
        EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-4],
        )
        education_group_to_postpone = EducationGroupYearFactory(
            education_group=self.education_group,
            academic_year=self.academic_years[-3],
        )

        self.assertEqual(EducationGroupYear.objects.count(), 2)

        result, errors = EducationGroupAutomaticPostponementToN6().postpone()

        self.assertEqual(len(result), 2)
        self.assertEqual(EducationGroupYear.objects.count(), 4)

        latest_postponed_egy = result[-1]
        self.assertEqual(latest_postponed_egy.academic_year.year,
                         self.current_year + 6)
        self.assertEqual(latest_postponed_egy.education_group,
                         education_group_to_postpone.education_group)
        self.assertFalse(errors)
Пример #14
0
def extend_education_groups():
    process = EducationGroupAutomaticPostponementToN6()
    process.postpone()
    return process.serialize_postponement_results()