def test_tabs_are_translated(self): courses.Course.ENVIRON_TEST_OVERRIDES['extra_locales'] = { 'availability': 'available', 'locale': 'el'} prefs = models.StudentPreferencesDAO.load_or_create() prefs.locale = 'el' models.StudentPreferencesDAO.save(prefs) bundle = { 'course:extra_tabs:[0]:label': { 'type': 'string', 'source_value': None, 'data': [ {'source_value': 'FAQ', 'target_value': 'faq'}]}, 'course:extra_tabs:[0]:content': { 'type': 'html', 'source_value': 'Frequently asked questions', 'data': [{ 'source_value': 'Frequently asked questions', 'target_value': 'fREQUENTLY aSKED qUESTIONS'}]}} key_el = ResourceBundleKey( ResourceKey.COURSE_SETTINGS_TYPE, 'homepage', 'el') ResourceBundleDAO.save(ResourceBundleDTO(str(key_el), bundle)) dom = self.parse_html_string(self.get('course').body) faq_el = dom.find('.//div[@id="gcb-nav-x"]//ul/li[4]/a') self.assertEquals('faq', faq_el.text) self.assertEquals(self.faq_url, faq_el.attrib['href']) self.assertIn('fREQUENTLY aSKED qUESTIONS', self.get(self.faq_url))
def test_tabs_are_translated(self): courses.Course.ENVIRON_TEST_OVERRIDES['extra_locales'] = [{ 'availability': 'available', 'locale': 'el'}] prefs = models.StudentPreferencesDAO.load_or_default() prefs.locale = 'el' models.StudentPreferencesDAO.save(prefs) bundle = { 'course:extra_tabs:[0]:label': { 'type': 'string', 'source_value': None, 'data': [ {'source_value': 'FAQ', 'target_value': 'faq'}]}, 'course:extra_tabs:[0]:content': { 'type': 'html', 'source_value': 'Frequently asked questions', 'data': [{ 'source_value': 'Frequently asked questions', 'target_value': 'fREQUENTLY aSKED qUESTIONS'}]}} key_el = ResourceBundleKey( resources_display.ResourceCourseSettings.TYPE, 'homepage', 'el') ResourceBundleDAO.save(ResourceBundleDTO(str(key_el), bundle)) dom = self.parse_html_string(self.get('course').body) faq_el = dom.find('.//div[@id="gcb-nav-x"]//ul/li[4]/a') self.assertEquals('faq', faq_el.text) self.assertEquals(self.faq_url, faq_el.attrib['href']) self.assertIn('fREQUENTLY aSKED qUESTIONS', self.get(self.faq_url))
def test_localized_search(self): def _text(elt): return ''.join(elt.itertext()) dogs_page = """ <html> <body> A page about dogs. </body> </html>""" dogs_link = 'http://dogs.null/' self.pages[dogs_link + '$'] = (dogs_page, 'text/html') dogs_page_fr = """ <html> <body> A page about French dogs. </body> </html>""" dogs_link_fr = 'http://dogs_fr.null/' self.pages[dogs_link_fr + '$'] = (dogs_page_fr, 'text/html') self.base = '/test' context = actions.simple_add_course( 'test', '*****@*****.**', 'Test Course') course = courses.Course(None, context) actions.login('*****@*****.**') actions.register(self, 'Some Admin') unit = course.add_unit() unit.now_available = True lesson = course.add_lesson(unit) lesson.objectives = 'A lesson about <a href="%s">dogs</a>' % dogs_link lesson.now_available = True course.save() lesson_bundle = { 'objectives': { 'type': 'html', 'source_value': ( 'A lesson about <a href="%s">dogs</a>' % dogs_link), 'data': [{ 'source_value': ( 'A lesson about <a#1 href="%s">dogs</a#1>' % dogs_link), 'target_value': ( 'A lesson about French <a#1 href="%s">' 'dogs</a#1>' % dogs_link_fr)}] } } lesson_key_fr = ResourceBundleKey( resources_display.ResourceLesson.TYPE, lesson.lesson_id, 'fr') with common_utils.Namespace('ns_test'): ResourceBundleDAO.save( ResourceBundleDTO(str(lesson_key_fr), lesson_bundle)) extra_locales = [{'locale': 'fr', 'availability': 'available'}] with actions.OverriddenEnvironment({'extra_locales': extra_locales}): self.index_test_course() dom = self.parse_html_string(self.get('search?query=dogs').body) snippets = dom.findall('.//div[@class="gcb-search-result-snippet"]') self.assertEquals(2, len(snippets)) # Expect no French hits self.assertIn('page about dogs', _text(snippets[0])) self.assertIn('lesson about dogs', _text(snippets[1])) # Switch locale to 'fr' with common_utils.Namespace('ns_test'): prefs = models.StudentPreferencesDAO.load_or_create() prefs.locale = 'fr' models.StudentPreferencesDAO.save(prefs) dom = self.parse_html_string(self.get('search?query=dogs').body) snippets = dom.findall('.//div[@class="gcb-search-result-snippet"]') self.assertEquals(2, len(snippets)) # Expect no Engish hits self.assertIn('page about French dogs', _text(snippets[0])) self.assertIn('lesson about French dogs', _text(snippets[1]))
def test_localized_search(self): def _text(elt): return ''.join(elt.itertext()) dogs_page = """ <html> <body> A page about dogs. </body> </html>""" dogs_link = 'http://dogs.null/' self.pages[dogs_link + '$'] = (dogs_page, 'text/html') dogs_page_fr = """ <html> <body> A page about French dogs. </body> </html>""" dogs_link_fr = 'http://dogs_fr.null/' self.pages[dogs_link_fr + '$'] = (dogs_page_fr, 'text/html') self.base = '/test' context = actions.simple_add_course('test', '*****@*****.**', 'Test Course') course = courses.Course(None, context) actions.login('*****@*****.**') actions.register(self, 'Some Admin') unit = course.add_unit() unit.now_available = True lesson = course.add_lesson(unit) lesson.objectives = 'A lesson about <a href="%s">dogs</a>' % dogs_link lesson.now_available = True course.save() lesson_bundle = { 'objectives': { 'type': 'html', 'source_value': ('A lesson about <a href="%s">dogs</a>' % dogs_link), 'data': [{ 'source_value': ('A lesson about <a#1 href="%s">dogs</a#1>' % dogs_link), 'target_value': ('A lesson about French <a#1 href="%s">' 'dogs</a#1>' % dogs_link_fr) }] } } lesson_key_fr = ResourceBundleKey( resources_display.ResourceLesson.TYPE, lesson.lesson_id, 'fr') with common_utils.Namespace('ns_test'): ResourceBundleDAO.save( ResourceBundleDTO(str(lesson_key_fr), lesson_bundle)) extra_locales = [{'locale': 'fr', 'availability': 'available'}] with actions.OverriddenEnvironment({'extra_locales': extra_locales}): self.index_test_course() dom = self.parse_html_string(self.get('search?query=dogs').body) snippets = dom.findall( './/div[@class="gcb-search-result-snippet"]') self.assertEquals(2, len(snippets)) # Expect no French hits self.assertIn('page about dogs', _text(snippets[0])) self.assertIn('lesson about dogs', _text(snippets[1])) # Switch locale to 'fr' with common_utils.Namespace('ns_test'): prefs = models.StudentPreferencesDAO.load_or_create() prefs.locale = 'fr' models.StudentPreferencesDAO.save(prefs) dom = self.parse_html_string(self.get('search?query=dogs').body) snippets = dom.findall( './/div[@class="gcb-search-result-snippet"]') self.assertEquals(2, len(snippets)) # Expect no Engish hits self.assertIn('page about French dogs', _text(snippets[0])) self.assertIn('lesson about French dogs', _text(snippets[1]))