Exemple #1
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])
Exemple #2
0
    def setUp(self):
        self.education_group_year = EducationGroupYearFactory()
        self.cms_label_name = business.CONTACT_INTRO_KEY

        text_label = TextLabelFactory(entity=OFFER_YEAR,
                                      label=self.cms_label_name)
        self.contact_intro_fr = TranslatedTextRandomFactory(
            text_label=text_label,
            language=settings.LANGUAGE_CODE_FR,
            reference=self.education_group_year.id,
            entity=text_label.entity)
        self.contact_intro_en = TranslatedTextRandomFactory(
            text_label=text_label,
            language=settings.LANGUAGE_CODE_EN,
            reference=self.education_group_year.id,
            entity=text_label.entity)
    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
                           ])
Exemple #4
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)
    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,
                        }]
                    })
Exemple #6
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'])
    def setUpTestData(cls):
        cls.academic_year = AcademicYearFactory(year=2018)
        cls.learning_unit_year = LearningUnitYearFactory(
            academic_year=cls.academic_year,
            learning_container_year__academic_year=cls.academic_year,
            subtype=learning_unit_year_subtypes.FULL)
        for label in CMS_LABEL_PEDAGOGY:
            TranslatedTextRandomFactory(reference=cls.learning_unit_year.pk,
                                        text_label__label=label,
                                        language=settings.LANGUAGE_CODE_FR)

        cls.person = PersonFactory()
        url_kwargs = {
            'acronym': cls.learning_unit_year.acronym,
            'year': cls.learning_unit_year.academic_year.year
        }
        cls.url = reverse('learning_unit_api_v1:' +
                          LearningUnitSummarySpecification.name,
                          kwargs=url_kwargs)
Exemple #8
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)
Exemple #9
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)
    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')
    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)