Ejemplo n.º 1
0
    def setUp(self):
        super().setUp()

        self.user = UserFactory()
        self.person = PersonFactory(user=self.user)

        # the user can access to the education group
        self.user.user_permissions.add(
            Permission.objects.get(codename='can_access_education_group'))

        academic_year = AcademicYearFactory()

        type_training = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        self.education_group_parent = EducationGroupYearFactory(
            acronym="Parent",
            academic_year=academic_year,
            education_group_type=type_training)

        self.education_group_year = EducationGroupYearFactory(
            acronym="Child_1",
            academic_year=academic_year,
            education_group_type=type_training)

        GroupElementYearFactory(parent=self.education_group_parent,
                                child_branch=self.education_group_year)

        self.text_label = TextLabelFactory(label='welcome_introduction',
                                           entity=entity_name.OFFER_YEAR)

        TranslatedTextLabelFactory(text_label=self.text_label,
                                   language="fr-be",
                                   label='Introduction')

        TranslatedTextLabelFactory(text_label=self.text_label,
                                   language="en",
                                   label='Introduction')
        # fr-be
        TranslatedTextRandomFactory(text_label=self.text_label,
                                    entity=self.text_label.entity,
                                    reference=str(
                                        self.education_group_year.id))

        # en
        EnglishTranslatedTextRandomFactory(text_label=self.text_label,
                                           entity=self.text_label.entity,
                                           reference=str(
                                               self.education_group_year.id))
        page = LoginPage(driver=self.selenium,
                         base_url=self.live_server_url + '/login/').open()

        page.login(username=self.user.username)

        self.url = reverse('education_group_general_informations',
                           args=[
                               self.education_group_parent.id,
                               self.education_group_year.id
                           ])
Ejemplo n.º 2
0
    def test_no_translation_for_term(self):
        education_group_year = EducationGroupYearMasterFactory()

        iso_language, language = 'fr-be', 'fr'

        text_label = TextLabelFactory(entity=OFFER_YEAR)
        translated_text_label = TranslatedTextLabelFactory(text_label=text_label, language=iso_language)

        message = {
            'anac': str(education_group_year.academic_year.year),
            'code_offre': education_group_year.acronym,
            'sections': [text_label.label]
        }

        response = self.post(
            year=education_group_year.academic_year.year,
            language=language,
            acronym=education_group_year.acronym,
            data=message
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content_type, 'application/json')

        response_json = response.json()
        sections, conditions_admission_section = remove_conditions_admission(response_json['sections'])
        response_sections = convert_sections_list_of_dict_to_dict(sections)

        sections = convert_sections_list_of_dict_to_dict([{
            'id': text_label.label,
            'label': translated_text_label.label,
            'content': None
        }])

        self.assertEqual(response_sections, sections)
Ejemplo n.º 3
0
    def setUp(self):
        super().setUp()

        self.user = UserFactory()
        # the user can access to the education group
        self.user.user_permissions.add(Permission.objects.get(codename='can_access_education_group'))
        # and can edit the education groups
        # self.user.user_permissions.add(Permission.objects.get(codename='can_edit_educationgroup_pedagogy'))

        academic_year = AcademicYearFactory()
        self.education_group_year = EducationGroupYearFactory(academic_year=academic_year)

        self.text_label = TextLabelFactory(entity=entity_name.OFFER_YEAR)

        self.translated_text_label = TranslatedTextLabelFactory(text_label=self.text_label,
                                                                label='Intro')
        # fr-be
        TranslatedTextRandomFactory(text_label=self.text_label,
                                    entity=self.text_label.entity,
                                    reference=str(self.education_group_year.id))

        # en
        TranslatedTextRandomFactory(text_label=self.text_label,
                                    entity=self.text_label.entity,
                                    language='en',
                                    reference=str(self.education_group_year.id))
        page = LoginPage(
            driver=self.selenium,
            base_url=self.live_server_url + '/login/'
        ).open()

        page.login(username=self.user.username)

        self.url = reverse('education_group_general_informations', args=[self.education_group_year.id])
Ejemplo n.º 4
0
 def test_get_label_translation(self):
     text_label = TextLabelFactory(entity=entity_name.OFFER_YEAR,
                                   label='TEST_LABEL')
     TranslatedTextLabelFactory(language='fr-be',
                                text_label=text_label,
                                label='TEST_LABEL_TRANSLATED')
     self.assertEqual(
         get_label_translation(text_entity=entity_name.OFFER_YEAR,
                               label='TEST_LABEL',
                               language='fr-be'), 'TEST_LABEL_TRANSLATED')
