Пример #1
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        # pylint: disable=W0212
        self.old_nav_mappings = DashboardHandler._nav_mappings
        # pylint: disable=W0212
        DashboardHandler._nav_mappings = {self.ACTION: 'outline'}
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()
Пример #2
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        # pylint: disable=W0212
        self.old_nav_mappings = DashboardHandler._custom_nav_mappings
        # pylint: disable=W0212
        DashboardHandler._custom_nav_mappings = {self.ACTION: 'outline'}
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(self.ACCESS_COURSE_NAME,
                                            self.ADMIN_EMAIL,
                                            'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(
                None, {
                    'name': self.ROLE,
                    'users': [self.USER_EMAIL],
                    'permissions': {
                        dashboard.custom_module.name: [self.PERMISSION]
                    }
                })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(self.NO_ACCESS_COURSE_NAME,
                                            self.ADMIN_EMAIL,
                                            'Course with no access')

        self.course_without_access = courses.Course(None, context)

        def test_content(self):
            return self.render_page({
                'main_content': 'test',
                'page_title': 'test'
            })

        # save properties
        self.old_menu_group = DashboardHandler.root_menu_group
        # pylint: disable=W0212
        self.old_get_acitons = DashboardHandler._custom_get_actions
        # pylint: enable=W0212

        # put a dummy method in
        menu_group = menus.MenuGroup('test', 'Test Dashboard')
        DashboardHandler.root_menu_group = menu_group
        DashboardHandler.default_action = self.ACTION
        DashboardHandler.add_nav_mapping(self.ACTION, self.ACTION)
        DashboardHandler.add_sub_nav_mapping(self.ACTION,
                                             self.ACTION,
                                             self.ACTION,
                                             action=self.ACTION,
                                             contents=test_content)
        DashboardHandler.map_action_to_permission('get_%s' % self.ACTION,
                                                  self.PERMISSION)
        actions.logout()
Пример #4
0
    def setUp(self):
        super(CronCleanupTest, self).setUp()
        admin_email = '*****@*****.**'
        self.course_one = actions.simple_add_course(
            COURSE_ONE, admin_email, 'Course One')
        self.course_two = actions.simple_add_course(
            COURSE_TWO, admin_email, 'Course Two')

        actions.login(admin_email, True)
        actions.register(self, admin_email, COURSE_ONE)
        actions.register(self, admin_email, COURSE_TWO)

        self.save_tz = os.environ.get('TZ')
        os.environ['TZ'] = 'GMT'
        time.tzset()
    def setUp(self):
        super(CronCleanupTest, self).setUp()
        admin_email = '*****@*****.**'
        self.course_one = actions.simple_add_course(COURSE_ONE, admin_email,
                                                    'Course One')
        self.course_two = actions.simple_add_course(COURSE_TWO, admin_email,
                                                    'Course Two')

        actions.login(admin_email, True)
        actions.register(self, admin_email, COURSE_ONE)
        actions.register(self, admin_email, COURSE_TWO)

        self.save_tz = os.environ.get('TZ')
        os.environ['TZ'] = 'GMT'
        time.tzset()
Пример #6
0
    def setUp(self):
        super(PeerReviewDashboardStudentTest, self).setUp()
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(self.COURSE_NAME, '*****@*****.**',
                                            'Peer Back Button Child')
        self.course = courses.Course(None, context)

        self.assessment = self.course.add_assessment()
        self.assessment.title = 'Assessment'
        self.assessment.html_content = 'assessment content'
        self.assessment.workflow_yaml = (
            '{grader: human,'
            'matcher: peer,'
            'review_due_date: \'2034-07-01 12:00\','
            'review_min_count: 1,'
            'review_window_mins: 20,'
            'submission_due_date: \'2034-07-01 12:00\'}')
        self.assessment.now_available = True

        self.course.save()
        actions.login(self.STUDENT_EMAIL)
        actions.register(self, self.STUDENT_EMAIL)
        config.Registry.test_overrides[
            utils.CAN_PERSIST_ACTIVITY_EVENTS.name] = True

        actions.submit_assessment(
            self,
            self.assessment.unit_id, {
                'answers': '',
                'score': 0,
                'assessment_type': self.assessment.unit_id
            },
            presubmit_checks=False)
    def setUp(self):
        super(CertificateCriteriaTestCase, self).setUp()

        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Certificate Criteria')

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
        self.course.save()
        actions.login(self.STUDENT_EMAIL)
        actions.register(self, self.STUDENT_EMAIL)
        self.student = (
            models.StudentProfileDAO.get_enrolled_student_by_email_for(
                self.STUDENT_EMAIL, context))

        # Override course.yaml settings by patching app_context.
        self.get_environ_old = sites.ApplicationContext.get_environ
        self.certificate_criteria = []

        def get_environ_new(app_context):
            environ = self.get_environ_old(app_context)
            environ['certificate_criteria'] = self.certificate_criteria
            return environ

        sites.ApplicationContext.get_environ = get_environ_new
