Example #1
0
    def test_is_linked_to_entity_in_charge_of_external_learning_unit_year(self):
        person_entity = PersonEntityFactory(person=self.person_with_user)
        luy = LearningUnitYearFactory()
        external_luy = ExternalLearningUnitYearFactory(learning_unit_year=luy)

        self.assertFalse(
            self.person_with_user.is_linked_to_entity_in_charge_of_learning_unit_year(luy)
        )

        external_luy.requesting_entity = person_entity.entity
        external_luy.save()

        self.assertTrue(
            self.person_with_user.is_linked_to_entity_in_charge_of_learning_unit_year(luy)
        )
Example #2
0
 def setUpTestData(cls):
     anac = AcademicYearFactory()
     requirement_entity = EntityFactory()
     EntityVersionFactory(
         start_date=AcademicYearFactory(year=anac.year - 1).start_date,
         end_date=AcademicYearFactory(year=anac.year + 1).end_date,
         entity=requirement_entity)
     luy = LearningUnitYearFactory(
         academic_year=anac,
         learning_container_year__requirement_entity=requirement_entity)
     ExternalLearningUnitYearFactory(learning_unit_year=luy)
     cls.luy = LearningUnitYear.objects.filter(
         pk=luy.pk).annotate_full_title().get()
     setattr(cls.luy, "entity_requirement", "OSIS")
     setattr(cls.luy, "entity_allocation", "OSIS")
     url_kwargs = {
         'acronym': cls.luy.acronym,
         'year': cls.luy.academic_year.year
     }
     url = reverse('learning_unit_api_v1:learningunits_read',
                   kwargs=url_kwargs)
     cls.serializer = ExternalLearningUnitDetailedSerializer(
         cls.luy,
         context={
             'request': RequestFactory().get(url),
             'language': settings.LANGUAGE_CODE_EN
         })
Example #3
0
    def setUp(self):
        self.user = UserFactory()
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_learningunit"))
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_edit_learningunit"))
        self.person = CentralManagerFactory(user=self.user)
        self.client.force_login(self.user)

        self.academic_year = create_current_academic_year()

        luy = LearningUnitYearFullFactory(academic_year=self.academic_year)
        self.external = ExternalLearningUnitYearFactory(learning_unit_year=luy)

        luy.learning_container_year.container_type = EXTERNAL
        luy.learning_container_year.save()

        EntityVersionFactory(entity=self.external.requesting_entity)
        PersonEntityFactory(person=self.person,
                            entity=self.external.requesting_entity)

        self.data = get_valid_external_learning_unit_form_data(
            self.academic_year, self.person, self.external.learning_unit_year)

        self.url = reverse(update_learning_unit,
                           args=[self.external.learning_unit_year.pk])
Example #4
0
    def setUp(self):
        self.user = UserFactory()
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_access_learningunit"))
        self.user.user_permissions.add(
            Permission.objects.get(codename="can_edit_learningunit"))
        self.person = CentralManagerFactory(user=self.user)
        self.client.force_login(self.user)

        person_entity = PersonEntityFactory(
            person=self.person,
            entity=EntityVersionFactory().entity,
        )

        self.academic_year = create_current_academic_year()

        luy = LearningUnitYearFullFactory(
            academic_year=self.academic_year,
            internship_subtype=None,
            acronym="EFAC0000",
            learning_container_year__container_type=EXTERNAL,
            learning_container_year__requirement_entity=person_entity.entity,
        )
        self.external = ExternalLearningUnitYearFactory(learning_unit_year=luy)

        self.data = get_valid_external_learning_unit_form_data(
            self.academic_year, self.person, self.external.learning_unit_year)

        self.url = reverse(update_learning_unit,
                           args=[self.external.learning_unit_year.pk])
Example #5
0
    def test_external_learning_unit_read_permission_denied(self):
        learning_container_year = LearningContainerYearFactory(
            academic_year=self.current_academic_year)
        learning_unit_year = LearningUnitYearFactory(
            academic_year=self.current_academic_year,
            learning_container_year=learning_container_year,
            subtype=learning_unit_year_subtypes.FULL)
        external_learning_unit_year = ExternalLearningUnitYearFactory(
            learning_unit_year=learning_unit_year)
        learning_unit_year = external_learning_unit_year.learning_unit_year

        a_user_without_perms = PersonFactory().user
        client = Client()
        client.force_login(a_user_without_perms)

        response = client.get(
            reverse("learning_unit", args=[learning_unit_year.id]))
        self.assertEqual(response.status_code,
                         HttpResponseForbidden.status_code)
        self.assertTemplateUsed(response, "access_denied.html")

        a_user_without_perms.user_permissions.add(
            Permission.objects.get(
                codename='can_access_externallearningunityear'))

        response = client.get(
            reverse("learning_unit", args=[learning_unit_year.id]))
        self.assertEqual(response.status_code, 200)
 def test_when_is_external_of_mobility(self):
     external_learning_unit = ExternalLearningUnitYearFactory(
         learning_unit_year__learning_container_year__container_type=
         LearningContainerYearType.EXTERNAL.name,
         mobility=True,
     )
     result = external_learning_unit.learning_unit_year.container_type_verbose
     self.assertEqual(result, _("Mobility"))
 def test_normal_case(self):
     external_learning_unit = ExternalLearningUnitYearFactory(
         learning_unit_year__learning_container_year__container_type=
         LearningContainerYearType.OTHER_INDIVIDUAL.name, )
     result = external_learning_unit.learning_unit_year.container_type_verbose
     expected_result = external_learning_unit.learning_unit_year.learning_container_year.get_container_type_display(
     )
     self.assertEqual(result, expected_result)
