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 #2
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 #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)
Exemple #5
0
 def setUp(self):
     self.person = PersonFactory()
     self.tutor = TutorFactory(person=self.person)
     self.learning_container_year = LearningContainerYearFactory()
     self.attribution_new = AttributionNewFactory(learning_container_year=self.learning_container_year,
                                                  start_year=2018, end_year=2020, tutor=self.tutor,
                                                  score_responsible=True)
 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)
Exemple #7
0
 def setUpTestData(cls):
     cls.tutor = TutorFactory()
     cls.learning_container_year = LearningContainerYearFactory()
     cls.attribution_new = AttributionNewFactory(
         learning_container_year=cls.learning_container_year,
         start_year=2018,
         end_year=2020,
         tutor=cls.tutor,
         score_responsible=True)
Exemple #8
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)
Exemple #9
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()
Exemple #10
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 #11
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 #12
0
 def test_duration_without_end_year(self):
     attribution_new_without_end_year = AttributionNewFactory(
         start_year=2018, end_year=None)
     self.assertIsNone(attribution_new_without_end_year.duration)
Exemple #13
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 #15
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]
Exemple #16
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))