Ejemplo n.º 5
0
 def test_get_label_translation(self):
     text_label = TextLabelFactory(entity=entity_name.OFFER_YEAR,
                                   label='TEST_LABEL')
     TranslatedTextLabelFactory(language=settings.LANGUAGE_CODE_FR,
                                text_label=text_label,
                                label='TEST_LABEL_TRANSLATED')
     self.assertEqual(
         get_label_translation(text_entity=entity_name.OFFER_YEAR,
                               label='TEST_LABEL',
                               language=settings.LANGUAGE_CODE_FR),
         'TEST_LABEL_TRANSLATED')
Ejemplo n.º 6
0
    def test_with_one_section(self):
        education_group_year = EducationGroupYearFactory(acronym='actu2m')

        text_label = TextLabelFactory(entity=OFFER_YEAR, label='caap')

        for iso_language, language in [('fr-be', 'fr'), ('en', 'en')]:
            with self.subTest(iso_language=iso_language, language=language):
                ttl = TranslatedTextLabelFactory(text_label=text_label,
                                                 language=iso_language)
                tt = TranslatedTextRandomFactory(
                    text_label=text_label,
                    language=iso_language,
                    reference=education_group_year.id,
                    entity=text_label.entity)

                message = {
                    'code_offre': education_group_year.acronym,
                    'anac': str(education_group_year.academic_year.year),
                    'sections': [
                        text_label.label,
                    ]
                }

                response = self.post(education_group_year.academic_year.year,
                                     language,
                                     education_group_year.acronym,
                                     data=message)

                self.assertEqual(response.status_code, 200)
                self.assertEqual(response.content_type, 'application/json')

                response_json = response.json()
                sections, conditions_admission_section = remove_conditions_admission(
                    response_json['sections'])
                response_json['sections'] = sections

                title_to_test = education_group_year.title if language == 'fr' else education_group_year.title_english

                self.assertDictEqual(
                    response_json, {
                        'acronym':
                        education_group_year.acronym.upper(),
                        'language':
                        language,
                        'title':
                        title_to_test,
                        'year':
                        education_group_year.academic_year.year,
                        'sections': [{
                            'label': ttl.label,
                            'id': tt.text_label.label,
                            'content': tt.text,
                        }]
                    })
Ejemplo n.º 7
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
                                                   })
Ejemplo n.º 8
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
     })
Ejemplo n.º 9
0
    def test_valid_get_request_with_translated_text_labels(self):
        language = "fr-be"
        self.tutor.person.language = language
        self.tutor.person.save()
        trans_text_label = TranslatedTextLabelFactory()
        response = self.client.get(self.url, data={"language": language, "label": trans_text_label.text_label.label})

        self.assertTemplateUsed(response, "my_osis/educational_information_edit.html")

        context = response.context
        self.assertEqual(context["learning_unit_year"], self.learning_unit_year)
        self.assertTrue(context["form"])
        self.assertEqual(context["text_label_translated"], trans_text_label)
        self.assertEqual(context["language_translated"], ('fr-be', _('French')))
Ejemplo n.º 10
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]
Ejemplo n.º 11
0
 def test_case_text_not_existing(self):
     with mock.patch(
             'base.business.education_groups.general_information_sections.SECTIONS_PER_OFFER_TYPE',
             _get_mocked_sections_per_offer_type(
                 self.egy, specific=[WELCOME_INTRODUCTION])):
         TranslatedTextLabelFactory(language=self.language,
                                    text_label__label=WELCOME_INTRODUCTION)
         welcome_introduction_section = GeneralInformationSerializer(
             self.egy,
             context={
                 'language': self.language,
                 'acronym': self.egy.acronym
             }).data['sections'][0]
         self.assertIsNone(welcome_introduction_section['content'])
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    def test_raise_with_unknown_common_text(self):
        from webservices.views import process_section
        education_group_year = EducationGroupYearMasterFactory()
        education_group_year_common = EducationGroupYearCommonMasterFactory(
            academic_year=education_group_year.academic_year
        )

        context = new_context(education_group_year, 'fr-be', 'fr', education_group_year.acronym)

        text_label = TextLabelFactory(label='caap', entity='offer_year')
        translated_text_label = TranslatedTextLabelFactory(text_label=text_label, language=context.language)
        tt = TranslatedTextRandomFactory(text_label=text_label,
                                         language=context.language,
                                         reference=str(education_group_year_common.id),
                                         entity=text_label.entity)

        section = process_section(context, education_group_year, 'nothing-commun')
        self.assertIsNone(section['label'])
