Exemplo n.º 1
0
    def setUp(self):
        super(StudentLabelsTest, self).setUp()
        actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)

        with common_utils.Namespace(NAMESPACE):
            self.foo_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Foo',
                       'descripton': 'foo',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.bar_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Bar',
                       'descripton': 'bar',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.baz_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Baz',
                       'descripton': 'baz',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.quux_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Quux',
                       'descripton': 'quux',
                       'type': models.LabelDTO.LABEL_TYPE_GENERAL}))

        actions.login(REGISTERED_STUDENT_EMAIL)
        actions.register(self, REGISTERED_STUDENT_NAME, COURSE_NAME)
        actions.logout()
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def setUp(self):
        super(StudentTracksTest, self).setUp()

        # Add a course that will show up.
        actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)

        # Add labels
        with common_utils.Namespace(NAMESPACE):
            self.foo_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Foo',
                       'descripton': 'foo',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.bar_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Bar',
                       'descripton': 'bar',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.baz_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Baz',
                       'descripton': 'baz',
                       'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
            self.quux_id = models.LabelDAO.save(models.LabelDTO(
                None, {'title': 'Quux',
                       'descripton': 'quux',
                       'type': models.LabelDTO.LABEL_TYPE_GENERAL}))

        # Register a student for that course.
        actions.login(REGISTERED_STUDENT_EMAIL)
        actions.register(self, REGISTERED_STUDENT_NAME, COURSE_NAME)
        actions.logout()

        # Add some units to the course.
        self._course = courses.Course(
            None, app_context=sites.get_all_courses()[0])
        self._unit_no_labels = self._course.add_unit()
        self._unit_no_labels.title = 'Unit No Labels'
        self._unit_no_labels.now_available = True
        self._unit_labels_foo = self._course.add_unit()
        self._unit_labels_foo.title = 'Unit Labels: Foo'
        self._unit_labels_foo.now_available = True
        self._unit_labels_foo.labels = str(self.foo_id)
        self._unit_labels_foo_bar = self._course.add_unit()
        self._unit_labels_foo_bar.title = 'Unit Labels: Bar, Foo'
        self._unit_labels_foo_bar.now_available = True
        self._unit_labels_foo_bar.labels = '%s %s' % (self.bar_id, self.foo_id)
        self._unit_labels_quux = self._course.add_unit()
        self._unit_labels_quux.title = 'Unit Labels: Quux'
        self._unit_labels_quux.now_available = True
        self._unit_labels_quux.labels = str(self.quux_id)
        self._unit_labels_foo_quux = self._course.add_unit()
        self._unit_labels_foo_quux.title = 'Unit Labels: Foo Quux'
        self._unit_labels_foo_quux.now_available = True
        self._unit_labels_foo_quux.labels = '%s %s' % (str(self.foo_id),
                                                       str(self.quux_id))
        self._course.save()
    def test_news_label_filtering(self):
        actions.login(self.STUDENT_EMAIL)
        actions.register(self, 'John Smith')

        label_foo = models.LabelDAO.save(models.LabelDTO(
            None, {'title': 'Foo',
                   'descripton': 'foo',
                   'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))
        label_bar = models.LabelDAO.save(models.LabelDTO(
            None, {'title': 'Bar',
                   'descripton': 'bar',
                   'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK}))

        now_ts = utc.now_as_timestamp() + 3  # Avoid filtering in-past items
        news.CourseNewsDao.add_news_item(news.NewsItem(
            'test:no_labels', 'url_no_labels',
            when=utc.timestamp_to_datetime(now_ts)))
        news.CourseNewsDao.add_news_item(news.NewsItem(
            'test:with_labels', 'url_with_labels',
            labels=common_utils.list_to_text([label_foo]),
            when=utc.timestamp_to_datetime(now_ts - 1)))

        # Student starts life with no labels, so should match both items.
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'Test Item no_labels', 'url_no_labels', True),
             news_tests_lib.NewsItem(
                 'Test Item with_labels', 'url_with_labels', True)],
            news_tests_lib.extract_news_items_from_soup(soup))

        # Apply non-matching label to Student; should not see labeled news.
        models.Student.set_labels_for_current(
            common_utils.list_to_text([label_bar]))
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'Test Item no_labels', 'url_no_labels', True)],
            news_tests_lib.extract_news_items_from_soup(soup))

        # Apply matching label to Student; should again see labeled news.
        models.Student.set_labels_for_current(
            common_utils.list_to_text([label_foo, label_bar]))
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals(
            [news_tests_lib.NewsItem(
                'Test Item no_labels', 'url_no_labels', True),
             news_tests_lib.NewsItem(
                 'Test Item with_labels', 'url_with_labels', True)],
            news_tests_lib.extract_news_items_from_soup(soup))
