Exemple #1
0
def _create_attribution_charge(academic_year,
                               attribution,
                               l_acronym,
                               volume_cm=None,
                               volume_tp=None):
    from base.models.learning_unit_component import LearningUnitComponent

    if volume_cm is not None:
        l_unit_component = LearningUnitComponent.objects.filter(
            learning_unit_year__acronym=l_acronym,
            learning_unit_year__academic_year=academic_year,
            learning_component_year__type=learning_component_year_type.
            LECTURING).first()
        AttributionChargeNewFactory(
            attribution=attribution,
            learning_component_year=l_unit_component.learning_component_year,
            allocation_charge=volume_cm)

    if volume_tp is not None:
        l_unit_component = LearningUnitComponent.objects.filter(
            learning_unit_year__acronym=l_acronym,
            learning_unit_year__academic_year=academic_year,
            learning_component_year__type=learning_component_year_type.
            PRACTICAL_EXERCISES).first()
        AttributionChargeNewFactory(
            attribution=attribution,
            learning_component_year=l_unit_component.learning_component_year,
            allocation_charge=volume_tp)
class TestChargeRepartitionMixin:
    @classmethod
    def setUpTestData(cls):
        cls.learning_unit_year = LearningUnitYearPartimFactory()
        cls.lecturing_unit_component = LecturingLearningUnitComponentFactory(
            learning_unit_year=cls.learning_unit_year)
        cls.practical_unit_component = PracticalLearningUnitComponentFactory(
            learning_unit_year=cls.learning_unit_year)

        cls.full_learning_unit_year = LearningUnitYearFullFactory(
            learning_container_year=cls.learning_unit_year.
            learning_container_year,
            academic_year=cls.learning_unit_year.academic_year)
        cls.lecturing_unit_component_full = LecturingLearningUnitComponentFactory(
            learning_unit_year=cls.full_learning_unit_year)
        cls.practical_unit_component_full = PracticalLearningUnitComponentFactory(
            learning_unit_year=cls.full_learning_unit_year)
        cls.person = PersonWithPermissionsFactory('can_access_learningunit')

    def setUp(self):
        self.attribution = AttributionNewFactory(
            learning_container_year=self.learning_unit_year.
            learning_container_year)
        attribution_id = self.attribution.id
        self.charge_lecturing = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.lecturing_unit_component.
            learning_component_year)
        self.charge_practical = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.practical_unit_component.
            learning_component_year)

        self.attribution_full = self.attribution
        self.attribution_full.id = None
        self.attribution_full.save()
        self.charge_lecturing_full = AttributionChargeNewFactory(
            attribution=self.attribution_full,
            learning_component_year=self.lecturing_unit_component_full.
            learning_component_year)
        self.charge_practical_full = AttributionChargeNewFactory(
            attribution=self.attribution_full,
            learning_component_year=self.practical_unit_component_full.
            learning_component_year)

        self.attribution = AttributionNew.objects.get(id=attribution_id)
        self.client.force_login(self.person.user)

        self.patcher = patch.object(RulesRequiredMixin,
                                    "test_func",
                                    return_value=True)
        self.mocked_permission_function = self.patcher.start()

    def tearDown(self):
        self.patcher.stop()

    def clean_partim_charges(self):
        self.charge_practical.delete()
        self.charge_lecturing.delete()
        self.attribution.delete()
