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 ])
def test_with_one_parent_one_same_tree_level(self): parent = TextLabelFactory(order=1) tl_child_1 = TextLabelFactory(parent=parent) tl_child_2 = TextLabelFactory(parent=parent, order=30) self.assertEqual(parent.order, 1) self.assertEqual(tl_child_1.order, 1) self.assertEqual(tl_child_2.order, 2)
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())
def test_circular_dependency(self): a = TextLabelFactory() b = TextLabelFactory(parent=a) c = TextLabelFactory(parent=b) b.parent = c with self.assertRaises(ValueError): return b.save()
def test_without_parent_one_same_tree_level_shift_value(self): tl_initial_1 = TextLabelFactory(order=1) # Order: 1 tl_initial_2 = TextLabelFactory(order=2) # Order: 2 tl_new_1 = TextLabelFactory(order=1) # Order: 1 tl_initial_1.refresh_from_db() tl_initial_2.refresh_from_db() self.assertEqual(tl_new_1.order, 1) self.assertEqual(tl_initial_1.order, 2) self.assertEqual(tl_initial_2.order, 3)
def test_with_one_parent_one_same_tree_level_shift_value(self): parent = TextLabelFactory(order=1) tl_child_initial_1 = TextLabelFactory(parent=parent, order=1) tl_child_initial_2 = TextLabelFactory(parent=parent, order=4) tl_child_new_2 = TextLabelFactory(parent=parent, order=2) tl_child_initial_1.refresh_from_db() tl_child_initial_2.refresh_from_db() self.assertEqual(parent.order, 1) self.assertEqual(tl_child_initial_1.order, 1) self.assertEqual(tl_child_initial_2.order, 3) self.assertEqual(tl_child_new_2.order, 2)
def test_change_parent_go_up_one_level(self): a = TextLabelFactory() b = TextLabelFactory(parent=a) c = TextLabelFactory(parent=b) c.parent = a c.save() self.assertEqual(c.parent, a) self.assertEqual(c.order, 1) b.refresh_from_db() self.assertEqual(b.order, 2)
def test_change_parent_go_root_recompute_child(self): root = TextLabelFactory() child_1 = TextLabelFactory(parent=root) child_2 = TextLabelFactory(parent=root) child_1.parent = None child_1.save() root.refresh_from_db() child_2.refresh_from_db() self.assertEqual(root.parent, None) self.assertEqual(root.order, 2) self.assertEqual(child_1.parent, None) self.assertEqual(child_1.order, 1) self.assertEqual(child_2.parent, root) self.assertEqual(child_2.order, 1)
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])
def test_learning_achievement_save_triggers_cms_save(self, mock_translated_text_update_or_create): learning_achievement = LearningAchievementFactory( code_name=1, learning_unit_year=self.luy, language=self.language_fr, consistency_id=1 ) learning_achievement_en = LearningAchievementFactory( code_name=1, learning_unit_year=self.luy, language=self.language_en, consistency_id=1 ) TextLabelFactory(label='themes_discussed') self.client.post(reverse( 'achievement_edit', kwargs={ 'learning_unit_year_id': self.luy.id, 'learning_achievement_id': learning_achievement.id } ), data={ 'code_name': 'AA1', 'text_fr': 'Text', 'postpone': 0, 'consistency_id': 1, } ) self.assertTrue(mock_translated_text_update_or_create.called)
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)
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} )
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 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])
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 ])
def setUp(self): self.A = TextLabelFactory(order=1) self.B = TextLabelFactory(parent=self.A, order=1) self.C = TextLabelFactory(parent=self.A, order=2) self.D = TextLabelFactory(parent=self.B, order=1) self.E = TextLabelFactory(parent=self.C, order=1) self.F = TextLabelFactory(parent=self.C, order=2) self.G = TextLabelFactory(parent=self.C, order=3)
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')
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')
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, }] })
def test_valid_get_request(self): language = "en" text_label = TextLabelFactory() response = self.client.get(self.url, data={"language": language, "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"], None) self.assertEqual(context["language_translated"], ('en', _('English')))
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 ])
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")
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 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 test_with_multiple_parent_one_same_tree_level_shift_value(self): parent_1 = TextLabelFactory(order=1) parent_2 = TextLabelFactory(order=2) parent_3 = TextLabelFactory(order=3) self.assertEqual(parent_1.order, 1) self.assertEqual(parent_2.order, 2) self.assertEqual(parent_3.order, 3) tl_child_parent_1_initial_1 = TextLabelFactory(parent=parent_1) tl_child_parent_1_new_1 = TextLabelFactory(parent=parent_1, order=1) tl_child_parent_1_initial_1.refresh_from_db() self.assertEqual(tl_child_parent_1_initial_1.order, 2) self.assertEqual(tl_child_parent_1_new_1.order, 1) tl_child_parent_2_initial_1 = TextLabelFactory(parent=parent_2, order=1) tl_child_parent_2_initial_2 = TextLabelFactory(parent=parent_2, order=2) self.assertEqual(tl_child_parent_2_initial_1.order, 1) self.assertEqual(tl_child_parent_2_initial_2.order, 2)
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_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)
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_learning_achievement_save_triggers_cms_save( self, mock_translated_text_update_or_create): learning_achievement = LearningAchievementFactory( learning_unit_year=self.learning_unit_year, language=self.language_fr) learning_achievement_en = LearningAchievementFactory( learning_unit_year=self.learning_unit_year, language=self.language_en) TextLabelFactory(label='themes_discussed') self.client.post(reverse('achievement_edit', kwargs={ 'learning_unit_year_id': self.learning_unit_year.id, 'learning_achievement_id': learning_achievement.id }), data={ 'code_name': 'AA1', 'text_fr': 'Text', 'lua_fr_id': learning_achievement.id, 'lua_en_id': learning_achievement_en.id }) self.assertTrue(mock_translated_text_update_or_create.called)
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)