Esempio n. 1
0
    def test_find_by_entity_reference(self):
        text_label_lu_3 = TextLabelFactory(
            order=1, label='program', entity=entity_name.LEARNING_UNIT_YEAR)
        text_label_oy_1 = TextLabelFactory(order=2,
                                           label='introduction',
                                           entity=entity_name.OFFER_YEAR)
        text_label_oy_2 = TextLabelFactory(order=3,
                                           label='profil',
                                           entity=entity_name.OFFER_YEAR)
        text_label_oy_3 = TextLabelFactory(order=4,
                                           label='job',
                                           entity=entity_name.OFFER_YEAR)

        TranslatedTextFactory(text_label=text_label_lu_3,
                              entity=entity_name.LEARNING_UNIT_YEAR,
                              reference=REFERENCE)

        TranslatedTextFactory(text_label=text_label_oy_1,
                              entity=entity_name.OFFER_YEAR,
                              reference=REFERENCE)
        TranslatedTextFactory(text_label=text_label_oy_2,
                              entity=entity_name.OFFER_YEAR,
                              reference=REFERENCE)
        TranslatedTextFactory(text_label=text_label_oy_3,
                              entity=entity_name.OFFER_YEAR,
                              reference=REFERENCE)

        tt = TranslatedText.objects.filter(
            text_label__entity=entity_name.OFFER_YEAR,
            reference=REFERENCE).order_by('text_label__order').values_list(
                'text_label__label', flat=True)
        self.assertEqual(list(tt), [
            text_label_oy_1.label, text_label_oy_2.label, text_label_oy_3.label
        ])
Esempio n. 2
0
    def test_delete_cms_data(self):
        """In this test, we will ensure that CMS data linked to the learning unit year is correctly deleted"""
        learning_container_year = LearningContainerYearFactory(academic_year=self.academic_year)
        learning_unit_year_to_delete = LearningUnitYearFactory(learning_container_year=learning_container_year,
                                                               subtype=learning_unit_year_subtypes.FULL,
                                                               academic_year=learning_container_year.academic_year)
        # Create CMS data - TAB Specification
        cms_specification_label = TextLabelFactory(entity=entity_name.LEARNING_UNIT_YEAR,
                                                   label=CMS_LABEL_SPECIFICATIONS[0])
        TranslatedTextFactory(entity=entity_name.LEARNING_UNIT_YEAR, reference=learning_unit_year_to_delete.pk,
                              text_label=cms_specification_label, text='Specification of learning unit year')
        # Create CMS data - TAB Pedagogy
        cms_pedagogy_label = TextLabelFactory(entity=entity_name.LEARNING_UNIT_YEAR,
                                              label=CMS_LABEL_PEDAGOGY[0])
        TranslatedTextFactory(entity=entity_name.LEARNING_UNIT_YEAR, reference=learning_unit_year_to_delete.pk,
                              text_label=cms_pedagogy_label, text='Pedagogy of learning unit year')
        # Create CMS data - TAB Summary
        cms_summary_label = TextLabelFactory(entity=entity_name.LEARNING_UNIT_YEAR,
                                             label=CMS_LABEL_SUMMARY[0])
        TranslatedTextFactory(entity=entity_name.LEARNING_UNIT_YEAR, reference=learning_unit_year_to_delete.pk,
                              text_label=cms_summary_label, text='Summary of learning unit year')

        # Before delete, we should have 3 data in CMS
        self.assertEqual(3, TranslatedText.objects.all().count())

        deletion._delete_cms_data(learning_unit_year_to_delete)

        # After deletion, we should have no data in CMS
        self.assertFalse(TranslatedText.objects.all().count())
Esempio n. 3
0
    def test_valid_post_request(self):
        new_text = "Hello world!!"
        translated_text = TranslatedTextFactory()
        response = self.client.post(self.url, data={"trans_text": new_text, "cms_id": translated_text.id})

        self.assertRedirects(response, reverse("learning_unit_summary", args=[self.learning_unit_year.id]))
        translated_text.refresh_from_db()
        self.assertEqual(translated_text.text, new_text)
