示例#1
0
def create_learning_unit_enrollment(learning_unit_year, offer_enrollment):
    return LearningUnitEnrollmentFactory(learning_unit_year=learning_unit_year,
                                         offer_enrollment=offer_enrollment)
示例#2
0
    def test_check_related_partims_deletion(self):
        l_container_year = LearningContainerYearFactory()
        LearningUnitYearFactory(acronym="LBIR1212",
                                learning_container_year=l_container_year,
                                academic_year=self.academic_year,
                                subtype=learning_unit_year_subtypes.FULL,
                                learning_unit=self.learning_unit)
        msg = deletion._check_related_partims_deletion(l_container_year)
        self.assertEqual(len(msg.values()), 0)

        l_unit_2 = LearningUnitYearFactory(
            acronym="LBIR1213",
            learning_container_year=l_container_year,
            academic_year=self.academic_year,
            subtype=learning_unit_year_subtypes.PARTIM)

        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)
        LearningUnitEnrollmentFactory(learning_unit_year=l_unit_2)

        group_1 = GroupElementYearFactory(child_branch=None,
                                          child_leaf=l_unit_2)
        group_2 = GroupElementYearFactory(child_branch=None,
                                          child_leaf=l_unit_2)

        component = LearningComponentYearFactory(learning_unit_year=l_unit_2)

        attribution_1 = AttributionNewFactory(
            learning_container_year=l_unit_2.learning_container_year)
        attribution_2 = AttributionNewFactory(
            learning_container_year=l_unit_2.learning_container_year)

        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_1)
        AttributionChargeNewFactory(learning_component_year=component,
                                    attribution=attribution_2)

        msg = deletion._check_related_partims_deletion(l_container_year)
        msg = list(msg.values())

        self.assertEqual(len(msg), 5)
        self.assertIn(
            _("There is %(count)d enrollments in %(subtype)s %(acronym)s for the year %(year)s"
              ) % {
                  'subtype': _('The partim'),
                  'acronym': l_unit_2.acronym,
                  'year': l_unit_2.academic_year,
                  'count': 3
              }, msg)

        msg_delete_tutor = _(
            "%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s"
        )
        self.assertIn(
            msg_delete_tutor % {
                'subtype': _('The partim'),
                'acronym': l_unit_2.acronym,
                'year': l_unit_2.academic_year,
                'tutor': attribution_1.tutor
            }, msg)
        self.assertIn(
            msg_delete_tutor % {
                'subtype': _('The partim'),
                'acronym': l_unit_2.acronym,
                'year': l_unit_2.academic_year,
                'tutor': attribution_2.tutor
            }, msg)

        msg_delete_offer_type = _(
            '%(subtype)s %(acronym)s is included in the group %(group)s for the year %(year)s'
        )

        self.assertIn(
            msg_delete_offer_type % {
                'subtype': _('The partim'),
                'acronym': l_unit_2.acronym,
                'group': group_1.parent.partial_acronym,
                'year': l_unit_2.academic_year
            }, msg)
        self.assertIn(
            msg_delete_offer_type % {
                'subtype': _('The partim'),
                'acronym': l_unit_2.acronym,
                'group': group_2.parent.partial_acronym,
                'year': l_unit_2.academic_year
            }, msg)