Exemple #3
0
    def setUp(self):

        self.learning_unit_year = LearningUnitYearFullFactory(
            learning_container_year = self.learning_container_year
        )
        self.lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=self.learning_unit_year)
        self.practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=self.learning_unit_year)
        self.attribution = AttributionNewFactory(
            learning_container_year=self.learning_unit_year.learning_container_year
        )
        self.charge_lecturing = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.lecturing_component
        )
        self.charge_practical = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.practical_component
        )

        self.client.force_login(self.person.user)
        self.url = reverse("update_attribution", args=[self.learning_unit_year.id, self.attribution.id])

        self.patcher = patch.object(RulesRequiredMixin, "test_func", return_value=True)
        self.mocked_permission_function = self.patcher.start()
    def setUpTestData(cls):
        cls.education_group_year = EducationGroupYearFactory()
        cls.child_leaves = GroupElementYearChildLeafFactory.create_batch(
            2, parent=cls.education_group_year, is_mandatory=True)
        for node, acronym in zip(
                cls.child_leaves,
            ["LCORS124" + str(i) for i in range(0, len(cls.child_leaves))]):
            node.child_leaf.acronym = acronym
            node.child_leaf.save()

        cls.luy_children = [child.child_leaf for child in cls.child_leaves]
        cls.workbook_contains = \
            EducationGroupYearLearningUnitsContainedToExcel(cls.education_group_year, CustomXlsForm({}))._to_workbook()
        cls.sheet_contains = cls.workbook_contains.worksheets[0]

        generator_container = GenerateContainer(
            cls.education_group_year.academic_year,
            cls.education_group_year.academic_year)
        cls.luy = generator_container.generated_container_years[
            0].learning_unit_year_full

        cls.lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.person_1 = PersonFactory(last_name='Dupont',
                                     first_name="Marcel",
                                     email="*****@*****.**")
        cls.person_2 = PersonFactory(last_name='Marseillais',
                                     first_name="Pol",
                                     email="*****@*****.**")
        cls.tutor_1 = TutorFactory(person=cls.person_1)
        cls.tutor_2 = TutorFactory(person=cls.person_2)
        cls.attribution_1 = AttributionNewFactory(
            tutor=cls.tutor_1,
            learning_container_year=cls.luy.learning_container_year)
        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_1,
            learning_component_year=cls.lecturing_component)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_1,
            learning_component_year=cls.practical_component)
        cls.attribution_2 = AttributionNewFactory(
            tutor=cls.tutor_2,
            learning_container_year=cls.luy.learning_container_year)
        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_2,
            learning_component_year=cls.lecturing_component)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_2,
            learning_component_year=cls.practical_component)
        cls.gey = GroupElementYearChildLeafFactory(child_leaf=cls.luy)
 def setUp(self):
     self.person = PersonFactory(first_name="John", last_name="Doe")
     self.tutor = TutorFactory(person=self.person)
     self.attribution_new = AttributionNewFactory(tutor=self.tutor, function=function.PROFESSOR)
     self.attribution_new_without_attribution_charge = AttributionNewFactory(tutor=self.tutor,
                                                                             function=function.PROFESSOR)
     self.learning_component_year_lecturing = LearningComponentYearFactory(type=component_type.LECTURING)
     self.learning_component_year_practical = LearningComponentYearFactory(type=component_type.PRACTICAL_EXERCISES)
     self.attribution_charge_new_lecturing = \
         AttributionChargeNewFactory(attribution=self.attribution_new,
                                     learning_component_year=self.learning_component_year_lecturing,
                                     allocation_charge=10)
     self.attribution_charge_new_practical = \
         AttributionChargeNewFactory(attribution=self.attribution_new,
                                     learning_component_year=self.learning_component_year_practical,
                                     allocation_charge=20)
class AttributionChargeNewTest(TestCase):
    def setUp(self):
        self.person = PersonFactory(first_name="John", last_name="Doe")
        self.tutor = TutorFactory(person=self.person)
        self.attribution_new = AttributionNewFactory(tutor=self.tutor, function=function.PROFESSOR)
        self.attribution_new_without_attribution_charge = AttributionNewFactory(tutor=self.tutor,
                                                                                function=function.PROFESSOR)
        self.learning_component_year_lecturing = LearningComponentYearFactory(type=component_type.LECTURING)
        self.learning_component_year_practical = LearningComponentYearFactory(type=component_type.PRACTICAL_EXERCISES)
        self.attribution_charge_new_lecturing = \
            AttributionChargeNewFactory(attribution=self.attribution_new,
                                        learning_component_year=self.learning_component_year_lecturing,
                                        allocation_charge=10)
        self.attribution_charge_new_practical = \
            AttributionChargeNewFactory(attribution=self.attribution_new,
                                        learning_component_year=self.learning_component_year_practical,
                                        allocation_charge=20)
    def test_search_with_attribution(self):
        result = attribution_charge_new.search(attribution=self.attribution_new)
        self.assertCountEqual(result, [self.attribution_charge_new_lecturing, self.attribution_charge_new_practical])

    def test_search_with_learning_component_year(self):
        result = attribution_charge_new.search(learning_component_year=self.learning_component_year_practical)
        self.assertCountEqual(result, [self.attribution_charge_new_practical])

    def test_search_with_learning_component_year_list(self):
        learning_component_year_list = [self.learning_component_year_lecturing, self.learning_component_year_practical]
        result = attribution_charge_new.search(learning_component_year=learning_component_year_list)
        self.assertCountEqual(result, [self.attribution_charge_new_practical, self.attribution_charge_new_lecturing])

    def test_str_function(self):
        self.assertEqual(self.attribution_charge_new_lecturing.__str__(), "DOE, John - PROFESSOR")
Exemple #7
0
    def setUpTestData(cls):
        cls.person = PersonWithPermissionsFactory('can_access_learningunit')

        cls.luy_without_attribution = LearningUnitYearFullFactory()

        cls.luy = LearningUnitYearFullFactory()

        cls.lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.attribution = AttributionNewFactory(
            learning_container_year=cls.luy.learning_container_year)
        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution,
            learning_component_year=cls.lecturing_component)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution,
            learning_component_year=cls.practical_component)
    def test_should_exclude_attributions_for_which_repartition_has_been_done(
            self):
        attribution = self.attribution_full
        attribution.id = None
        attribution.save()

        charge_lecturing = AttributionChargeNewFactory(
            attribution=attribution,
            learning_component_year=self.lecturing_unit_component.
            learning_component_year)
        charge_practical = AttributionChargeNewFactory(
            attribution=attribution,
            learning_component_year=self.practical_unit_component.
            learning_component_year)

        response = self.client.get(self.url)

        context = response.context
        self.assertQuerysetEqual(context["attributions"], [])