Esempio n. 4
0
class TestEditEducationGroupAchievementAdditionalInformation(
        TestEducationGroupAchievementCMSSetup):
    def setUp(self):
        super().setUp()

        self.url = reverse(
            "education_group_achievement_additional_information",
            args=[
                self.education_group_year.pk,
                self.education_group_year.pk,
            ])

        self.text_label = TextLabelFactory(
            label=CMS_LABEL_ADDITIONAL_INFORMATION,
            entity=entity_name.OFFER_YEAR)
        self.program_aim_french = TranslatedTextFactory(
            text_label=self.text_label,
            language=LANGUAGE_CODE_FR,
            entity=entity_name.OFFER_YEAR,
            reference=self.education_group_year.pk,
            text="dummy text")

    def test_update_achievement_program_aim(self):
        """This test ensure that the french version is updated and the english version is created"""
        data = {
            "text_french": 'dummy text in french',
            "text_english": 'dummy text in english'
        }

        response = self.client.post(self.url, data=data)

        self.assertEqual(response.status_code, 302)
        self.program_aim_french.refresh_from_db()
        # Update french version
        self.assertEqual(self.program_aim_french.text, data['text_french'])
        # Create english version
        self.assertTrue(
            TranslatedText.objects.filter(
                text_label=self.text_label,
                reference=self.education_group_year.pk,
                language=LANGUAGE_CODE_EN,
                entity=entity_name.OFFER_YEAR,
                text=data['text_english']).exists())

    def test_update_without_permission(self):
        self.user.user_permissions.remove(
            Permission.objects.get(
                codename="change_educationgroupachievement"))
        response = self.client.post(self.url,
                                    data={'french_text': 'Evil hacker'})
        self.assertEqual(response.status_code, 403)

    def test_update_when_user_not_logged(self):
        self.client.logout()
        response = self.client.post(self.url,
                                    data={'french_text': 'Evil hacker'})
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, "/login/?next={}".format(self.url))
 def setUp(self):
     self.learning_unit_year = LearningUnitYearFactory(
         academic_year=create_current_academic_year()
     )
     self.laa = TranslatedTextFactory(
         reference=self.learning_unit_year.id
     )
     self.laa_en = TranslatedTextFactory(
         reference=self.learning_unit_year.id
     )
Esempio n. 6
0
    def setUpTestData(cls):
        cls.learning_unit_year = LearningUnitYearFactory()
        cls.translated_text = TranslatedTextFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=cls.learning_unit_year.id)

        cls.learning_unit_year_no_cms = LearningUnitYearFactory()
Esempio n. 7
0
    def test_learning_unit_pedagogy_edit(self):
        luy = self._create_learning_unit_year_for_entity(self.an_entity)
        edit_url = reverse(learning_unit_pedagogy_edit,
                           kwargs={'learning_unit_year_id': luy.id})

        text_label_bibliography = TextLabelFactory(
            entity=entity_name.LEARNING_UNIT_YEAR, label='bibliography')
        TranslatedTextFactory(entity=entity_name.LEARNING_UNIT_YEAR,
                              reference=luy.id,
                              language='fr-be',
                              text_label=text_label_bibliography,
                              text='Some random text')

        self.client.force_login(self.faculty_user)
        response = self.client.get(edit_url,
                                   data={
                                       'label': 'bibliography',
                                       'language': 'fr-be'
                                   })

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'learning_unit/pedagogy_edit.html')
        self.assertTemplateUsed(
            response, 'learning_unit/blocks/modal/modal_pedagogy_edit.html')
        self.assertEqual(response.context["cms_label_pedagogy_fr_only"],
                         CMS_LABEL_PEDAGOGY_FR_ONLY)
        self.assertEqual(response.context["label_name"], 'bibliography')
    def test_get_results_ensure_text_from_parent_if_partim_info_empty(self):
        partim = LearningUnitYearFactory(
            acronym=self.learning_unit_year.acronym + 'A',
            academic_year=self.academic_year,
            learning_container_year=self.learning_unit_year.
            learning_container_year,
            subtype=learning_unit_year_subtypes.PARTIM,
        )
        partims_labels = CMS_LABEL_PEDAGOGY + CMS_LABEL_SPECIFICATIONS
        partims_labels.remove('resume')
        for label in partims_labels:
            TranslatedTextFactory(reference=partim.pk,
                                  text_label__label=label,
                                  language=settings.LANGUAGE_CODE_FR)

        url_kwargs = {
            'acronym': partim.acronym,
            'year': partim.academic_year.year
        }
        url = reverse('learning_unit_api_v1:' +
                      LearningUnitSummarySpecification.name,
                      kwargs=url_kwargs)
        response = self.client.get(url)

        expected_keys = set(CMS_LABEL_PEDAGOGY + CMS_LABEL_SPECIFICATIONS)

        diff = set(response.data.keys()) - expected_keys
        self.assertFalse(diff)
        expected_parent_text = TranslatedText.objects.get(
            reference=self.learning_unit_year.pk,
            text_label__label='resume',
            language=settings.LANGUAGE_CODE_FR)
        self.assertEqual(response.data['resume'], expected_parent_text.text)