Exemplo n.º 5
0
    def setUp(self):
        super(UnitPrePostAssessmentTest, self).setUp()

        context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                            COURSE_TITLE)
        self.course = courses.Course(None, context)

        self.unit_no_lessons = self.course.add_unit()
        self.unit_no_lessons.title = 'No Lessons'
        self.unit_no_lessons.now_available = True

        self.unit_one_lesson = self.course.add_unit()
        self.unit_one_lesson.title = 'One Lesson'
        self.unit_one_lesson.now_available = True
        self.lesson = self.course.add_lesson(self.unit_one_lesson)
        self.lesson.title = 'Lesson One'
        self.lesson.objectives = 'body of lesson'
        self.lesson.now_available = True

        self.assessment_one = self.course.add_assessment()
        self.assessment_one.title = 'Assessment One'
        self.assessment_one.html_content = 'assessment one content'
        self.assessment_one.now_available = True

        self.assessment_two = self.course.add_assessment()
        self.assessment_two.title = 'Assessment Two'
        self.assessment_two.html_content = 'assessment two content'
        self.assessment_two.now_available = True

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

        with common_utils.Namespace(NAMESPACE):
            self.track_one_id = models.LabelDAO.save(
                models.LabelDTO(
                    None, {
                        'title': 'Track One',
                        'descripton': 'track_one',
                        'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK
                    }))
            self.general_one_id = models.LabelDAO.save(
                models.LabelDTO(
                    None, {
                        'title': 'Track One',
                        'descripton': 'track_one',
                        'type': models.LabelDTO.LABEL_TYPE_GENERAL
                    }))
Exemplo n.º 6
0
    def _process_extra_locales(self, default_locale, extra_locales):
        """Make sure each locale has a label to go along."""

        existing_locale_labels = models.LabelDAO.get_all_of_type(
            models.LabelDTO.LABEL_TYPE_LOCALE)

        existing = {label.title for label in existing_locale_labels}
        required = {l['locale'] for l in extra_locales} | {default_locale}

        need_added = required - existing
        need_deleted = existing - required

        # Delete unused locale labels
        for label_dto in existing_locale_labels:
            if label_dto.title in need_deleted:
                models.LabelDAO.delete(label_dto)

        # Add new required labels
        for locale in need_added:
            models.LabelDAO.save(
                models.LabelDTO(
                    None, {
                        'title': locale,
                        'version': '1.0',
                        'description': '[%s] language' % locale,
                        'type': models.LabelDTO.LABEL_TYPE_LOCALE
                    }))
Exemplo n.º 7
0
    def _process_extra_locales(self, extra_locales):
        """Make sure each locale has a label to go along."""
        existing = set([
            label.title for label in models.LabelDAO.get_all_of_type(
                models.LabelDTO.LABEL_TYPE_LOCALE)])

        course_locale = self.app_context.default_locale
        for extra_locale in extra_locales + [{'locale': course_locale}]:
            locale = extra_locale['locale']
            if locale in existing:
                continue
            models.LabelDAO.save(models.LabelDTO(
                None, {'title': locale,
                       'version': '1.0',
                       'description': '[%s] locale' % locale,
                       'type': models.LabelDTO.LABEL_TYPE_LOCALE}))
    def setUp(self):
        super(ManualProgressTest, self).setUp()

        # Add a course that will show up.
        context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                            COURSE_TITLE)

        # Register a student for that course.
        actions.login(REGISTERED_STUDENT_EMAIL)
        actions.register(self, REGISTERED_STUDENT_NAME, COURSE_NAME)

        # Add content to course
        self._course = courses.Course(None, context)

        self._unit_one = self._course.add_unit()
        self._unit_one.title = 'Unit Labels: Foo'
        self._unit_one.availability = courses.AVAILABILITY_AVAILABLE
        self._lesson_1_1 = self._course.add_lesson(self._unit_one)
        self._lesson_1_1.title = 'Unit One, Lesson One'
        self._lesson_1_1.availability = courses.AVAILABILITY_AVAILABLE
        self._lesson_1_1.manual_progress = True
        self._lesson_1_2 = self._course.add_lesson(self._unit_one)
        self._lesson_1_2.title = 'Unit One, Lesson Two'
        self._lesson_1_2.availability = courses.AVAILABILITY_AVAILABLE
        self._lesson_1_2.manual_progress = True

        self._unit_two = self._course.add_unit()
        self._unit_two.title = 'Unit Labels: Foo'
        self._unit_two.availability = courses.AVAILABILITY_AVAILABLE
        self._unit_two.manual_progress = True
        self._lesson_2_1 = self._course.add_lesson(self._unit_two)
        self._lesson_2_1.title = 'Unit Two, Lesson One'
        self._lesson_2_1.availability = courses.AVAILABILITY_AVAILABLE
        self._lesson_2_2 = self._course.add_lesson(self._unit_two)
        self._lesson_2_2.title = 'Unit Two, Lesson Two'
        self._lesson_2_2.availability = courses.AVAILABILITY_AVAILABLE

        self._sub_assessment = self._course.add_assessment()
        self._sub_assessment.availability = courses.AVAILABILITY_AVAILABLE

        self._toplevel_assessment = self._course.add_assessment()
        self._sub_assessment.availability = courses.AVAILABILITY_AVAILABLE

        self._unit_three = self._course.add_unit()
        self._unit_three.pre_assessment = self._sub_assessment.unit_id

        self._course.save()

        with common_utils.Namespace(NAMESPACE):
            self.foo_id = models.LabelDAO.save(
                models.LabelDTO(
                    None, {
                        'title': 'Foo',
                        'descripton': 'foo',
                        'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK
                    }))
            self.bar_id = models.LabelDAO.save(
                models.LabelDTO(
                    None, {
                        'title': 'Bar',
                        'descripton': 'bar',
                        'type': models.LabelDTO.LABEL_TYPE_COURSE_TRACK
                    }))
        self.overridden_environment = actions.OverriddenEnvironment(
            {'course': {
                analytics.CAN_RECORD_STUDENT_EVENTS: 'true'
            }})
        self.overridden_environment.__enter__()