Exemple #9
0
    def setUpTestData(cls):
        cls.attribution_charge = AttributionChargeNewFactory()
        cls.attribution = AttributionNew.objects.annotate(
            first_name=F('tutor__person__first_name'),
            middle_name=F('tutor__person__middle_name'),
            last_name=F('tutor__person__last_name'),
            email=F('tutor__person__email'),
            global_id=F('tutor__person__global_id'),
        ).get(id=cls.attribution_charge.attribution_id)

        cls.serializer = LearningUnitAttributionSerializer(cls.attribution)
Exemple #10
0
    def setUpTestData(cls):
        cls.full_luy = LearningUnitYearFullFactory()
        cls.partim_luy_1 = LearningUnitYearPartimFactory(
            academic_year=cls.full_luy.academic_year,
            learning_container_year=cls.full_luy.learning_container_year)
        cls.partim_luy_2 = LearningUnitYearPartimFactory(
            academic_year=cls.full_luy.academic_year,
            learning_container_year=cls.full_luy.learning_container_year)
        cls.attribution_full = AttributionNewFactory(
            learning_container_year=cls.full_luy.learning_container_year)
        cls.full_lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=cls.full_luy)
        cls.full_practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=cls.full_luy)

        cls.partim_1_lecturing_component = \
            LecturingLearningComponentYearFactory(learning_unit_year=cls.partim_luy_1)
        cls.partim_1_practical_component = \
            PracticalLearningComponentYearFactory(learning_unit_year=cls.partim_luy_1)

        cls.partim_2_lecturing_component = \
            LecturingLearningComponentYearFactory(learning_unit_year=cls.partim_luy_2)
        cls.partim_2_practical_component = \
            PracticalLearningComponentYearFactory(learning_unit_year=cls.partim_luy_2)

        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_full,
            learning_component_year=cls.full_lecturing_component,
            allocation_charge=20)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_full,
            learning_component_year=cls.full_practical_component,
            allocation_charge=20)

        cls.attribution_partim_1 = cls.attribution_full
        cls.attribution_partim_1.id = None
        cls.attribution_partim_1.save()

        cls.attribution_partim_2 = cls.attribution_full
        cls.attribution_partim_2.id = None
        cls.attribution_partim_2.save()
 def setUp(self):
     self.academic_year = AcademicYearFactory(year=timezone.now().year)
     self.l_unit_1 = LearningUnitYearFactory(
         acronym="LBIR1212",
         academic_year=self.academic_year,
         subtype=learning_unit_year_subtypes.FULL)
     component = LearningComponentYearFactory(
         learning_unit_year=self.l_unit_1)
     self.attribution_charge_news = [
         AttributionChargeNewFactory(learning_component_year=component)
         for _ in range(5)
     ]
def _create_attribution_charge(academic_year,
                               attribution,
                               l_acronym,
                               volume_cm=None,
                               volume_tp=None):
    component_qs = LearningComponentYear.objects.filter(
        learning_unit_year__acronym=l_acronym,
        learning_unit_year__academic_year=academic_year)
    if volume_cm is not None:
        component = component_qs.filter(
            type=learning_component_year_type.LECTURING).first()
        AttributionChargeNewFactory(attribution=attribution,
                                    learning_component_year=component,
                                    allocation_charge=volume_cm)

    if volume_tp is not None:
        component = component_qs.filter(
            type=learning_component_year_type.PRACTICAL_EXERCISES).first()
        AttributionChargeNewFactory(attribution=attribution,
                                    learning_component_year=component,
                                    allocation_charge=volume_tp)
Exemple #13
0
 def setUpTestData(cls):
     cls.academic_year = AcademicYearFactory(current=True)
     cls.l_unit_1 = LearningUnitYearFactory(
         acronym="LBIR1212",
         academic_year=cls.academic_year,
         subtype=learning_unit_year_subtypes.FULL)
     component = LearningComponentYearFactory(
         learning_unit_year=cls.l_unit_1)
     cls.attribution_charge_news = [
         AttributionChargeNewFactory(learning_component_year=component)
         for _ in range(5)
     ]
Exemple #14
0
    def setUp(self):
        self.attribution = AttributionNewFactory(
            learning_container_year=self.learning_unit_year.
            learning_container_year)
        attribution_id = self.attribution.id
        self.charge_lecturing = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.lecturing_component)
        self.charge_practical = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.practical_component)

        self.attribution_full = self.attribution
        self.attribution_full.id = None
        self.attribution_full.save()
        self.charge_lecturing_full = AttributionChargeNewFactory(
            attribution=self.attribution_full,
            learning_component_year=self.lecturing_component_full)
        self.charge_practical_full = AttributionChargeNewFactory(
            attribution=self.attribution_full,
            learning_component_year=self.practical_component_full)

        self.attribution = AttributionNew.objects.get(id=attribution_id)
        self.client.force_login(self.person.user)

        self.patcher = patch.object(RulesRequiredMixin,
                                    "test_func",
                                    return_value=True)
        self.mocked_permission_function = self.patcher.start()
        self.addCleanup(self.patcher.stop)