Esempio n. 9
0
    def setUp(self):
        super().setUp()

        self.url = reverse("education_group_achievement_program_aim",
                           args=[
                               self.education_group_year.pk,
                               self.education_group_year.pk,
                           ])
        self.text_label = TextLabelFactory(label=CMS_LABEL_PROGRAM_AIM,
                                           entity=entity_name.OFFER_YEAR)
        self.program_aim_french = TranslatedTextFactory(
            text_label=self.text_label,
            language=LANGUAGE_CODE_FR,
            entity=entity_name.OFFER_YEAR,
            reference=self.education_group_year.pk,
            text="dummy text")
Esempio n. 10
0
    def setUpTestData(cls):
        academic_year = AcademicYearFactory()
        type_training = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)
        cls.education_group_parent = EducationGroupYearFactory(
            acronym="Parent",
            academic_year=academic_year,
            education_group_type=type_training)
        cls.education_group_child = EducationGroupYearFactory(
            acronym="Child_1",
            academic_year=academic_year,
            education_group_type=type_training)

        GroupElementYearFactory(parent=cls.education_group_parent,
                                child_branch=cls.education_group_child)

        cls.cms_label_for_child = TranslatedTextFactory(
            text_label=TextLabelFactory(entity=entity_name.OFFER_YEAR),
            reference=cls.education_group_child.id)

        cls.user = UserFactory()
        cls.user.user_permissions.add(
            Permission.objects.get(codename="can_access_education_group"))
        cls.url = reverse("education_group_general_informations",
                          args=[cls.education_group_child.id])
Esempio n. 11
0
    def test_save_fr_bibliography_also_updates_en_bibliography(self, mock_update_or_create):
        """Ensure that if we modify bibliography in FR => bibliography in EN is updated with same text"""
        text_label_bibliography = TextLabelFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            label='bibliography'
        )
        cms_translated_text_fr = TranslatedTextFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=self.luys[self.current_ac.year].id,
            language='fr-be',
            text_label=text_label_bibliography,
            text='Some random text'
        )
        valid_form_data_fr = _get_valid_cms_form_data(cms_translated_text_fr)

        form = LearningUnitPedagogyEditForm(valid_form_data_fr)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        for language in settings.LANGUAGES:
            mock_update_or_create.assert_any_call(
                entity=cms_translated_text_fr.entity,
                reference=cms_translated_text_fr.reference,
                language=language[0],
                text_label=cms_translated_text_fr.text_label,
                defaults={'text': cms_translated_text_fr.text}
            )
Esempio n. 12
0
    def setUpTestData(cls):
        cls.education_group_year = EducationGroupYearFactory()
        cls.translated_text = TranslatedTextFactory(
            entity=entity_name.OFFER_YEAR,
            reference=cls.education_group_year.id)

        cls.education_group_year_no_cms = EducationGroupYearFactory()