Example #8
0
    def setUp(self):
        self.academic_year = create_current_academic_year()

        self.be_organization_adr_city1 = OrganizationAddressFactory(country__iso_code="BE", city=NAMEN)
        self.external_lu_1 = ExternalLearningUnitYearFactory(
            co_graduation=True,
            learning_unit_year__academic_year=self.academic_year,
            learning_unit_year__acronym='EDROI1001',
            learning_unit_year__campus__organization=self.be_organization_adr_city1.organization,
        )

        self.be_organization_adr_city2 = OrganizationAddressFactory(country__iso_code="BE", city='Bruxelles')
        self.external_lu_2 = ExternalLearningUnitYearFactory(
            co_graduation=True,
            learning_unit_year__academic_year=self.academic_year,
            learning_unit_year__acronym='EDROI1002',
            learning_unit_year__campus__organization=self.be_organization_adr_city2.organization,
        )
 def test_when_is_course(self):
     external_learning_unit = ExternalLearningUnitYearFactory(
         learning_unit_year__learning_container_year__container_type=
         LearningContainerYearType.COURSE.name, )
     luy = external_learning_unit.learning_unit_year
     result = luy.container_type_verbose
     expected_result = '{} ({})'.format(
         luy.learning_container_year.get_container_type_display(),
         luy.get_subtype_display())
     self.assertEqual(result, expected_result)
Example #10
0
    def test_external_learning_unit_read(self):
        external_learning_unit_year = ExternalLearningUnitYearFactory(
            learning_unit_year__subtype=learning_unit_year_subtypes.FULL, )
        learning_unit_year = external_learning_unit_year.learning_unit_year

        response = self.client.get(
            reverse('learning_unit', args=[learning_unit_year.pk]))

        self.assertTemplateUsed(response, 'learning_unit/identification.html')
        self.assertEqual(response.context['learning_unit_year'],
                         learning_unit_year)
Example #11
0
 def test_when_external_learning_unit_is_not_co_graduation(
         self, mock_is_person_linked_to_entity_in_charge_of_lu,
         mock_is_learning_unit_year_in_state_to_be_modified,
         mock_is_year_editable):
     mock_is_person_linked_to_entity_in_charge_of_lu.return_value = True
     mock_is_learning_unit_year_in_state_to_be_modified.return_value = True
     mock_is_year_editable.return_value = True
     a_person = CentralManagerFactory()
     luy = LearningUnitYearFactory(academic_year=self.academic_yr)
     ExternalLearningUnitYearFactory(learning_unit_year=luy,
                                     co_graduation=False)
     self.assertFalse(
         perms.is_external_learning_unit_cograduation(luy, a_person, False))
Example #12
0
    def setUp(self):
        self.academic_year = create_current_academic_year()

        self.learning_unit_year_1 = LearningUnitYearFactory(
            academic_year=self.academic_year, acronym='XLDR1001')
        self.external_lu_1 = ExternalLearningUnitYearFactory(
            external_acronym='XLDR1001',
            learning_unit_year=self.learning_unit_year_1)
        self.learning_unit_year_2 = LearningUnitYearFactory(
            academic_year=self.academic_year, acronym='XLDR1002')
        self.external_lu_2 = ExternalLearningUnitYearFactory(
            external_acronym='XLDR1002',
            learning_unit_year=self.learning_unit_year_2)

        self.a_be_country = CountryFactory(iso_code='BE')
        self.be_organization_adr_city1 = OrganizationAddressFactory(
            country=self.a_be_country, city=NAMEN)
        self.be_campus_1 = CampusFactory(
            organization=self.be_organization_adr_city1.organization)
        self.learning_container_year = LearningContainerYearFactory(
            academic_year=self.academic_year)
        self.learning_unit_year_3 = LearningUnitYearFactory(
            learning_container_year=self.learning_container_year,
            academic_year=self.academic_year,
            campus=self.be_campus_1)
        self.external_lu_BE_1 = ExternalLearningUnitYearFactory(
            learning_unit_year=self.learning_unit_year_3)

        self.be_organization_adr_city2 = OrganizationAddressFactory(
            country=self.a_be_country, city='Bruxelles')
        self.be_campus_2 = CampusFactory(
            organization=self.be_organization_adr_city2.organization)
        self.learning_container_year_4 = LearningContainerYearFactory(
            academic_year=self.academic_year)
        self.external_lu_BE_2 = ExternalLearningUnitYearFactory(
            learning_unit_year=LearningUnitYearFactory(
                learning_container_year=self.learning_container_year_4,
                academic_year=self.academic_year,
                campus=self.be_campus_2))
