示例#1
0
    def test_save(self):
        learning_container_year_full = self.learning_unit_year_full.learning_container_year
        a_new_learning_unit_partim = LearningUnitYearFactory.build(
            academic_year=self.current_academic_year,
            acronym=FULL_ACRONYM + 'C',
            subtype=learning_unit_year_subtypes.PARTIM,
            language=self.learning_unit_year_full.language)
        post_data = get_valid_form_data(a_new_learning_unit_partim)

        form = _instanciate_form(
            learning_unit_full=self.learning_unit_year_full.learning_unit,
            academic_year=self.learning_unit_year_full.academic_year,
            post_data=post_data,
            instance=None)
        self.assertTrue(form.is_valid(), form.errors)
        saved_instance = form.save()

        self.assertIsInstance(saved_instance, LearningUnitYear)
        self.assertEqual(saved_instance.learning_container_year,
                         learning_container_year_full)
        learning_component_year_list = LearningComponentYear.objects.filter(
            learning_container_year=saved_instance.learning_container_year)
        self.assertEqual(learning_component_year_list.count(), 6)
        self.assertEqual(
            EntityComponentYear.objects.filter(
                learning_component_year__in=learning_component_year_list).
            count(), 18)
        self.assertTrue(
            learning_component_year_list.filter(type=LECTURING,
                                                acronym="PM").exists())
        self.assertTrue(
            learning_component_year_list.filter(type=PRACTICAL_EXERCISES,
                                                acronym="PP").exists())
示例#2
0
    def test_save_method_create_new_instance(self):
        partim_acronym = FULL_ACRONYM + 'C'
        a_new_learning_unit_partim = LearningUnitYearFactory.build(
            academic_year=self.current_academic_year,
            acronym=partim_acronym,
            subtype=learning_unit_year_subtypes.PARTIM,
            language=self.learning_unit_year_full.language)
        post_data = get_valid_form_data(a_new_learning_unit_partim)

        form = _instanciate_form(
            learning_unit_full=self.learning_unit_year_full.learning_unit,
            academic_year=self.learning_unit_year_full.academic_year,
            post_data=post_data,
            instance=None)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        # Check all related object is created
        self.assertEqual(
            LearningUnitYear.objects.filter(
                acronym=partim_acronym,
                academic_year=self.current_academic_year).count(), 1)
        self.assertEqual(
            LearningUnit.objects.filter(
                learningunityear__acronym=partim_acronym).count(), 1)
    def test_when_create_instance(self):
        initial_counts = self._get_initial_counts()
        acronym = 'LAGRO1200'
        new_learning_unit_year = LearningUnitYearFactory.build(
            acronym=acronym,
            academic_year=self.current_academic_year,
            subtype=learning_unit_year_subtypes.FULL,
            language=self.initial_language,
            learning_container_year__academic_year=self.current_academic_year,
            learning_container_year__container_type=learning_container_year_types.COURSE,
            campus=self.initial_campus
        )
        post_data = get_valid_form_data(self.current_academic_year, person=self.person,
                                        learning_unit_year=new_learning_unit_year)
        form = _instanciate_form(self.current_academic_year, post_data=post_data, person=self.person,
                                 start_year=self.current_academic_year.year)
        self.assertTrue(form.is_valid(), form.errors)
        saved_luy = form.save()
        self.assertEqual(LearningUnitYear.objects.filter(acronym='LAGRO1200').count(), 1)
        self.assertEqual(LearningComponentYear.objects.filter(
            learning_container_year=self.learning_unit_year.learning_container_year).count(), 4)

        self._assert_correctly_create_records_in_all_learning_unit_structure(initial_counts)
        self.assertEqual(LearningComponentYear.objects.filter(
            learning_container_year=saved_luy.learning_container_year
        ).count(), 2)
        self.assertEqual(
            LearningComponentYear.objects.get(
                learning_container_year=saved_luy.learning_container_year, type=LECTURING).acronym, "PM")
        self.assertEqual(
            LearningComponentYear.objects.get(
                learning_container_year=saved_luy.learning_container_year, type=PRACTICAL_EXERCISES).acronym, "PP")
    def test_save_method_create_new_instance_with_start_anac(self):
        partim_acronym = FULL_ACRONYM + "B"
        start_year = self.current_academic_year.year + 2
        a_new_learning_unit_partim = LearningUnitYearFactory.build(
            academic_year__year=start_year,
            acronym=FULL_ACRONYM,
            subtype=learning_unit_year_subtypes.PARTIM,
            language=self.learning_unit_year_full.language)
        post_data = get_valid_form_data(a_new_learning_unit_partim)
        person = PersonFactory()
        form = PartimForm(person,
                          self.learning_unit_year_full.learning_unit,
                          self.learning_unit_year_full.academic_year,
                          data=post_data,
                          learning_unit_instance=None,
                          start_anac=start_year)

        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        # Check all related object is created
        self.assertEqual(
            LearningUnitYear.objects.filter(
                acronym=partim_acronym,
                academic_year=self.current_academic_year).count(), 1)
        self.assertEqual(
            LearningUnit.objects.filter(
                learningunityear__acronym=partim_acronym).count(), 1)
        self.assertEqual(
            LearningUnit.objects.filter(
                learningunityear__acronym=partim_acronym).first().start_year,
            start_year)