Esempio n. 13
0
 def setUp(self):
     self.cms_label_name = 'skills_and_achievements_introduction'
     self.education_group_year = EducationGroupYearFactory()
     self.introduction = TranslatedTextFactory(
         entity=entity_name.OFFER_YEAR,
         reference=self.education_group_year.pk,
         language=settings.LANGUAGE_CODE_EN,
         text_label__label=self.cms_label_name)
Esempio n. 14
0
 def setUp(self):
     super().setUp()
     self.cms_translated_text = TranslatedTextFactory(
         entity=entity_name.LEARNING_UNIT_YEAR,
         reference=self.luys[self.current_ac.year].id,
         language='EN',
         text='Text random')
     self.valid_form_data = _get_valid_cms_form_data(
         self.cms_translated_text)
Esempio n. 15
0
 def setUp(self):
     TranslatedTextFactory(
         entity=entity_name.LEARNING_UNIT_YEAR,
         reference=self.learning_unit_year.pk,
         language='fr-be',
         text='Some random text',
         text_label__entity=entity_name.LEARNING_UNIT_YEAR,
         text_label__label='bibliography',
     )
     self.client.force_login(self.faculty_person.user)
Esempio n. 16
0
 def test_get_certificate_aim(self):
     certificate_aim_french = TranslatedTextFactory(
         entity=entity_name.OFFER_YEAR,
         reference=self.education_group_year.id,
         text_label__label=CMS_LABEL_PROGRAM_AIM,
         language=settings.LANGUAGE_CODE_FR,
     )
     certificate_aim_english = TranslatedTextFactory(
         entity=entity_name.OFFER_YEAR,
         reference=self.education_group_year.id,
         text_label__label=CMS_LABEL_PROGRAM_AIM,
         language=settings.LANGUAGE_CODE_EN,
     )
     response = self._call_url_as_http_get()
     self.assertEqual(
         response.context[CMS_LABEL_PROGRAM_AIM][settings.LANGUAGE_CODE_FR],
         certificate_aim_french)
     self.assertEqual(
         response.context[CMS_LABEL_PROGRAM_AIM][settings.LANGUAGE_CODE_EN],
         certificate_aim_english)
Esempio n. 17
0
 def test_get_additional_informations(self):
     additional_infos_french = TranslatedTextFactory(
         entity=entity_name.OFFER_YEAR,
         reference=self.education_group_year.id,
         text_label__label=CMS_LABEL_ADDITIONAL_INFORMATION,
         language=settings.LANGUAGE_CODE_FR,
     )
     additional_infos_english = TranslatedTextFactory(
         entity=entity_name.OFFER_YEAR,
         reference=self.education_group_year.id,
         text_label__label=CMS_LABEL_ADDITIONAL_INFORMATION,
         language=settings.LANGUAGE_CODE_EN,
     )
     response = self._call_url_as_http_get()
     self.assertEqual(
         response.context[CMS_LABEL_ADDITIONAL_INFORMATION][
             settings.LANGUAGE_CODE_FR], additional_infos_french)
     self.assertEqual(
         response.context[CMS_LABEL_ADDITIONAL_INFORMATION][
             settings.LANGUAGE_CODE_EN], additional_infos_english)
Esempio n. 18
0
 def setUpTestData(cls):
     cls.language = settings.LANGUAGE_CODE_EN
     cls.egy = EducationGroupYearFactory()
     for label in [
             SKILLS_AND_ACHIEVEMENTS_INTRO, SKILLS_AND_ACHIEVEMENTS_EXTRA
     ]:
         TranslatedTextFactory(text_label__label=label,
                               reference=cls.egy.id,
                               entity=OFFER_YEAR,
                               language=cls.language)
     cls.serializer = AchievementsSerializer(cls.egy,
                                             context={'lang': cls.language})