Exemple #15
0
 def setUpTestData(cls):
     cls.person = PersonWithPermissionsFactory('can_access_learningunit')
     cls.learning_container_year = LearningContainerYearFactory(
         container_type=LearningContainerYearType.COURSE.name
     )
     cls.learning_unit_year = LearningUnitYearFullFactory(
         learning_container_year=cls.learning_container_year
     )
     cls.lecturing_component = LecturingLearningComponentYearFactory(
         learning_unit_year=cls.learning_unit_year)
     cls.practical_component = PracticalLearningComponentYearFactory(
         learning_unit_year=cls.learning_unit_year)
     cls.attribution = AttributionNewFactory(
         learning_container_year=cls.learning_unit_year.learning_container_year
     )
     cls.charge_lecturing = AttributionChargeNewFactory(
         attribution=cls.attribution,
         learning_component_year=cls.lecturing_component
     )
     cls.charge_practical = AttributionChargeNewFactory(
         attribution=cls.attribution,
         learning_component_year=cls.practical_component
     )
Exemple #16
0
    def setUp(self):
        generator_container = GenerateContainer(datetime.date.today().year-2, datetime.date.today().year)
        self.learning_unit_yr_1 = generator_container.generated_container_years[0].learning_unit_year_full

        self.learning_unit_yr_1.entities = {
            entity_container_year_link_type.REQUIREMENT_ENTITY: EntityVersionFactory(acronym=ACRONYM_REQUIREMENT),
            entity_container_year_link_type.ALLOCATION_ENTITY: EntityVersionFactory(acronym=ACRONYM_ALLOCATION)
        }

        component_1 = LearningUnitComponentFactory(learning_unit_year=self.learning_unit_yr_1)
        self.attribution_1 = AttributionChargeNewFactory(learning_component_year=component_1.learning_component_year)
        self.learning_unit_yr_1.attribution_charge_news = attribution_charge_new. \
            find_attribution_charge_new_by_learning_unit_year(self.learning_unit_yr_1)
        self.user = UserFactory()
Exemple #17
0
    def test_delete_all_learning_units_year_case_error_have_attributionnew_with_charge(
            self):
        learning_unit_years = self.learning_unit_year_list
        ly1 = learning_unit_years[1]
        attrib_new_1 = AttributionNewFactory(
            learning_container_year=ly1.learning_container_year)
        learning_component_year_1 = LearningComponentYearFactory(
            learning_unit_year=ly1)
        AttributionChargeNewFactory(
            attribution=attrib_new_1,
            learning_component_year=learning_component_year_1)

        request_factory = RequestFactory()

        request = request_factory.post(
            reverse(delete_all_learning_units_year, args=[ly1.id]))
        request.user = self.user

        setattr(request, 'session', 'session')
        setattr(request, '_messages', FallbackStorage(request))

        response = delete_all_learning_units_year(request, ly1.id)

        # Get message from context
        msg = [m.message for m in get_messages(request)]
        msg_level = [m.level for m in get_messages(request)]
        self.assertEqual(len(msg), 1)
        self.assertIn(messages.ERROR, msg_level)

        # Check error message
        subtype = _('The partim') if ly1.is_partim() else _(
            'The learning unit')
        self.assertIn(
            _("%(subtype)s %(acronym)s is assigned to %(tutor)s for the year %(year)s"
              ) % {
                  'subtype': subtype,
                  'acronym': ly1.acronym,
                  'tutor': attrib_new_1.tutor,
                  'year': ly1.academic_year
              }, msg)

        # Check that record is not deleted
        self.assertTrue(LearningUnitYear.objects.filter(pk=ly1.pk).exists())

        # Check redirection to identification
        self.assertEqual(response.status_code, 302)
        self.assertEqual(
            response.url,
            reverse('learning_unit', kwargs={'learning_unit_year_id': ly1.pk}))
Exemple #18
0
    def setUp(self):
        self.charge_lecturing_1 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_1,
            learning_component_year=self.partim_1_lecturing_component,
            allocation_charge=10)
        self.charge_practical_1 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_1,
            learning_component_year=self.partim_1_practical_component,
            allocation_charge=10)

        self.charge_lecturing_2 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_2,
            learning_component_year=self.partim_2_lecturing_component,
            allocation_charge=10)
        self.charge_practical_2 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_2,
            learning_component_year=self.partim_2_practical_component,
            allocation_charge=10)