Пример #8
0
    def setUp(self):
        super(CertificateCriteriaTestCase, self).setUp()

        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(self.COURSE_NAME, self.ADMIN_EMAIL,
                                            'Certificate Criteria')

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
        self.course.save()
        actions.login(self.STUDENT_EMAIL)
        actions.register(self, self.STUDENT_EMAIL)
        self.student = (
            models.StudentProfileDAO.get_enrolled_student_by_email_for(
                self.STUDENT_EMAIL, context))

        # Override course.yaml settings by patching app_context.
        self.get_environ_old = sites.ApplicationContext.get_environ
        self.certificate_criteria = []

        def get_environ_new(app_context):
            environ = self.get_environ_old(app_context)
            environ['certificate_criteria'] = self.certificate_criteria
            return environ

        sites.ApplicationContext.get_environ = get_environ_new
    def setUp(self):
        super(PeerReviewDashboardStudentTest, self).setUp()
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, '*****@*****.**', 'Peer Back Button Child')
        self.course = courses.Course(None, context)

        self.assessment = self.course.add_assessment()
        self.assessment.title = 'Assessment'
        self.assessment.html_content = 'assessment content'
        self.assessment.workflow_yaml = (
            '{grader: human,'
            'matcher: peer,'
            'review_due_date: \'2034-07-01 12:00\','
            'review_min_count: 1,'
            'review_window_mins: 20,'
            'submission_due_date: \'2034-07-01 12:00\'}')
        self.assessment.now_available = True

        self.course.save()
        actions.login(self.STUDENT_EMAIL)
        actions.register(self, self.STUDENT_EMAIL)

        actions.submit_assessment(
            self,
            self.assessment.unit_id,
            {'answers': '', 'score': 0,
             'assessment_type': self.assessment.unit_id},
            presubmit_checks=False
        )
    def test_tracked_lessons(self):
        context = actions.simple_add_course('test', '*****@*****.**',
                                            'Test Course')
        course = courses.Course(None, context)
        actions.login('*****@*****.**')
        actions.register(self, 'Some Admin', 'test')

        with common_utils.Namespace('ns_test'):
            foo_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Foo',
                       'descripton': 'foo',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            bar_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Bar',
                       'descripton': 'bar',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))

        unit1 = course.add_unit()
        unit1.now_available = True
        unit1.labels = str(foo_id)
        lesson11 = course.add_lesson(unit1)
        lesson11.objectives = 'common plugh <gcb-youtube videoid="glados">'
        lesson11.now_available = True
        lesson11.notes = search_unit_test.VALID_PAGE_URL
        lesson11.video = 'portal'
        course.update_unit(unit1)
        unit2 = course.add_unit()
        unit2.now_available = True
        unit1.labels = str(bar_id)
        lesson21 = course.add_lesson(unit2)
        lesson21.objectives = 'common plover'
        lesson21.now_available = True
        course.update_unit(unit2)
        course.save()
        self.index_test_course()

        # Registered, un-tracked student sees all.
        response = self.get('/test/search?query=common')
        self.assertIn('common', response.body)
        self.assertIn('plugh', response.body)
        self.assertIn('plover', response.body)
        response = self.get('/test/search?query=link')  # Do see followed links
        self.assertIn('Partial', response.body)
        self.assertIn('Absolute', response.body)
        response = self.get('/test/search?query=lemon')  # Do see video refs
        self.assertIn('v=glados', response.body)

        # Student with tracks sees filtered view.
        with common_utils.Namespace('ns_test'):
            models.Student.set_labels_for_current(str(foo_id))
        response = self.get('/test/search?query=common')
        self.assertIn('common', response.body)
        self.assertNotIn('plugh', response.body)
        self.assertIn('plover', response.body)
        response = self.get('/test/search?query=link')  # Links are filtered
        self.assertNotIn('Partial', response.body)
        self.assertNotIn('Absolute', response.body)
        response = self.get('/test/search?query=lemon')  # Don't see video refs
        self.assertNotIn('v=glados', response.body)