Esempio n. 19
0
 def setUpTestData(cls):
     cls.egy = TrainingFactory(
         education_group_type__name=TrainingType.PGRM_MASTER_120.name)
     cls.common_egy = EducationGroupYearCommonFactory(
         academic_year=cls.egy.academic_year)
     cls.language = settings.LANGUAGE_CODE_EN
     cls.pertinent_sections = {
         'specific': [DETAILED_PROGRAM, SKILLS_AND_ACHIEVEMENTS],
         'common': [COMMON_DIDACTIC_PURPOSES]
     }
     for section in cls.pertinent_sections['common']:
         TranslatedTextLabelFactory(language=cls.language,
                                    text_label__label=section)
         TranslatedTextFactory(
             reference=cls.common_egy.id,
             entity=OFFER_YEAR,
             language=cls.language,
             text_label__label=section,
         )
     for section in cls.pertinent_sections['specific']:
         TranslatedTextLabelFactory(language=cls.language,
                                    text_label__label=section)
         TranslatedTextFactory(reference=cls.egy.id,
                               entity=OFFER_YEAR,
                               language=cls.language,
                               text_label__label=section)
     for label in [
             SKILLS_AND_ACHIEVEMENTS_INTRO, SKILLS_AND_ACHIEVEMENTS_EXTRA
     ]:
         TranslatedTextFactory(text_label__label=label,
                               reference=cls.egy.id,
                               entity=OFFER_YEAR,
                               language=cls.language)
     cls.serializer = GeneralInformationSerializer(cls.egy,
                                                   context={
                                                       'language':
                                                       cls.language,
                                                       'acronym':
                                                       cls.egy.acronym
                                                   })
Esempio n. 20
0
 def setUpTestData(cls):
     cls.person = PersonFactory()
     cls.language = settings.LANGUAGE_CODE_EN
     cls.egy = EducationGroupYearFactory()
     common_egy = EducationGroupYearCommonFactory(academic_year=cls.egy.academic_year)
     cls.pertinent_sections = {
         'specific': [EVALUATION_KEY, DETAILED_PROGRAM, SKILLS_AND_ACHIEVEMENTS],
         'common': [COMMON_DIDACTIC_PURPOSES, EVALUATION_KEY]
     }
     for section in cls.pertinent_sections['common']:
         TranslatedTextLabelFactory(language=cls.language, text_label__label=section)
         TranslatedTextFactory(
             reference=common_egy.id,
             entity=OFFER_YEAR,
             language=cls.language,
             text_label__label=section
         )
     for section in cls.pertinent_sections['specific']:
         if section != EVALUATION_KEY:
             TranslatedTextLabelFactory(language=cls.language, text_label__label=section)
         TranslatedTextFactory(
             reference=cls.egy.id,
             entity=OFFER_YEAR,
             language=cls.language,
             text_label__label=section
         )
     for label in [SKILLS_AND_ACHIEVEMENTS_INTRO, SKILLS_AND_ACHIEVEMENTS_EXTRA]:
         TranslatedTextFactory(
             text_label__label=label,
             reference=cls.egy.id,
             entity=OFFER_YEAR,
             language=cls.language
         )
     cls.url = reverse('generalinformations_read', kwargs={
         'acronym': cls.egy.acronym,
         'year': cls.egy.academic_year.year,
         'language': cls.language
     })
Esempio n. 21
0
    def test_find_by_entity_reference(self):
        text_label_lu_3 = TextLabelFactory(
            order=1, label='program', entity=entity_name.LEARNING_UNIT_YEAR)
        text_label_oy_1 = TextLabelFactory(order=2,
                                           label='introduction',
                                           entity=entity_name.OFFER_YEAR)
        text_label_oy_2 = TextLabelFactory(order=3,
                                           label='profil',
                                           entity=entity_name.OFFER_YEAR)
        text_label_oy_3 = TextLabelFactory(order=4,
                                           label='job',
                                           entity=entity_name.OFFER_YEAR)

        translated_text_lu_1 = TranslatedTextFactory(
            text_label=text_label_lu_3,
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=REFERENCE)

        translated_text_oy_1 = TranslatedTextFactory(
            text_label=text_label_oy_1,
            entity=entity_name.OFFER_YEAR,
            reference=REFERENCE)
        translated_text_oy_2 = TranslatedTextFactory(
            text_label=text_label_oy_2,
            entity=entity_name.OFFER_YEAR,
            reference=REFERENCE)
        translated_text_oy_3 = TranslatedTextFactory(
            text_label=text_label_oy_3,
            entity=entity_name.OFFER_YEAR,
            reference=REFERENCE)

        self.assertEqual(
            list(
                translated_text.find_by_entity_reference(
                    entity_name.OFFER_YEAR, REFERENCE)), [
                        text_label_oy_1.label, text_label_oy_2.label,
                        text_label_oy_3.label
                    ])