示例#5
0
def get_valid_external_learning_unit_form_data(academic_year, person, learning_unit_year=None):
    entities = create_entities_hierarchy()
    PersonEntityFactory(person=person, entity=entities['root_entity'], with_child=True)
    requesting_entity = entities['child_one_entity_version']
    organization = OrganizationFactory(type=organization_type.MAIN)
    campus = CampusFactory(organization=organization)
    language = LanguageFactory(code='FR')

    if not learning_unit_year:
        container_year = LearningContainerYearFactory(academic_year=academic_year)
        learning_unit_year = LearningUnitYearFactory.build(
            acronym='EOSIS1111',
            academic_year=academic_year,
            learning_container_year=container_year,
            subtype=learning_unit_year_subtypes.FULL,
            campus=campus,
            language=language
        )
    return {
        # Learning unit year data model form
        'acronym_0': learning_unit_year.acronym[0],
        'acronym_1': learning_unit_year.acronym[1:],
        'acronym_2': "A",
        'academic_year': learning_unit_year.academic_year.id,
        'specific_title': learning_unit_year.specific_title,
        'specific_title_english': learning_unit_year.specific_title_english,
        'credits': learning_unit_year.credits,
        'status': learning_unit_year.status,
        'campus': learning_unit_year.campus.id,
        'language': learning_unit_year.language.pk,
        'periodicity': learning_unit_year.periodicity,

        # Learning unit data model form
        'faculty_remark': learning_unit_year.learning_unit.faculty_remark,

        # Learning container year data model form
        'common_title': learning_unit_year.learning_container_year.common_title,
        'common_title_english': learning_unit_year.learning_container_year.common_title_english,
        'is_vacant': learning_unit_year.learning_container_year.is_vacant,

        # External learning unit model form
        'requirement_entity': requesting_entity.id,
        'allocation_entity': requesting_entity.id,
        'external_acronym': 'Gorzyne',
        'external_credits': '5',

        # Learning component year data model form
        'component-TOTAL_FORMS': '2',
        'component-INITIAL_FORMS': '0',
        'component-MAX_NUM_FORMS': '2',
        'component-0-hourly_volume_total_annual': 20,
        'component-0-hourly_volume_partial_q1': 10,
        'component-0-hourly_volume_partial_q2': 10,
        'component-0-planned_classes': 1,
        'component-1-hourly_volume_total_annual': 20,
        'component-1-hourly_volume_partial_q1': 10,
        'component-1-hourly_volume_partial_q2': 10,
        'component-1-planned_classes': 1,
    }
 def _get_post_data_with_different_entities_container_year(self, container_type):
     container_year = LearningContainerYearFactory.build(academic_year=self.current_academic_year,
                                                         container_type=container_type)
     learning_unit_year = LearningUnitYearFactory.build(academic_year=self.current_academic_year,
                                                        learning_container_year=container_year,
                                                        subtype=learning_unit_year_subtypes.FULL)
     post_data = get_valid_form_data(self.current_academic_year, person=self.person,
                                     learning_unit_year=learning_unit_year)
     post_data['allocation_entity-entity'] = EntityVersionFactory().id
     return post_data
示例#7
0
 def test_creation_case_wrong_learning_unit_data(self, mock_is_valid):
     a_new_learning_unit_partim = LearningUnitYearFactory.build(
         academic_year=self.current_academic_year,
         acronym=FULL_ACRONYM + 'B',
         subtype=learning_unit_year_subtypes.PARTIM,
         language=self.learning_unit_year_full.language)
     post_data = get_valid_form_data(a_new_learning_unit_partim)
     form = _instanciate_form(
         learning_unit_full=self.learning_unit_year_full.learning_unit,
         academic_year=self.learning_unit_year_full.academic_year,
         post_data=post_data)
     self.assertFalse(form.is_valid())