Exemple #19
0
    def setUpTestData(cls):
        tutor = TutorFactory(person=PersonFactory())
        cls.attribution = AttributionNewFactory(
            tutor=tutor,
            substitute=PersonFactory()
        )
        cls.luy = LearningUnitYearFactory()
        cls.attribution_charge = AttributionChargeNewFactory(
            attribution=cls.attribution,
            learning_component_year__learning_unit_year=cls.luy
        )

        cls.person = PersonFactory()
        url_kwargs = {
            'acronym': cls.luy.acronym,
            'year': cls.luy.academic_year.year
        }
        cls.url = reverse('learning_unit_api_v1:learningunitattributions_read', kwargs=url_kwargs)
    def setUp(self):
        self.country = CountryFactory()
        self.academic_yr = AcademicYearFactory(year=timezone.now().year)
        self.start_date = self.academic_yr.start_date
        self.end_date = self.academic_yr.end_date

        self.list_learning_unit_container_year = self._create_list_containers(4)
        self.list_learning_unit_year = self._create_list_learning_units_from_containers(
            self.list_learning_unit_container_year)
        self.list_entity_version = self._create_list_entities_version()
        self._add_entities_to_containers(
            self.list_entity_version,
            self.list_learning_unit_container_year
        )
        self.tutor = TutorFactory()
        self.attribution = AttributionNewFactory(tutor=self.tutor)
        self.learning_component = LearningComponentYearFactory(learning_unit_year=self.list_learning_unit_year[0])
        self.attribution_charge_new = \
            AttributionChargeNewFactory(attribution=self.attribution,
                                        learning_component_year=self.learning_component)
Exemple #21
0
def step_impl(context, person, luys, year):
    """
    :type context: behave.runner.Context
    """
    ac_year = AcademicYear.objects.get(year=year[:4])
    luys = LearningUnitYear.objects.filter(acronym__in=luys.split(','),
                                           academic_year=ac_year)
    for luy in luys:
        # Use all possible factories. I have no idea which is the good one.
        attribution = AttributionNewFactory(
            learning_container_year=luy.learning_container_year,
            tutor__person__last_name=person,
            start_year=ac_year.year,
        )

        AttributionFactory(
            learning_unit_year=luy,
            tutor__person__last_name=person,
            start_year=ac_year.year,
        )

        AttributionChargeNewFactory(
            learning_component_year=luy.learningcomponentyear_set.first(),
            attribution=attribution)
Exemple #22
0
    def test_get_data_part2(self):
        learning_container_luy = LearningContainerYearFactory(
            academic_year=self.current_academic_year)
        luy = LearningUnitYearFactory(
            academic_year=self.current_academic_year,
            learning_container_year=learning_container_luy,
            periodicity=learning_unit_year_periodicity.ANNUAL,
            status=True,
            language=None,
        )

        component_lecturing = LearningComponentYearFactory(
            learning_container_year=learning_container_luy,
            type=learning_component_year_type.LECTURING,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1)
        component_practical = LearningComponentYearFactory(
            learning_container_year=learning_container_luy,
            type=learning_component_year_type.PRACTICAL_EXERCISES,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1)
        LearningUnitComponentFactory(
            learning_unit_year=luy,
            learning_component_year=component_lecturing)
        LearningUnitComponentFactory(
            learning_unit_year=luy,
            learning_component_year=component_practical)
        a_tutor = TutorFactory()

        an_attribution = AttributionNewFactory(tutor=a_tutor, start_year=2017)

        attribution_charge_new_lecturing = AttributionChargeNewFactory(
            learning_component_year=component_lecturing,
            attribution=an_attribution,
            allocation_charge=15.0)
        attribution_charge_new_practical = AttributionChargeNewFactory(
            learning_component_year=component_practical,
            attribution=an_attribution,
            allocation_charge=5.0)

        luy.attribution_charge_news = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year(
            luy)
        expected_common = [
            xls_build.translate(luy.periodicity),
            xls_build.translate(luy.status),
            component_lecturing.hourly_volume_total_annual,
            component_lecturing.hourly_volume_partial_q1,
            component_lecturing.hourly_volume_partial_q2,
            component_lecturing.planned_classes,
            component_practical.hourly_volume_total_annual,
            component_practical.hourly_volume_partial_q1,
            component_practical.hourly_volume_partial_q2,
            component_practical.planned_classes,
            xls_build.translate(luy.quadrimester),
            xls_build.translate(luy.session), "", ''
        ]
        self.assertEqual(_get_data_part2(luy, False), expected_common)
        self.assertEqual(
            _get_data_part2(luy, True),
            expected_attribution_data(attribution_charge_new_lecturing,
                                      attribution_charge_new_practical,
                                      expected_common, luy))