Esempio n. 22
0
 def _get_pertinent_intro_section(self, gey, egy):
     TranslatedTextLabelFactory(
         text_label__label=INTRODUCTION,
         language=self.language,
     )
     TranslatedTextFactory(text_label__label=INTRODUCTION,
                           language=self.language,
                           entity=OFFER_YEAR,
                           reference=gey.child_branch.id)
     return GeneralInformationSerializer(egy,
                                         context={
                                             'language': self.language,
                                             'acronym': egy.acronym
                                         }).data['sections'][0]
Esempio n. 23
0
    def test_save_with_postponement(self, mock_update_or_create):
        """In this test, we ensure that if we modify UE of N+1 or N+X => The postponement until the lastest UE"""
        luy_in_future = self.luys[self.current_ac.year + 1]
        cms_pedagogy_future = TranslatedTextFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=luy_in_future.id,
            language='EN',
            text='Text in future')
        form = LearningUnitPedagogyEditForm(
            data=_get_valid_cms_form_data(cms_pedagogy_future))
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        # N+1 ===> N+6
        self.assertEqual(mock_update_or_create.call_count, 5)
Esempio n. 24
0
 def _create_needed_cms_label(cls, cms_labels, with_en):
     for idx, cms_label in enumerate(cms_labels):
         tl = TextLabelFactory(label=cms_label, entity=LEARNING_UNIT_YEAR)
         TranslatedTextLabelFactory(text_label=tl,
                                    language=LANGUAGE_CODE_FR,
                                    label="{}{}".format(
                                        PREFIX_FAKE_LABEL, cms_label))
         TranslatedTextLabelFactory(text_label=tl,
                                    language=LANGUAGE_CODE_EN,
                                    label="{}{}".format(
                                        PREFIX_FAKE_LABEL, cms_label))
         TranslatedTextFactory(language=LANGUAGE_CODE_FR,
                               text="{}{} - FR".format(
                                   PREFIX_FAKE_TEXT_LABEL, cms_label),
                               text_label=tl,
                               reference=cls.l_unit_yr_1.id,
                               entity=LEARNING_UNIT_YEAR)
         if with_en:
             TranslatedTextFactory(language=LANGUAGE_CODE_EN,
                                   text="{}{} - EN".format(
                                       PREFIX_FAKE_TEXT_LABEL, cms_label),
                                   text_label=tl,
                                   reference=cls.l_unit_yr_1.id,
                                   entity=LEARNING_UNIT_YEAR)
Esempio n. 25
0
    def setUpTestData(cls):
        cls.language = settings.LANGUAGE_CODE_EN
        cls.egy = EducationGroupYearCommonFactory()
        cls.pertinent_sections = general_information_sections.SECTIONS_PER_OFFER_TYPE['common']
        cls.data = {}
        for section in cls.pertinent_sections['specific']:
            tt = TranslatedTextFactory(
                reference=cls.egy.id,
                entity=OFFER_YEAR,
                language=cls.language,
                text_label__label=section
            )
            cls.data[tt.text_label.label] = tt.text

        cls.serializer = CommonTextSerializer(cls.data, context={'language': cls.language})
Esempio n. 26
0
 def setUpTestData(cls):
     cls.person = PersonFactory()
     cls.language = settings.LANGUAGE_CODE_EN
     cls.egy = EducationGroupYearCommonFactory()
     cls.pertinent_sections = general_information_sections.SECTIONS_PER_OFFER_TYPE[
         'common']
     cls.data = {}
     for section in cls.pertinent_sections['specific']:
         tt = TranslatedTextFactory(reference=cls.egy.id,
                                    entity=OFFER_YEAR,
                                    language=cls.language,
                                    text_label__label=section)
         cls.data[tt.text_label.label] = tt.text
     cls.url = reverse(CommonText.name,
                       kwargs={
                           'year': cls.egy.academic_year.year,
                           'language': cls.language
                       })