Example #13
0
 def setUpTestData(cls):
     current_year = datetime.date.today().year
     start_year = AcademicYearFactory(year=current_year - 2)
     end_year = AcademicYearFactory(year=current_year + 2)
     cls.academic_years = GenerateAcademicYear(start_year,
                                               end_year).academic_years
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=cls.academic_years[0],
         learning_unit_year__learning_container_year__container_type=
         learning_container_year_types.EXTERNAL,
         mobility=True,
         co_graduation=False,
     )
 def test_assert_ignore_external_learning_units_of_type_mobility(self):
     original_count = LearningUnitYear.objects.filter(externallearningunityear__co_graduation=True, externallearningunityear__mobility=False).count()
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=self.academic_year,
         mobility=True,
         co_graduation=False,
         learning_unit_year__acronym="XTEST1234",
     )
     form_data = {
         "academic_year": self.academic_year.id,
     }
     form = ExternalLearningUnitYearForm(form_data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.get_activity_learning_units().count(), original_count)
Example #15
0
 def test_search_on_external_cograduation(self):
     data = QueryDict(mutable=True)
     academic_year = self.academic_years[0]
     data.update({
         "academic_year_id": str(academic_year.id),
         "container_type": learning_container_year_types.EXTERNAL
     })
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=academic_year,
         learning_unit_year__learning_container_year__container_type=
         learning_container_year_types.EXTERNAL,
         mobility=True,
         co_graduation=False,
     )
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=academic_year,
         learning_unit_year__learning_container_year__container_type=
         learning_container_year_types.EXTERNAL,
         mobility=False,
         co_graduation=True,
     )
     form = LearningUnitYearForm(data)
     self.assertTrue(form.is_valid())
     self.assertEqual(form.get_queryset().count(), 1)
Example #16
0
    def test_get_results_external_ue(self):
        ExternalLearningUnitYearFactory(learning_unit_year=self.luy)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        luy_with_full_title = LearningUnitYear.objects.filter(
            pk=self.luy.pk).annotate_full_title()
        luy_with_full_title = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(
            luy_with_full_title).get()
        serializer = ExternalLearningUnitDetailedSerializer(
            luy_with_full_title,
            context={
                'request': RequestFactory().get(self.url),
                'language': settings.LANGUAGE_CODE
            })
        self.assertEqual(response.data, serializer.data)
Example #17
0
 def test_search_on_external_cograduation(self):
     self.data.update({
         "academic_year_id":
         str(self.academic_years[0].id),
         "container_type":
         learning_container_year_types.EXTERNAL
     })
     ExternalLearningUnitYearFactory(
         learning_unit_year__academic_year=self.academic_years[0],
         learning_unit_year__learning_container_year__container_type=
         learning_container_year_types.EXTERNAL,
         mobility=False,
         co_graduation=True,
     )
     learning_unit_filter = LearningUnitFilter(self.data)
     self.assertTrue(learning_unit_filter.is_valid())
     self.assertEqual(learning_unit_filter.qs.count(), 1)
Example #18
0
    def test_search_on_external_title(self):
        ExternalLearningUnitYearFactory(
            learning_unit_year__academic_year=self.academic_years[0],
            learning_unit_year__learning_container_year__container_type=
            learning_container_year_types.EXTERNAL,
            learning_unit_year__learning_container_year__common_title=TITLE,
        )

        self.data.update({
            "academic_year_id": str(self.academic_years[0].id),
            "container_type": learning_container_year_types.EXTERNAL,
            "title": TITLE
        })

        learning_unit_filter = ExternalLearningUnitFilter(self.data)
        self.assertTrue(learning_unit_filter.is_valid())
        self.assertEqual(learning_unit_filter.qs.count(), 1)
Example #19
0
    def test_contains_luy_borrowed_mobility(self):
        acronym = 'XTEST0022'
        eluy = ExternalLearningUnitYearFactory(
            learning_unit_year__acronym=acronym,
            learning_unit_year__academic_year=self.academic_year,
            mobility=True,
            co_graduation=False,
            learning_unit_year__learning_container_year__requirement_entity=self
            .BARC.entity,
            learning_unit_year__learning_container_year__allocation_entity=self
            .BARC.entity)
        luy = LearningUnitYear.objects.get(externallearningunityear=eluy)
        GroupElementYearFactory(parent=self.group_element_year_2.child_branch,
                                child_branch=None,
                                child_leaf=luy)

        node = json.dumps(EducationGroupHierarchy(self.parent).to_json())
        str_expected_service = '{}'.format(acronym)
        str_expected_not_service = '|E| {}'.format(acronym)
        self.assertTrue(str_expected_service in node)
        self.assertTrue(str_expected_not_service not in node)
Example #20
0
 def setUp(self):
     self.external = ExternalLearningUnitYearFactory(learning_unit_year=self.luy)
     self.client.force_login(self.user)
Example #21
0
 def test_is_external(self):
     luy = LearningUnitYearFactory()
     ExternalLearningUnitYearFactory(learning_unit_year=luy)
     self.assertTrue(luy.is_external())