示例#8
0
 def test_creation_case_correct_post_data(self):
     a_new_learning_unit_partim = LearningUnitYearFactory.build(
         academic_year=self.current_academic_year,
         acronym=FULL_ACRONYM,
         subtype=learning_unit_year_subtypes.PARTIM,
         language=self.learning_unit_year_full.language)
     post_data = get_valid_form_data(a_new_learning_unit_partim)
     form = _instanciate_form(
         learning_unit_full=self.learning_unit_year_full.learning_unit,
         academic_year=self.learning_unit_year_full.academic_year,
         post_data=post_data)
     # The form should be valid
     self.assertTrue(form.is_valid(), form.errors)
     # In partim, we can only modify LearningUnitYearModelForm / LearningUnitModelForm
     self._test_learning_unit_model_form_instance(form, post_data)
     self._test_learning_unit_year_model_form_instance(form, post_data)
     # Inherit instance from learning unit year full
     self._test_learning_container_model_form_instance(form)
     self._test_learning_container_year_model_form_instance(form)
def get_valid_form_data(academic_year, person, learning_unit_year=None):
    entities = create_entities_hierarchy()
    PersonEntityFactory(person=person,
                        entity=entities['root_entity'],
                        with_child=True)
    requirement_entity_version = entities['child_one_entity_version']
    organization = OrganizationFactory(type=organization_type.MAIN)
    campus = CampusFactory(organization=organization)
    language = LanguageFactory(code='FR')

    if not learning_unit_year:
        learning_container = LearningContainerFactory()
        container_year = LearningContainerYearFactory(
            academic_year=academic_year, learning_container=learning_container)

        learning_unit_full = LearningUnitFactory(
            learning_container=learning_container,
            start_year=academic_year.year,
            end_year=academic_year.year,
        )

        learning_unit_year = LearningUnitYearFactory.build(
            academic_year=academic_year,
            learning_unit=learning_unit_full,
            learning_container_year=container_year,
            subtype=learning_unit_year_subtypes.FULL,
            campus=campus,
            language=language,
            periodicity=learning_unit_year_periodicity.ANNUAL)

    cm_lcy = LearningComponentYear.objects.filter(
        learning_unit_year=learning_unit_year).first()
    pp_lcy = LearningComponentYear.objects.filter(
        learning_unit_year=learning_unit_year).last()

    return {
        # Learning unit year data model form
        'acronym': learning_unit_year.acronym,
        'acronym_0': learning_unit_year.acronym[0],
        'acronym_1': learning_unit_year.acronym[1:],
        'subtype': learning_unit_year.subtype,
        'academic_year': learning_unit_year.academic_year.id,
        'specific_title': learning_unit_year.specific_title,
        'specific_title_english': learning_unit_year.specific_title_english,
        'credits': learning_unit_year.credits,
        'session': learning_unit_year.session,
        'quadrimester': learning_unit_year.quadrimester,
        'status': learning_unit_year.status,
        'internship_subtype': None,
        'attribution_procedure': learning_unit_year.attribution_procedure,
        'campus': learning_unit_year.campus.id,
        'language': learning_unit_year.language.pk,
        'periodicity': learning_unit_year.periodicity,

        # Learning unit data model form
        'faculty_remark': learning_unit_year.learning_unit.faculty_remark,
        'other_remark': learning_unit_year.learning_unit.other_remark,

        # Learning container year data model form
        'common_title':
        learning_unit_year.learning_container_year.common_title,
        'common_title_english':
        learning_unit_year.learning_container_year.common_title_english,
        'container_type':
        learning_unit_year.learning_container_year.container_type,
        'type_declaration_vacant':
        learning_unit_year.learning_container_year.type_declaration_vacant,
        'team': learning_unit_year.learning_container_year.team,
        'is_vacant': learning_unit_year.learning_container_year.is_vacant,
        'requirement_entity-entity': requirement_entity_version.id,
        'allocation_entity-entity': requirement_entity_version.id,
        'additional_requirement_entity_1-entity': '',

        # Learning component year data model form
        'component-0-id': cm_lcy and cm_lcy.pk,
        'component-1-id': pp_lcy and pp_lcy.pk,
        'component-TOTAL_FORMS': '2',
        'component-INITIAL_FORMS': '0' if not cm_lcy else '2',
        'component-MAX_NUM_FORMS': '2',
        'component-0-hourly_volume_total_annual': 20,
        'component-0-hourly_volume_partial_q1': 10,
        'component-0-hourly_volume_partial_q2': 10,
        'component-1-hourly_volume_total_annual': 20,
        'component-1-hourly_volume_partial_q1': 10,
        'component-1-hourly_volume_partial_q2': 10,
    }