Exemple #23
0
class TestGetChargeRepartitionWarningMessage(TestCase):
    @classmethod
    def setUpTestData(cls):
        cls.full_luy = LearningUnitYearFullFactory()
        cls.partim_luy_1 = LearningUnitYearPartimFactory(
            academic_year=cls.full_luy.academic_year,
            learning_container_year=cls.full_luy.learning_container_year)
        cls.partim_luy_2 = LearningUnitYearPartimFactory(
            academic_year=cls.full_luy.academic_year,
            learning_container_year=cls.full_luy.learning_container_year)
        cls.attribution_full = AttributionNewFactory(
            learning_container_year=cls.full_luy.learning_container_year)
        cls.full_lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=cls.full_luy)
        cls.full_practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=cls.full_luy)

        cls.partim_1_lecturing_component = \
            LecturingLearningComponentYearFactory(learning_unit_year=cls.partim_luy_1)
        cls.partim_1_practical_component = \
            PracticalLearningComponentYearFactory(learning_unit_year=cls.partim_luy_1)

        cls.partim_2_lecturing_component = \
            LecturingLearningComponentYearFactory(learning_unit_year=cls.partim_luy_2)
        cls.partim_2_practical_component = \
            PracticalLearningComponentYearFactory(learning_unit_year=cls.partim_luy_2)

        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_full,
            learning_component_year=cls.full_lecturing_component,
            allocation_charge=20)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_full,
            learning_component_year=cls.full_practical_component,
            allocation_charge=20)

        cls.attribution_partim_1 = cls.attribution_full
        cls.attribution_partim_1.id = None
        cls.attribution_partim_1.save()

        cls.attribution_partim_2 = cls.attribution_full
        cls.attribution_partim_2.id = None
        cls.attribution_partim_2.save()

    def setUp(self):
        self.charge_lecturing_1 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_1,
            learning_component_year=self.partim_1_lecturing_component,
            allocation_charge=10)
        self.charge_practical_1 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_1,
            learning_component_year=self.partim_1_practical_component,
            allocation_charge=10)

        self.charge_lecturing_2 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_2,
            learning_component_year=self.partim_2_lecturing_component,
            allocation_charge=10)
        self.charge_practical_2 = AttributionChargeNewFactory(
            attribution=self.attribution_partim_2,
            learning_component_year=self.partim_2_practical_component,
            allocation_charge=10)

    def test_should_not_give_warning_messages_when_volume_partim_inferior_or_equal_to_volume_parent(
            self):
        msgs = get_charge_repartition_warning_messages(
            self.full_luy.learning_container_year)

        self.assertEqual(msgs, [])

    def test_should_not_fail_when_no_charges(self):
        self.charge_lecturing_1.allocation_charge = None
        self.charge_lecturing_1.save()
        self.charge_lecturing_2.allocation_charge = None
        self.charge_lecturing_2.save()
        self.charge_practical_1.allocation_charge = None
        self.charge_practical_1.save()
        self.charge_practical_2.allocation_charge = None
        self.charge_practical_2.save()

        msgs = get_charge_repartition_warning_messages(
            self.full_luy.learning_container_year)

        self.assertEqual(msgs, [])

    def test_should_give_warning_messages_when_volume_partim_superior_to_volume_parent(
            self):
        self.charge_lecturing_1.allocation_charge = 50
        self.charge_lecturing_1.save()

        msgs = get_charge_repartition_warning_messages(
            self.full_luy.learning_container_year)
        tutor_name = Person.get_str(
            self.attribution_full.tutor.person.first_name,
            self.attribution_full.tutor.person.middle_name,
            self.attribution_full.tutor.person.last_name)
        tutor_name_with_function = "{} ({})".format(
            tutor_name, _(self.attribution_full.get_function_display()))
        self.assertListEqual(msgs, [
            _("The sum of volumes for the partims for professor %(tutor)s is superior to the "
              "volume of full UE for this professor") % {
                  "tutor": tutor_name_with_function
              }
        ])
