Example #1
0
    def test_when_type_is_internship(self):
        self.learning_unit_year.learning_container_year.additional_entity_1 = None
        self.learning_unit_year.learning_container_year.additional_entity_2 = None
        self.learning_unit_year.learning_container_year.save()

        self.post_data['credits'] = 99
        self.post_data['container_type'] = INTERNSHIP
        self.post_data['internship_subtype'] = TEACHING_INTERNSHIP

        form = FullForm(self.person,
                        self.learning_unit_year.academic_year,
                        start_year=self.current_academic_year.year,
                        data=self.post_data)

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

        self.assertEqual(saved_luy.credits, 99)
        self.assertEqual(saved_luy.learning_container_year.container_type,
                         INTERNSHIP)
        self.assertEqual(saved_luy.internship_subtype, TEACHING_INTERNSHIP)
        learning_component_year_list = LearningComponentYear.objects.filter(
            learning_unit_year__learning_container_year=saved_luy.
            learning_container_year)
        self.assertEqual(learning_component_year_list.count(), 2)
        self.assertEqual(
            LearningComponentYear.objects.get(learning_unit_year=saved_luy,
                                              type=LECTURING).acronym, "PM")
        self.assertEqual(
            LearningComponentYear.objects.get(
                learning_unit_year=saved_luy,
                type=PRACTICAL_EXERCISES).acronym, "PP")
Example #2
0
    def test_when_type_is_dissertation(self):
        self.learning_unit_year.learning_container_year.additional_entity_1 = None
        self.learning_unit_year.learning_container_year.additional_entity_2 = None
        self.learning_unit_year.learning_container_year.save()

        self.post_data['credits'] = 99
        self.post_data['container_type'] = DISSERTATION

        form = FullForm(self.person,
                        self.learning_unit_year.academic_year,
                        start_year=self.current_academic_year.year,
                        data=self.post_data)

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

        self.assertEqual(saved_luy.credits, 99)
        self.assertEqual(saved_luy.learning_container_year.container_type,
                         DISSERTATION)
        learning_component_year_list = LearningComponentYear.objects.filter(
            learning_unit_year__learning_container_year=saved_luy.
            learning_container_year)
        self.assertEqual(learning_component_year_list.count(), 1)
        learning_component_year = LearningComponentYear.objects.get(
            learning_unit_year=saved_luy, type=None)
        self.assertEqual(learning_component_year.acronym,
                         DEFAULT_ACRONYM_COMPONENT[None])
        self.assertEqual(learning_component_year.type, None)
    def test_when_update_instance(self):
        self.post_data = get_valid_form_data(self.current_academic_year,
                                             self.person,
                                             self.learning_unit_year)
        EntityContainerYear.objects.filter(
            type__in=[
                ADDITIONAL_REQUIREMENT_ENTITY_1,
                ADDITIONAL_REQUIREMENT_ENTITY_2
            ],
            learning_container_year=self.learning_unit_year.
            learning_container_year).delete()

        initial_counts = self._get_initial_counts()
        self.post_data['credits'] = 99

        form = FullForm(
            self.person,
            self.learning_unit_year.academic_year,
            learning_unit_instance=self.learning_unit_year.learning_unit,
            data=self.post_data)

        self.assertTrue(form.is_valid(), form.errors)
        form.save()
        self.assertEqual(
            LearningUnitYear.objects.get(
                pk=self.learning_unit_year.id).credits, 99)

        for model_class, initial_count in initial_counts.items():
            current_count = self._count_records(model_class)
            self.assertEqual(current_count, initial_count,
                             model_class.objects.all())