Ejemplo n.º 14
0
    def setUp(self):
        self.education_group_year = EducationGroupYearFactory(acronym='ACTU2M')

        common_education_group_year = EducationGroupYearCommonFactory(
            academic_year=self.education_group_year.academic_year
        )
        self.cms_label_name = 'evaluation'

        text_label = TextLabelFactory(entity=OFFER_YEAR, label='evaluation')
        TranslatedTextLabelFactory(text_label=text_label,
                                   language='fr-be')
        self.evaluation = TranslatedTextRandomFactory(text_label=text_label,
                                                      language='fr-be',
                                                      reference=self.education_group_year.id,
                                                      entity=text_label.entity)

        self.common = TranslatedTextRandomFactory(text_label=text_label,
                                                  language='fr-be',
                                                  reference=common_education_group_year.id,
                                                  entity=text_label.entity)
Ejemplo n.º 15
0
    def test_find_common_text(self):
        from webservices.views import process_section
        education_group_year = EducationGroupYearMasterFactory()
        education_group_year_common = EducationGroupYearCommonMasterFactory(
            academic_year=education_group_year.academic_year,
        )

        context = new_context(education_group_year, 'fr-be', 'fr', education_group_year.acronym)

        text_label = TextLabelFactory(label='caap', entity='offer_year')
        translated_text_label = TranslatedTextLabelFactory(text_label=text_label, language=context.language)
        tt = TranslatedTextRandomFactory(text_label=text_label,
                                         language=context.language,
                                         reference=str(education_group_year_common.id),
                                         entity=text_label.entity)

        section = process_section(context, education_group_year, 'caap-commun')
        self.assertEqual(translated_text_label.text_label, text_label)
        self.assertEqual(section['label'], translated_text_label.label)
        self.assertEqual(section['content'], tt.text)
Ejemplo n.º 16
0
    def test_intro(self):
        from webservices.views import process_section
        education_group_year_random = EducationGroupYearFactory()
        education_group_year = EducationGroupYearFactory(
            partial_acronym='ldvld100i',
            academic_year=education_group_year_random.academic_year
        )
        context = new_context(education_group_year_random,
                              'fr-be', 'fr', education_group_year_random.acronym)

        text_label = TextLabelFactory(entity='offer_year', label='intro')
        translated_text_label = TranslatedTextLabelFactory(text_label=text_label, language=context.language)
        tt = TranslatedTextRandomFactory(text_label=text_label,
                                         language=context.language,
                                         reference=str(education_group_year.id),
                                         entity=text_label.entity)

        section = process_section(context, education_group_year, 'intro-ldvld100i')

        self.assertEqual(translated_text_label.text_label, text_label)
        self.assertEqual(section['label'], translated_text_label.label)
        self.assertEqual(section['content'], tt.text)