Exemple #24
0
class TestEditAttribution(TestCase):
    @classmethod
    def setUpTestData(cls):
        cls.person = PersonWithPermissionsFactory('can_access_learningunit')
        cls.learning_container_year = LearningContainerYearFactory(
            container_type=LearningContainerYearType.COURSE.name
        )

    def setUp(self):

        self.learning_unit_year = LearningUnitYearFullFactory(
            learning_container_year = self.learning_container_year
        )
        self.lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=self.learning_unit_year)
        self.practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=self.learning_unit_year)
        self.attribution = AttributionNewFactory(
            learning_container_year=self.learning_unit_year.learning_container_year
        )
        self.charge_lecturing = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.lecturing_component
        )
        self.charge_practical = AttributionChargeNewFactory(
            attribution=self.attribution,
            learning_component_year=self.practical_component
        )

        self.client.force_login(self.person.user)
        self.url = reverse("update_attribution", args=[self.learning_unit_year.id, self.attribution.id])

        self.patcher = patch.object(RulesRequiredMixin, "test_func", return_value=True)
        self.mocked_permission_function = self.patcher.start()

    def tearDown(self):
        self.patcher.stop()

    def test_login_required(self):
        self.client.logout()

        response = self.client.get(self.url)
        self.assertRedirects(response, '/login/?next={}'.format(self.url))

    def test_template_used_with_get(self):
        response = self.client.get(self.url)

        self.assertTrue(self.mocked_permission_function.called)
        self.assertEqual(response.status_code, HttpResponse.status_code)
        self.assertTemplateUsed(response, "learning_unit/attribution_inner.html")

    def test_post(self):
        data = {
            'attribution_form-function': COORDINATOR,
            'attribution_form-start_year': 2018,
            'attribution_form-duration': 3,
            'lecturing_form-allocation_charge': 50,
            'practical_form-allocation_charge': 10
        }
        response = self.client.post(self.url, data=data)

        self.attribution.refresh_from_db()
        self.charge_lecturing.refresh_from_db()
        self.charge_practical.refresh_from_db()
        self.assertEqual(self.attribution.function, COORDINATOR)
        self.assertEqual(self.attribution.start_year, 2018)
        self.assertEqual(self.attribution.end_year, 2020)
        self.assertEqual(self.charge_lecturing.allocation_charge, 50)
        self.assertEqual(self.charge_practical.allocation_charge, 10)

        self.assertRedirects(response,
                             reverse("learning_unit_attributions", args=[self.learning_unit_year.id]))

    def test_post_partim(self):
        self.learning_unit_year.subtype = PARTIM
        self.learning_unit_year.save()
        data = {
            'attribution_form-function': COORDINATOR,
            'lecturing_form-allocation_charge': 50,
            'practical_form-allocation_charge': 10
        }
        response = self.client.post(self.url, data=data)

        self.attribution.refresh_from_db()
        self.charge_lecturing.refresh_from_db()
        self.charge_practical.refresh_from_db()
        self.assertEqual(self.charge_lecturing.allocation_charge, 50)
        self.assertEqual(self.charge_practical.allocation_charge, 10)

        self.assertRedirects(response,
                             reverse("learning_unit_attributions", args=[self.learning_unit_year.id]))
    def test_get_data_part2(self):
        learning_container_luy = LearningContainerYearFactory(academic_year=self.current_academic_year)
        luy = LearningUnitYearFactory(academic_year=self.current_academic_year,
                                      learning_container_year=learning_container_luy,
                                      periodicity=learning_unit_year_periodicity.ANNUAL,
                                      status=True,
                                      language=None,
                                      )

        component_lecturing = LearningComponentYearFactory(
            learning_unit_year=luy,
            type=learning_component_year_type.LECTURING,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1
        )
        component_practical = LearningComponentYearFactory(
            learning_unit_year=luy,
            type=learning_component_year_type.PRACTICAL_EXERCISES,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1
        )
        a_tutor = TutorFactory()

        an_attribution = AttributionNewFactory(
            tutor=a_tutor,
            start_year=2017
        )

        attribution_charge_new_lecturing = AttributionChargeNewFactory(learning_component_year=component_lecturing,
                                                                       attribution=an_attribution,
                                                                       allocation_charge=15.0)
        attribution_charge_new_practical = AttributionChargeNewFactory(learning_component_year=component_practical,
                                                                       attribution=an_attribution,
                                                                       allocation_charge=5.0)

        # Simulate annotate
        luy = annotate_qs(LearningUnitYear.objects.filter(pk=luy.pk)).first()
        luy.entity_requirement = EntityVersionFactory()

        luy.attribution_charge_news = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year_as_dict(
            luy)


        expected_common = [
            str(_(luy.periodicity.title())),
            str(_('yes')) if luy.status else str(_('no')),
            component_lecturing.hourly_volume_total_annual,
            component_lecturing.hourly_volume_partial_q1,
            component_lecturing.hourly_volume_partial_q2,
            component_lecturing.planned_classes,
            component_practical.hourly_volume_total_annual,
            component_practical.hourly_volume_partial_q1,
            component_practical.hourly_volume_partial_q2,
            component_practical.planned_classes,
            luy.get_quadrimester_display() or '',
            luy.get_session_display() or '',
            "",
        ]
        self.assertEqual(_get_data_part2(luy, False), expected_common)
        self.assertEqual(
            _get_data_part2(luy, True),
            expected_attribution_data(
                attribution_charge_new_lecturing, attribution_charge_new_practical,
                expected_common,
                luy
            )
        )