Example #4
0
    def test_when_update_instance(self):
        self.post_data = get_valid_form_data(self.current_academic_year,
                                             self.person,
                                             self.learning_unit_year)

        self.learning_unit_year.learning_container_year.additional_entity_1 = None
        self.learning_unit_year.learning_container_year.additional_entity_2 = None
        self.learning_unit_year.learning_container_year.save()

        initial_counts = self._get_initial_counts()
        self.post_data['credits'] = 99

        form = FullForm(
            self.person,
            self.learning_unit_year.academic_year,
            learning_unit_instance=self.learning_unit_year.learning_unit,
            data=self.post_data)

        self.assertTrue(form.is_valid(), form.errors)
        form.save()
        self.assertEqual(
            LearningUnitYear.objects.get(
                pk=self.learning_unit_year.id).credits, 99)

        for model_class, initial_count in initial_counts.items():
            current_count = self._count_records(model_class)
            self.assertEqual(current_count, initial_count,
                             model_class.objects.all())
    def test_when_type_is_dissertation(self):
        EntityContainerYear.objects.filter(type__in=[ADDITIONAL_REQUIREMENT_ENTITY_1, ADDITIONAL_REQUIREMENT_ENTITY_2],
                                           learning_container_year=self.learning_unit_year.learning_container_year
                                           ).delete()

        self.post_data['credits'] = 99
        self.post_data['container_type'] = DISSERTATION

        form = FullForm(self.person,
                        self.learning_unit_year.academic_year,
                        start_year=self.current_academic_year.year,
                        data=self.post_data)

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

        self.assertEqual(saved_luy.credits, 99)
        self.assertEqual(saved_luy.learning_container_year.container_type, DISSERTATION)
        learning_component_year_list = LearningComponentYear.objects.filter(
            learning_container_year=saved_luy.learning_container_year
        )
        self.assertEqual(learning_component_year_list.count(), 1)
        self.assertEqual(
            EntityComponentYear.objects.filter(
                learning_component_year__in=learning_component_year_list).count(), 1)
        learning_component_year = LearningComponentYear.objects.get(
            learning_container_year=saved_luy.learning_container_year, type=None)
        self.assertEqual(learning_component_year.acronym, DEFAULT_ACRONYM_COMPONENT[None])
        self.assertEqual(learning_component_year.type, None)
    def test_when_delete_additionnal_entity(self):
        post_data = get_valid_form_data(self.current_academic_year, self.person, self.learning_unit_year)
        # Assert additionnal entity exists exists
        if not self.learning_unit_year.learning_container_year.additional_entity_1:
            self.learning_unit_year.learning_container_year.additional_entity_1 = EntityFactory()
            self.learning_unit_year.learning_container_year.save()
        # Assert repartition volumes are set for additional entity
        component_queryset = LearningComponentYear.objects.filter(
            learning_unit_year__learning_container_year=self.learning_unit_year.learning_container_year
        )
        component_queryset.update(repartition_volume_additional_entity_1=15.0)

        # Removing additionnal entity
        post_data["additional_entity_1"] = ""

        self.assertEqual(component_queryset.count(), 4)  # Assert we are testing for Full AND Partim (2 components each)

        form = FullForm(
            self.person,
            self.learning_unit_year.academic_year,
            learning_unit_instance=self.learning_unit_year.learning_unit,
            data=post_data
        )

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

        self.learning_unit_year.learning_container_year.refresh_from_db()
        self.assertIsNone(self.learning_unit_year.learning_container_year.additional_entity_1)
        self.learning_unit_year.learning_container_year.refresh_from_db()
        self.assertIsNotNone(self.learning_unit_year.learning_container_year.requirement_entity)
        self.assertIsNotNone(self.learning_unit_year.learning_container_year.allocation_entity)
        for component in component_queryset:
            self.assertIsNone(component.repartition_volume_additional_entity_1)
    def test_when_type_is_internship(self):
        EntityContainerYear.objects.filter(type__in=[ADDITIONAL_REQUIREMENT_ENTITY_1, ADDITIONAL_REQUIREMENT_ENTITY_2],
                                           learning_container_year=self.learning_unit_year.learning_container_year
                                           ).delete()

        self.post_data['credits'] = 99
        self.post_data['container_type'] = INTERNSHIP
        self.post_data['internship_subtype'] = TEACHING_INTERNSHIP

        form = FullForm(self.person,
                        self.learning_unit_year.academic_year,
                        start_year=self.current_academic_year.year,
                        data=self.post_data)

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

        self.assertEqual(saved_luy.credits, 99)
        self.assertEqual(saved_luy.learning_container_year.container_type, INTERNSHIP)
        self.assertEqual(saved_luy.internship_subtype, TEACHING_INTERNSHIP)
        learning_component_year_list = LearningComponentYear.objects.filter(
            learning_container_year=saved_luy.learning_container_year
        )
        self.assertEqual(learning_component_year_list.count(), 2)
        self.assertEqual(
            EntityComponentYear.objects.filter(
                learning_component_year__in=learning_component_year_list).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_disable_fields_full_with_faculty_manager_and_central_manager(self):
     self.person.user.groups.add(FacultyManagerGroupFactory())
     self.person.user.groups.add(CentralManagerGroupFactory())
     form = FullForm(self.person, self.learning_unit_year.academic_year,
                     learning_unit_instance=self.learning_unit_year.learning_unit)
     disabled_fields = {key for key, value in form.fields.items() if value.disabled}
     self.assertEqual(disabled_fields, FULL_READ_ONLY_FIELDS.union({'internship_subtype'}))
 def _get_learning_unit_base_form(self,
                                  ac_year,
                                  learning_unit_instance=None,
                                  data=None,
                                  start_year=None):
     form_kwargs = {
         'person':
         self.person,
         'learning_unit_instance':
         learning_unit_instance,
         'academic_year':
         ac_year,
         'start_year':
         start_year,
         'data':
         data.copy() if data else None,
         'learning_unit_full_instance':
         self.learning_unit_full_instance,
         'postposal':
         not data,
         'start_anac':
         self.start_postponement
         if self.subtype == learning_unit_year_subtypes.PARTIM else None
     }
     if self.external:
         return ExternalLearningUnitBaseForm(
             **form_kwargs
         ) if self.subtype == learning_unit_year_subtypes.FULL else ExternalPartimForm(
             **form_kwargs)
     return FullForm(**form_kwargs) if self.subtype == learning_unit_year_subtypes.FULL else \
         PartimForm(**form_kwargs)
 def test_disable_fields_full_with_faculty_manager_and_central_manager(self):
     self.person.user.groups.add(Group.objects.get(name=FACULTY_MANAGER_GROUP))
     self.person.user.groups.add(Group.objects.get(name=CENTRAL_MANAGER_GROUP))
     form = FullForm(self.person, self.learning_unit_year.academic_year,
                     learning_unit_instance=self.learning_unit_year.learning_unit)
     disabled_fields = {key for key, value in form.fields.items() if value.disabled}
     self.assertEqual(disabled_fields, FULL_READ_ONLY_FIELDS.union({'internship_subtype'}))
 def test_disable_fields_acronym_with_faculty_manager_and_other_collective(self):
     self.person.user.groups.add(FacultyManagerGroupFactory())
     self.learning_unit_year.learning_container_year.container_type = LearningContainerYearType.OTHER_COLLECTIVE.name
     self.learning_unit_year.learning_container_year.save()
     form = FullForm(self.person, self.learning_unit_year.academic_year,
                     learning_unit_instance=self.learning_unit_year.learning_unit)
     disabled_fields = {key for key, value in form.fields.items() if value.disabled}
     self.assertTrue("acronym" not in disabled_fields)
 def test_disable_fields_full_proposal(self):
     form = FullForm(
         self.person,
         self.learning_unit_year.academic_year,
         learning_unit_instance=self.learning_unit_year.learning_unit,
         proposal=True)
     self.assertTrue(form.fields['academic_year'].disabled)
     self.assertTrue(form.fields['container_type'].disabled)
 def test_academic_years_restriction_for_faculty_manager(self):
     self.person.user.groups.add(FacultyManagerGroupFactory())
     form = FullForm(self.person, self.learning_unit_year.academic_year,
                     start_year=self.learning_unit_year.academic_year.year,
                     postposal=True)
     actual_choices = [choice[0] for choice in form.fields["academic_year"].choices if choice[0] != '']
     expected_choices = [acy.id for acy in self.acs[3:6]]
     self.assertCountEqual(actual_choices, expected_choices)
    def test_academic_years_restriction_for_central_manager(self):
        central_group = Group.objects.get(name='central_managers')
        self.person.user.groups.add(central_group)
        form = FullForm(self.person, self.learning_unit_year.academic_year,
                        start_year=self.learning_unit_year.academic_year.year,
                        postposal=True)
        actual_choices = [choice[0] for choice in form.fields["academic_year"].choices if choice[0] != '']
        expected_choices = [acy.id for acy in self.acs[3:10]]

        self.assertCountEqual(actual_choices, expected_choices)
Example #15
0
    def test_disable_fields_full_proposal_with_faculty_manager(self):
        self.person.user.groups.add(FacultyManagerGroupFactory())
        form = FullForm(
            self.person,
            self.learning_unit_year.academic_year,
            learning_unit_instance=self.learning_unit_year.learning_unit,
            proposal=True)

        for elem in PROPOSAL_READ_ONLY_FIELDS:
            self.assertEqual(form.fields[elem].disabled, True)
            self.assertEqual(form.fields['academic_year'].disabled, True)
Example #16
0
 def test_disable_fields_full_with_faculty_manager(self):
     self.person.user.groups.add(FacultyManagerGroupFactory())
     form = FullForm(
         self.person,
         self.learning_unit_year.academic_year,
         learning_unit_instance=self.learning_unit_year.learning_unit)
     disabled_fields = {
         key
         for key, value in form.fields.items() if value.disabled
     }
     self.assertTrue(FACULTY_OPEN_FIELDS not in disabled_fields)
def _instanciate_form(academic_year,
                      person=None,
                      post_data=None,
                      learning_unit_instance=None,
                      start_year=None):
    if not person:
        person = PersonFactory()
    return FullForm(person,
                    academic_year,
                    learning_unit_instance=learning_unit_instance,
                    data=post_data,
                    start_year=start_year)
    def test_disable_fields_full_proposal_with_faculty_manager(self):
        self.person.user.groups.add(
            Group.objects.get(name=FACULTY_MANAGER_GROUP))
        form = FullForm(
            self.person,
            self.learning_unit_year.academic_year,
            learning_unit_instance=self.learning_unit_year.learning_unit,
            proposal=True)

        for elem in PROPOSAL_READ_ONLY_FIELDS:
            self.assertEqual(form.fields[elem].disabled, True)
            self.assertEqual(form.fields['academic_year'].disabled, True)
Example #19
0
 def _get_learning_unit_base_form(self,
                                  ac_year,
                                  learning_unit_instance=None,
                                  data=None,
                                  start_year=None):
     form_kwargs = {
         'person': self.person,
         'learning_unit_instance': learning_unit_instance,
         'academic_year': ac_year,
         'start_year': start_year,
         'data': data.copy() if data else None,
         'learning_unit_full_instance': self.learning_unit_full_instance
     }
     return FullForm(**form_kwargs) if self.subtype == learning_unit_year_subtypes.FULL else \
         PartimForm(**form_kwargs)
Example #20
0
    def __init__(self,
                 data,
                 person,
                 learning_unit_year=None,
                 proposal=None,
                 proposal_type=None,
                 default_ac_year=None):
        self.person = person
        self.learning_unit_year = learning_unit_year
        self.proposal = proposal
        if proposal_type:
            self.proposal_type = proposal_type

        initial = self._get_initial()

        ac_year = default_ac_year or learning_unit_year.academic_year

        if not learning_unit_year or learning_unit_year.subtype == learning_unit_year_subtypes.FULL:
            learning_unit = learning_unit_year.learning_unit if learning_unit_year else None
            start_year = default_ac_year.year if default_ac_year else None
            self.learning_unit_form_container = FullForm(
                person,
                ac_year,
                learning_unit_instance=learning_unit,
                data=data,
                start_year=start_year,
                proposal=True,
                proposal_type=proposal_type)
        else:
            self.learning_unit_form_container = PartimForm(
                person,
                learning_unit_year.parent.learning_unit,
                ac_year,
                learning_unit_instance=learning_unit_year.learning_unit,
                data=data,
                proposal=True)

        self.form_proposal = ProposalLearningUnitForm(data,
                                                      person=person,
                                                      instance=proposal,
                                                      initial=initial)
 def test_case_start_year_and_learning_unit_instance_kwarg_are_missing(
         self):
     with self.assertRaises(AttributeError):
         FullForm(self.person,
                  self.learning_unit_year.academic_year,
                  post_data=self.post_data)