Ejemplo n.º 17
0
    def test_first_based_on_the_original_message(self):
        education_group_year = EducationGroupYearFactory(acronym='ACTU2M')

        common_education_group_year = EducationGroupYearFactory(
            acronym='common', academic_year=education_group_year.academic_year)

        iso_language, language = 'fr-be', 'fr'

        message = {
            'anac':
            str(education_group_year.academic_year.year),
            'code_offre':
            education_group_year.acronym,
            "sections": [
                "welcome_job", "welcome_profil", "welcome_programme",
                "welcome_introduction", "cond_admission", "infos_pratiques",
                "caap", "caap-commun", "contacts", "structure",
                "acces_professions", "comp_acquis", "pedagogie",
                "formations_accessibles", "evaluation", "mobilite",
                "programme_detaille", "certificats", "module_complementaire",
                "module_complementaire-commun", "prerequis",
                "prerequis-commun", "intro-lactu200t", "intro-lactu200s",
                "options", "intro-lactu200o", "intro-lsst100o"
            ]
        }

        ega = EducationGroupYearFactory(
            partial_acronym='lactu200t',
            academic_year=education_group_year.academic_year)
        text_label = TextLabelFactory(entity=OFFER_YEAR, label='intro')
        TranslatedTextLabelFactory(text_label=text_label,
                                   language=iso_language)
        TranslatedTextRandomFactory(text_label=text_label,
                                    language=iso_language,
                                    reference=ega.id,
                                    entity=text_label.entity)

        text_label = TextLabelFactory(entity=OFFER_YEAR, label='prerequis')
        TranslatedTextLabelFactory(text_label=text_label,
                                   language=iso_language)
        TranslatedTextRandomFactory(text_label=text_label,
                                    language=iso_language,
                                    reference=education_group_year.id,
                                    entity=text_label.entity)

        TranslatedTextRandomFactory(text_label=text_label,
                                    language=iso_language,
                                    reference=common_education_group_year.id,
                                    entity=text_label.entity)

        text_label = TextLabelFactory(entity=OFFER_YEAR, label='caap')
        TranslatedTextLabelFactory(text_label=text_label,
                                   language=iso_language)
        TranslatedTextRandomFactory(text_label=text_label,
                                    language=iso_language,
                                    reference=education_group_year.id,
                                    entity=text_label.entity)

        TranslatedTextRandomFactory(text_label=text_label,
                                    language=iso_language,
                                    reference=common_education_group_year.id,
                                    entity=text_label.entity)

        response = self.post(
            education_group_year.academic_year.year,
            language,
            education_group_year.acronym,
            data=message,
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content_type, 'application/json')
Ejemplo n.º 18
0
    def test_global(self):
        education_group_year = EducationGroupYearFactory(acronym='ACTU2M')

        common_education_group_year = EducationGroupYearFactory(
            acronym='common', academic_year=education_group_year.academic_year)

        iso_language, language = 'fr-be', 'fr'

        sections = [
            "welcome_job", "welcome_profil", "welcome_programme",
            "welcome_introduction", "cond_admission", "infos_pratiques",
            "caap", "caap-commun", "contacts", "structure",
            "acces_professions", "comp_acquis", "pedagogie",
            "formations_accessibles", "evaluation", "mobilite",
            "programme_detaille", "certificats", "module_complementaire",
            "module_complementaire-commun", "prerequis", "prerequis-commun",
            "intro-lactu200t", "intro-lactu200s", "options", "intro-lactu200o",
            "intro-lsst100o"
        ]

        sections_set, common_sections_set, intro_set = set(), set(), set()

        for section in sections:
            if section.startswith('intro-'):
                intro_set.add(section[len('intro-'):])
                continue
            if section.endswith('-commun'):
                section = section[:-len('-commun')]
                common_sections_set.add(section)
            sections_set.add(section)

        self.assertEqual(len(common_sections_set), 3)
        self.assertEqual(len(intro_set), 4)

        for section in sections_set:
            text_label = TextLabelFactory(entity=OFFER_YEAR, label=section)
            TranslatedTextLabelFactory(text_label=text_label,
                                       language=iso_language)

            TranslatedTextRandomFactory(
                text_label=text_label,
                language=iso_language,
                reference=education_group_year.id,
                entity=text_label.entity,
                text='<tag>{section}</tag>'.format(section=section))

            if section in common_sections_set:
                TranslatedTextRandomFactory(
                    text_label=text_label,
                    language=iso_language,
                    reference=common_education_group_year.id,
                    entity=text_label.entity,
                    text='<tag>{section}-commun</tag>'.format(section=section))

        text_label = TextLabelFactory(entity=OFFER_YEAR, label='intro')
        TranslatedTextLabelFactory(text_label=text_label,
                                   language=iso_language)

        for section in intro_set:
            ega = EducationGroupYearFactory(
                partial_acronym=section,
                academic_year=education_group_year.academic_year)
            TranslatedTextRandomFactory(
                text_label=text_label,
                language=iso_language,
                reference=ega.id,
                entity=text_label.entity,
                text='<tag>intro-{section}</tag>'.format(section=section))

        message = {
            'anac': str(education_group_year.academic_year.year),
            'code_offre': education_group_year.acronym,
            "sections": sections,
        }

        response = self.post(
            education_group_year.academic_year.year,
            language,
            education_group_year.acronym,
            data=message,
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content_type, 'application/json')

        response_json = response.json()

        sections, conditions_admission_section = remove_conditions_admission(
            response_json['sections'])
        response_sections = convert_sections_list_of_dict_to_dict(sections)

        for section in sections_set:
            if section in response_sections:
                response_sections.pop(section)

        self.assertEqual(len(response_sections),
                         len(intro_set) + len(common_sections_set))
        for section in common_sections_set:
            if section + '-commun' in response_sections:
                response_sections.pop(section + '-commun')

        self.assertEqual(len(response_sections), len(intro_set))
        for section in intro_set:
            if 'intro-' + section in response_sections:
                response_sections.pop('intro-' + section)

        self.assertEqual(len(response_sections), 0)