Пример #11
0
    def test_tracked_lessons(self):
        context = actions.simple_add_course('test', '*****@*****.**',
                                            'Test Course')
        course = courses.Course(None, context)
        actions.login('*****@*****.**')
        actions.register(self, 'Some Admin', 'test')

        with common_utils.Namespace('ns_test'):
            foo_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Foo',
                       'descripton': 'foo',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            bar_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Bar',
                       'descripton': 'bar',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))

        unit1 = course.add_unit()
        unit1.now_available = True
        unit1.labels = str(foo_id)
        lesson11 = course.add_lesson(unit1)
        lesson11.objectives = 'common plugh <gcb-youtube videoid="glados">'
        lesson11.now_available = True
        lesson11.notes = search_unit_test.VALID_PAGE_URL
        lesson11.video = 'portal'
        course.update_unit(unit1)
        unit2 = course.add_unit()
        unit2.now_available = True
        unit1.labels = str(bar_id)
        lesson21 = course.add_lesson(unit2)
        lesson21.objectives = 'common plover'
        lesson21.now_available = True
        course.update_unit(unit2)
        course.save()
        self.index_test_course()

        # Registered, un-tracked student sees all.
        response = self.get('/test/search?query=common')
        self.assertIn('common', response.body)
        self.assertIn('plugh', response.body)
        self.assertIn('plover', response.body)
        response = self.get('/test/search?query=link')  # Do see followed links
        self.assertIn('Partial', response.body)
        self.assertIn('Absolute', response.body)
        response = self.get('/test/search?query=lemon')  # Do see video refs
        self.assertIn('v=glados', response.body)

        # Student with tracks sees filtered view.
        with common_utils.Namespace('ns_test'):
            models.Student.set_labels_for_current(str(foo_id))
        response = self.get('/test/search?query=common')
        self.assertIn('common', response.body)
        self.assertNotIn('plugh', response.body)
        self.assertIn('plover', response.body)
        response = self.get('/test/search?query=link')  # Links are filtered
        self.assertNotIn('Partial', response.body)
        self.assertNotIn('Absolute', response.body)
        response = self.get('/test/search?query=lemon')  # Don't see video refs
        self.assertNotIn('v=glados', response.body)