Esempio n. 27
0
    def test_learning_units_summary_list_by_client_xls(self):
        # Generate data
        now = datetime.datetime.now()
        EntityVersionFactory(entity=self.an_entity,
                             start_date=now,
                             end_date=datetime.datetime(now.year+1, 9, 15),
                             entity_type='INSTITUTE')

        luy = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1100")
        self._create_entity_calendar(self.an_entity)

        TeachingMaterialFactory(learning_unit_year=luy, title="Magic wand", mandatory=True)
        TeachingMaterialFactory(learning_unit_year=luy, title="Broomsticks", mandatory=False)

        luy_without_mandatory_teaching_material = self._create_learning_unit_year_for_entity(self.an_entity, "LBIR1101")
        TeachingMaterialFactory(learning_unit_year=luy_without_mandatory_teaching_material, title="cauldron", mandatory=False)
        bibliography = TranslatedTextFactory(
            text_label=TextLabelFactory(label='bibliography'),
            entity=LEARNING_UNIT_YEAR,
            text="<ul><li>Test</li></ul>",
            reference=luy.pk,
            language='fr-be'
        )
        online_resources = TranslatedTextFactory(
            text_label=TextLabelFactory(label='online_resources'),
            entity=LEARNING_UNIT_YEAR,
            text="<a href='test_url'>TestURL</a>",
            reference=luy.pk,
            language='fr-be'
        )
        online_resources_en = TranslatedTextFactory(
            text_label=TextLabelFactory(label='online_resources'),
            entity=LEARNING_UNIT_YEAR,
            text="<a href='test_url'>TestURL EN</a>",
            reference=luy.pk,
            language='en'
        )

        # Test the view
        self.client.force_login(self.faculty_user)
        response = self.client.get(self.url, data={
            'academic_year_id': starting_academic_year().id,
            'xls_status': 'xls_teaching_material'
        })

        # OK, the server returned the xls file
        self.assertEqual(response.status_code, 200)
        wb = load_workbook(BytesIO(response.content), read_only=True)

        sheet = wb.active
        data = sheet['A1': 'G3']

        # Check the first row content
        titles = next(data)
        title_values = list(t.value for t in titles)
        self.assertEqual(title_values, [
            str(_('code')).title(),
            str(_('Title')),
            str(_('Req. Entity')).title(),
            str(_('bibliography')).title(),
            str(_('teaching materials')).title(),
            str("{} - Fr-Be".format(_('online resources'))).title(),
            str("{} - En".format(_('online resources'))).title(),
        ])

        # Check data from the luy
        first_luy = next(data)
        first_luy_values = list(t.value for t in first_luy)
        self.assertEqual(first_luy_values, [
            luy.acronym,
            luy.complete_title,
            str(luy.requirement_entity),
            "Test\n",
            "Magic wand",
            "TestURL - [test_url] \n",
            "TestURL EN - [test_url] \n"
        ])

        # The second luy has no mandatory teaching material
        with self.assertRaises(StopIteration):
            next(data)