Exemple #26
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)
Exemple #27
0
    def setUpTestData(cls):
        cls.academic_year = AcademicYearFactory(year=2017)
        cls.learning_container_luy1 = LearningContainerYearFactory(
            academic_year=cls.academic_year)
        cls.learning_unit_yr_1 = LearningUnitYearFactory(
            academic_year=cls.academic_year,
            learning_container_year=cls.learning_container_luy1,
            credits=50)
        cls.learning_unit_yr_2 = LearningUnitYearFactory()

        cls.proposal_creation_1 = ProposalLearningUnitFactory(
            state=proposal_state.ProposalState.ACCEPTED.name,
            type=proposal_type.ProposalType.CREATION.name,
        )
        cls.proposal_creation_2 = ProposalLearningUnitFactory(
            state=proposal_state.ProposalState.ACCEPTED.name,
            type=proposal_type.ProposalType.CREATION.name,
        )
        direct_parent_type = EducationGroupTypeFactory(
            name='Bachelor', category=education_group_categories.TRAINING)

        cls.an_education_group_parent = EducationGroupYearFactory(
            academic_year=cls.academic_year,
            education_group_type=direct_parent_type,
            acronym=ROOT_ACRONYM)
        cls.group_element_child = GroupElementYearFactory(
            parent=cls.an_education_group_parent,
            child_branch=None,
            child_leaf=cls.learning_unit_yr_1)
        cls.an_education_group = EducationGroupYearFactory(
            academic_year=cls.academic_year,
            acronym=PARENT_ACRONYM,
            title=PARENT_TITLE,
            partial_acronym=PARENT_PARTIAL_ACRONYM)

        cls.group_element_child2 = GroupElementYearFactory(
            parent=cls.an_education_group,
            child_branch=cls.group_element_child.parent,
        )
        cls.old_academic_year = AcademicYearFactory(
            year=datetime.date.today().year - 2)
        cls.current_academic_year = AcademicYearFactory(
            year=datetime.date.today().year)
        generatorContainer = GenerateContainer(cls.old_academic_year,
                                               cls.current_academic_year)
        cls.learning_unit_year_with_entities = generatorContainer.generated_container_years[
            0].learning_unit_year_full
        entities = [
            EntityVersionFactory(
                start_date=datetime.datetime(1900, 1, 1),
                end_date=None,
                entity_type=entity_type.FACULTY,
                entity__organization__type=organization_type.MAIN)
            for _ in range(4)
        ]
        cls.learning_unit_year_with_entities.entity_requirement = entities[0]
        cls.learning_unit_year_with_entities.entity_allocation = entities[1]
        cls.proposal_creation_3 = ProposalLearningUnitFactory(
            learning_unit_year=cls.learning_unit_year_with_entities,
            state=proposal_state.ProposalState.ACCEPTED.name,
            type=proposal_type.ProposalType.CREATION.name,
        )
        cls.learning_container_luy = LearningContainerYearFactory(
            academic_year=cls.academic_year)
        cls.luy_with_attribution = LearningUnitYearFactory(
            academic_year=cls.academic_year,
            learning_container_year=cls.learning_container_luy,
            periodicity=learning_unit_year_periodicity.ANNUAL,
            status=True,
            language=None,
        )
        cls.luy_with_attribution.entity_requirement = entities[0]
        cls.luy_with_attribution.entity_allocation = entities[1]

        cls.component_lecturing = LearningComponentYearFactory(
            learning_unit_year=cls.luy_with_attribution,
            type=learning_component_year_type.LECTURING,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1)
        cls.component_practical = LearningComponentYearFactory(
            learning_unit_year=cls.luy_with_attribution,
            type=learning_component_year_type.PRACTICAL_EXERCISES,
            hourly_volume_total_annual=15,
            hourly_volume_partial_q1=10,
            hourly_volume_partial_q2=5,
            planned_classes=1)
        a_person_tutor_1 = PersonFactory(last_name='Dupuis',
                                         first_name='Tom',
                                         email="*****@*****.**")
        cls.a_tutor_1 = TutorFactory(person=a_person_tutor_1)

        cls.an_attribution_1 = AttributionNewFactory(tutor=cls.a_tutor_1,
                                                     start_year=2017,
                                                     function=COORDINATOR)
        cls.attribution_charge_new_lecturing_1 = AttributionChargeNewFactory(
            learning_component_year=cls.component_lecturing,
            attribution=cls.an_attribution_1,
            allocation_charge=15.0)
        cls.attribution_charge_new_practical_1 = AttributionChargeNewFactory(
            learning_component_year=cls.component_practical,
            attribution=cls.an_attribution_1,
            allocation_charge=5.0)

        cls.a_tutor_2 = TutorFactory(
            person=PersonFactory(last_name='Maréchal', first_name='Didier'))

        cls.an_attribution_2 = AttributionNewFactory(tutor=cls.a_tutor_2,
                                                     start_year=2017)
        cls.attribution_charge_new_lecturing_2 = AttributionChargeNewFactory(
            learning_component_year=cls.component_lecturing,
            attribution=cls.an_attribution_2,
            allocation_charge=15.0)
        cls.attribution_charge_new_practical_2 = AttributionChargeNewFactory(
            learning_component_year=cls.component_practical,
            attribution=cls.an_attribution_2,
            allocation_charge=5.0)
        cls.entity_requirement = EntityVersion.objects.filter(entity=OuterRef(
            'learning_container_year__requirement_entity'), ).current(
                OuterRef('academic_year__start_date')).values('acronym')[:1]

        cls.entity_allocation = EntityVersion.objects.filter(entity=OuterRef(
            'learning_container_year__allocation_entity'), ).current(
                OuterRef('academic_year__start_date')).values('acronym')[:1]