Пример #12
0
    def setUp(self):
        super(CourseOutlineTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Outline Testing')

        self.course = courses.Course(None, context)
Пример #13
0
 def setUp(self):
     super(MapReduceSimpleTest, self).setUp()
     admin_email = '*****@*****.**'
     self.context = actions.simple_add_course('mr_test', admin_email, 'Test')
     actions.login(admin_email, is_admin=True)
     with common_utils.Namespace('ns_mr_test'):
         # Start range at 1 because 0 is a reserved ID.
         for key in range(1, DummyEntity.NUM_ENTITIES + 1):
             DummyDAO.upsert(key, {})
Пример #14
0
    def setUp(self):
        super(CourseOutlineTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Outline Testing')

        self.course = courses.Course(None, context)
Пример #15
0
 def setUp(self):
     super(MapReduceSimpleTest, self).setUp()
     admin_email = '*****@*****.**'
     self.context = actions.simple_add_course('mr_test', admin_email, 'Test')
     actions.login(admin_email, is_admin=True)
     with common_utils.Namespace('ns_mr_test'):
         # Start range at 1 because 0 is a reserved ID.
         for key in range(1, DummyEntity.NUM_ENTITIES + 1):
             DummyDAO.upsert(key, {})
Пример #16
0
    def setUp(self):
        super(DashboardAccessTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        context = actions.simple_add_course(
            self.ACCESS_COURSE_NAME, self.ADMIN_EMAIL, 'Course with access')

        self.course_with_access = courses.Course(None, context)

        with Namespace(self.course_with_access.app_context.namespace):
            role_dto = models.RoleDTO(None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {dashboard.custom_module.name: [self.PERMISSION]}
            })
            models.RoleDAO.save(role_dto)

        context = actions.simple_add_course(
            self.NO_ACCESS_COURSE_NAME, self.ADMIN_EMAIL,
            'Course with no access'
        )

        self.course_without_access = courses.Course(None, context)

        def test_content(self):
            return self.render_page(
                {'main_content': 'test', 'page_title': 'test'})

        # save properties
        self.old_menu_group = DashboardHandler.root_menu_group
        # pylint: disable=W0212
        self.old_get_acitons = DashboardHandler._custom_get_actions
        # pylint: enable=W0212

        # put a dummy method in
        menu_group = menus.MenuGroup('test', 'Test Dashboard')
        DashboardHandler.root_menu_group = menu_group
        DashboardHandler.default_action = self.ACTION
        DashboardHandler.add_nav_mapping(self.ACTION, self.ACTION)
        DashboardHandler.add_sub_nav_mapping(self.ACTION, self.ACTION,
            self.ACTION, action=self.ACTION, contents=test_content)
        DashboardHandler.map_action_to_permission(
            'get_%s' % self.ACTION, self.PERMISSION)
        actions.logout()
Пример #17
0
    def setUp(self):
        super(DashboardCustomNavTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Custom Dashboard')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
    def setUp(self):
        super(TestLessonSchema, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)
        context = actions.simple_add_course(self.COURSE_NAME, self.ADMIN_EMAIL,
                                            'Lesson Course')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
        self.unit = self.course.add_unit()
        self.course.save()
Пример #19
0
    def setUp(self):
        super(DashboardCustomNavTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Custom Dashboard')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
Пример #20
0
    def setUp(self):
        super(TestLessonSchema, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Lesson Course')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.course = courses.Course(None, context)
        self.unit = self.course.add_unit()
        self.course.save()
Пример #21
0
    def setUp(self):
        super(RoleEditorTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Roles Testing')

        self.course = courses.Course(None, context)

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.old_registered_permission = Roles._REGISTERED_PERMISSIONS
        Roles._REGISTERED_PERMISSIONS = {}
Пример #22
0
    def setUp(self):
        super(RoleEditorTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Roles Testing')

        self.course = courses.Course(None, context)

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        self.old_registered_permission = Roles._REGISTERED_PERMISSIONS
        Roles._REGISTERED_PERMISSIONS = {}
    def setUp(self):
        super(CourseOutlineTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(self.COURSE_NAME, self.ADMIN_EMAIL,
                                            'Outline Testing')

        self.course = courses.Course(None, context)
        self.assessment = self.course.add_assessment()
        self.assessment.title = 'Test Assessment'
        self.link = self.course.add_link()
        self.link.title = 'Test Link'
        self.unit = self.course.add_unit()
        self.unit.title = 'Test Unit'
        self.lesson = self.course.add_lesson(self.unit)
        self.lesson.title = 'Test Lesson'
        self.course.save()
Пример #24
0
    def setUp(self):
        super(CourseOutlineTestCase, self).setUp()

        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Outline Testing')

        self.course = courses.Course(None, context)
        self.assessment = self.course.add_assessment()
        self.assessment.title = 'Test Assessment'
        self.link = self.course.add_link()
        self.link.title = 'Test Link'
        self.unit = self.course.add_unit()
        self.unit.title = 'Test Unit'
        self.lesson = self.course.add_lesson(self.unit)
        self.lesson.title = 'Test Lesson'
        self.course.save()
Пример #25
0
    def setUp(self):
        super(AccessDraftsTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        self.context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Access Draft Testing')

        self.course = courses.Course(None, self.context)

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        role_dto = models.RoleDTO(None, {
            'name': self.ROLE,
            'users': [self.USER_EMAIL],
            'permissions': {
                custom_modules.core_module.name: [
                    custom_modules.SEE_DRAFTS_PERMISSION]
            }
        })
        models.RoleDAO.save(role_dto)
        actions.logout()
Пример #26
0
    def setUp(self):
        super(AccessDraftsTestCase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.base = '/' + self.COURSE_NAME
        self.context = actions.simple_add_course(self.COURSE_NAME,
                                                 self.ADMIN_EMAIL,
                                                 'Access Draft Testing')

        self.course = courses.Course(None, self.context)

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)

        role_dto = models.RoleDTO(
            None, {
                'name': self.ROLE,
                'users': [self.USER_EMAIL],
                'permissions': {
                    courses_module.custom_module.name:
                    [courses_module.SEE_DRAFTS_PERMISSION]
                }
            })
        models.RoleDAO.save(role_dto)
        actions.logout()
    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]))
Пример #28
0
    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]))