Esempio n. 28
0
    def test_learning_units_summary_list_by_client_xls(self):
        bibliography = TranslatedTextFactory(
            text_label=TextLabelFactory(label='bibliography'),
            entity=LEARNING_UNIT_YEAR,
            text="<ul><li>Test</li></ul>",
            reference=self.
            learning_unit_year_with_mandatory_teaching_materials.pk,
            language='fr-be')
        online_resources = TranslatedTextFactory(
            text_label=TextLabelFactory(label='online_resources'),
            entity=LEARNING_UNIT_YEAR,
            text="<a href='test_url'>TestURL</a>",
            reference=self.
            learning_unit_year_with_mandatory_teaching_materials.pk,
            language='fr-be')
        online_resources_en = TranslatedTextFactory(
            text_label=TextLabelFactory(label='online_resources'),
            entity=LEARNING_UNIT_YEAR,
            text="<a href='test_url'>TestURL EN</a>",
            reference=self.
            learning_unit_year_with_mandatory_teaching_materials.pk,
            language='en')

        response = self.client.get(self.url,
                                   data={
                                       'academic_year': self.academic_year.pk,
                                       'xls_status': 'xls_teaching_material'
                                   })

        # The server returned the xls file
        self.assertEqual(response.status_code, HttpResponse.status_code)
        wb = load_workbook(BytesIO(response.content), read_only=True)

        sheet = wb.active
        data = sheet['A1':'G3']

        # Check the first row content
        titles = next(data)
        title_values = list(t.value for t in titles)
        self.assertEqual(title_values, [
            str(_('code')).title(),
            str(_('Title')),
            str(_('Req. Entity')).title(),
            str(_('bibliography')).title(),
            str(_('teaching materials')).title(),
            str("{} - Fr-Be".format(_('online resources'))).title(),
            str("{} - En".format(_('online resources'))).title(),
        ])

        # Check data from the luy
        first_luy = next(data)
        first_luy_values = list(t.value for t in first_luy)
        self.assertEqual(first_luy_values, [
            self.learning_unit_year_with_mandatory_teaching_materials.acronym,
            self.learning_unit_year_with_mandatory_teaching_materials.
            complete_title,
            str(self.learning_unit_year_with_mandatory_teaching_materials.
                requirement_entity), "Test\n", "Magic wand",
            "TestURL - [test_url] \n", "TestURL EN - [test_url] \n"
        ])

        # The second luy has no mandatory teaching material
        with self.assertRaises(StopIteration):
            next(data)
Esempio n. 29
0
def _create_cms_data_for_luy(luy, quantity=10):
    for _ in range(quantity):
        TranslatedTextFactory(reference=luy.id, text=factory.fuzzy.FuzzyText(length=255).fuzz())
    def test_postpone(self):
        self.current_education_group_year = EducationGroupYearFactory(
            academic_year=self.current_year)

        publication_contact_entity = EntityFactory()
        self.previous_education_group_year = EducationGroupYearFactory(
            academic_year=self.previous_year,
            education_group=self.current_education_group_year.education_group,
            publication_contact_entity=publication_contact_entity,
        )

        TranslatedTextFactory(
            entity=OFFER_YEAR,
            reference=str(self.previous_education_group_year.pk),
            text=
            "It is our choices, Harry, that show what we truly are, far more than our abilities."
        )
        EducationGroupPublicationContactFactory(
            education_group_year=self.previous_education_group_year)

        EducationGroupDetailedAchievementFactory(
            education_group_achievement__education_group_year=self.
            previous_education_group_year)
        AdmissionConditionLineFactory(
            admission_condition__education_group_year=self.
            previous_education_group_year,
            section="nothing else matters")

        # this object will be removed during the copy.
        AdmissionConditionLineFactory(
            admission_condition__education_group_year=self.
            current_education_group_year,
            section="the world is dying.")

        postponer = ReddotEducationGroupAutomaticPostponement()
        postponer.postpone()

        self.assertEqual(len(postponer.result), 1)
        self.assertEqual(len(postponer.errors), 0)
        self.assertEqual(
            TranslatedText.objects.get(
                entity=OFFER_YEAR,
                reference=str(self.current_education_group_year.pk)).text,
            "It is our choices, Harry, that show what we truly are, far more than our abilities."
        )
        self.assertTrue(
            EducationGroupPublicationContact.objects.filter(
                education_group_year=self.current_education_group_year).exists(
                ))
        self.current_education_group_year.refresh_from_db()
        self.assertEqual(
            self.current_education_group_year.publication_contact_entity,
            publication_contact_entity)

        self.assertTrue(
            EducationGroupDetailedAchievement.objects.filter(
                education_group_achievement__education_group_year=self.
                current_education_group_year).exists())

        self.assertTrue(
            AdmissionConditionLine.objects.get(
                admission_condition__education_group_year=self.
                current_education_group_year).section, "nothing else matters")