def test_multiple_courses(self):
        COURSE_TWO = 'course_two'
        COURSE_TWO_NS = 'ns_' + COURSE_TWO

        # Slight cheat: Register gitkit data remover manually, rather than
        # enabling the entire module, which disrupts normal functional test
        # user login handling
        gitkit.EmailMapping.register_for_data_removal()

        actions.simple_add_course(
            COURSE_TWO, self.ADMIN_EMAIL, 'Data Removal Test Two')
        user = actions.login(self.STUDENT_EMAIL)

        actions.register(self, user.email(), course=self.COURSE)
        actions.register(self, user.email(), course=COURSE_TWO)
        # Slight cheat: Rather than enabling gitkit module, just call
        # the method that will insert the EmailMapping row.
        gitkit.EmailUpdatePolicy.apply(user)

        # Global profile object(s) should now exist.
        profile = models.StudentProfileDAO.get_profile_by_user_id(
            user.user_id())
        self.assertIsNotNone(profile)
        email_policy = gitkit.EmailMapping.get_by_user_id(user.user_id())
        self.assertIsNotNone(email_policy)

        # Unregister from 'data_removal_test' course.
        self._unregister_and_request_data_removal(self.COURSE)
        self._complete_removal()

        # Student object should be gone from data_removal_test course, but
        # not from course_two.
        with common_utils.Namespace(self.NAMESPACE):
            self.assertIsNone(models.Student.get_by_user(user))
        with common_utils.Namespace(COURSE_TWO_NS):
            self.assertIsNotNone(models.Student.get_by_user(user))

        # Global profile object(s) should still exist.
        profile = models.StudentProfileDAO.get_profile_by_user_id(
            user.user_id())
        self.assertIsNotNone(profile)
        email_policy = gitkit.EmailMapping.get_by_user_id(user.user_id())
        self.assertIsNotNone(email_policy)

        # Unregister from other course.
        self._unregister_and_request_data_removal(COURSE_TWO)
        self._complete_removal()

        # Both Student objects should now be gone.
        with common_utils.Namespace(self.NAMESPACE):
            self.assertIsNone(models.Student.get_by_user(user))
        with common_utils.Namespace(COURSE_TWO_NS):
            self.assertIsNone(models.Student.get_by_user(user))

        # Global profile object(s) should also be gone.
        profile = models.StudentProfileDAO.get_profile_by_user_id(
            user.user_id())
        self.assertIsNone(profile)
        email_policy = gitkit.EmailMapping.get_by_user_id(user.user_id())
        self.assertIsNone(email_policy)
示例#2
0
    def test_namespaced_handlers_404(self):
        self.admin_email = '*****@*****.**'
        self.prefix = 'course'
        actions.login(self.admin_email, is_admin=True)
        actions.simple_add_course(self.prefix, self.admin_email, 'Course')

        self.assert_handlers_404(embed._NAMESPACED_HANDLERS, prefix=self.prefix)
示例#3
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()
    def test_multiple_courses(self):
        user = self.make_test_user(self.STUDENT_EMAIL)

        COURSE_TWO = 'course_two'
        COURSE_TWO_NS = 'ns_' + COURSE_TWO

        actions.simple_add_course(
            COURSE_TWO, self.ADMIN_EMAIL, 'Data Removal Test Two')

        actions.login(user.email())
        actions.register(self, user.email(), course=self.COURSE)
        actions.register(self, user.email(), course=COURSE_TWO)
        actions.unregister(self, self.COURSE, do_data_removal=True)

        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.get(
            data_removal.DataRemovalCronHandler.URL,
            headers={'X-AppEngine-Cron': 'True'})
        self.execute_all_deferred_tasks()

        with common_utils.Namespace(self.NAMESPACE):
            self.assertIsNone(models.Student.get_by_user(user))
        with common_utils.Namespace(COURSE_TWO_NS):
            self.assertIsNotNone(
                models.Student.get_by_user(user))
    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.availability = courses.AVAILABILITY_AVAILABLE
        self._course.add_lesson(self._unit_no_labels)
        self._unit_labels_foo = self._course.add_unit()
        self._unit_labels_foo.title = 'Unit Labels: Foo'
        self._unit_labels_foo.availability = courses.AVAILABILITY_AVAILABLE
        self._unit_labels_foo.labels = str(self.foo_id)
        self._course.add_lesson(self._unit_labels_foo)
        self._unit_labels_foo_bar = self._course.add_unit()
        self._unit_labels_foo_bar.title = 'Unit Labels: Bar, Foo'
        self._unit_labels_foo_bar.availability = courses.AVAILABILITY_AVAILABLE
        self._unit_labels_foo_bar.labels = '%s %s' % (self.bar_id, self.foo_id)
        self._course.add_lesson(self._unit_labels_foo_bar)
        self._unit_labels_quux = self._course.add_unit()
        self._unit_labels_quux.title = 'Unit Labels: Quux'
        self._unit_labels_quux.availability = courses.AVAILABILITY_AVAILABLE
        self._unit_labels_quux.labels = str(self.quux_id)
        self._course.add_lesson(self._unit_labels_quux)
        self._unit_labels_foo_quux = self._course.add_unit()
        self._unit_labels_foo_quux.title = 'Unit Labels: Foo Quux'
        self._unit_labels_foo_quux.availability = courses.AVAILABILITY_AVAILABLE
        self._unit_labels_foo_quux.labels = '%s %s' % (str(self.foo_id),
                                                       str(self.quux_id))
        self._course.add_lesson(self._unit_labels_foo_quux)
        self._course.save()
 def setUp(self):
     super(AssetsRestTest, self).setUp()
     actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)
     actions.login(ADMIN_EMAIL, is_admin=True)
     actions.update_course_config(COURSE_NAME, {
         'extra_locales': [
             {'locale': 'de_DE', 'availability': 'available'}]})
     self.COURSE_NAME = COURSE_NAME
 def setUp(self):
     super(NamespacedHandlerTest, self).setUp()
     self.admin_email = '*****@*****.**'
     self.course_name = 'test_course'
     self.course_title = 'Test Course'
     self.namespaced_url = '/%s%s' % (
         self.course_name, hello.NamespacedHandler.URL)
     actions.simple_add_course(
         self.course_name, self.admin_email, self.course_title)
    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 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.availability = courses.AVAILABILITY_AVAILABLE

        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 setUp(testcase):
        super(TestUserRoutes, testcase).setUp()

        testcase.times_routed = 0
        testcase.times_other_routed = 0

        class TestHandler(utils.CourseHandler):
            def get(handler):
                testcase.times_routed += 1
                handler.response.write("test response")

        user_routes.register_handler(TestHandler, "test_handler", "Test Handler")

        class OtherHandler(utils.CourseHandler):
            def get(handler):
                testcase.times_other_routed += 1
                handler.response.write("test response")

        user_routes.register_handler(OtherHandler, "other_handler", "Other Handler")

        actions.login(testcase.ADMIN_EMAIL, is_admin=True)
        testcase.app_context = actions.simple_add_course(
            testcase.COURSE_NAME, testcase.ADMIN_EMAIL, "User Route Course"
        )
        testcase.base = "/{}".format(testcase.COURSE_NAME)
    def setUp(self):
        super(AutoregisterTests, self).setUp()

        self.context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Autoregister Course')
        course = courses.Course(None, app_context=self.context)
        self.unit = course.add_unit()
        self.unit.now_available = True
        self.lesson = course.add_lesson(self.unit)
        self.lesson.now_available = True
        course.save()

        actions.login(self.ADMIN_EMAIL)
        actions.update_course_config(
            self.COURSE_NAME,
            {
                'course': {
                    'now_available': True,
                    'browsable': False,
                },
                autoregister.AUTOREGISTER_SETTINGS_SCHEMA_SECTION: {
                    autoregister.REDIRECT_URL: self.REDIRECT_URL,
                    autoregister.AUTOREGISTER_ENABLED: True,
                }
            })
        actions.login(self.STUDENT_EMAIL)
    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__()
    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.now_available = True
        self._lesson_1_1 = self._course.add_lesson(self._unit_one)
        self._lesson_1_1.title = "Unit One, Lesson One"
        self._lesson_1_1.now_available = True
        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.now_available = True
        self._lesson_1_2.manual_progress = True

        self._unit_two = self._course.add_unit()
        self._unit_two.title = "Unit Labels: Foo"
        self._unit_two.now_available = True
        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.now_available = True
        self._lesson_2_2 = self._course.add_lesson(self._unit_two)
        self._lesson_2_2.title = "Unit Two, Lesson Two"
        self._lesson_2_2.now_available = True

        self._sub_assessment = self._course.add_assessment()
        self._sub_assessment.now_available = True

        self._toplevel_assessment = self._course.add_assessment()
        self._sub_assessment.now_available = True

        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}
                )
            )

        config.Registry.test_overrides[utils.CAN_PERSIST_ACTIVITY_EVENTS.name] = True
    def setUp(self):
        super(HtmlHookTest, self).setUp()

        self.app_context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)
        self.course = courses.Course(None, self.app_context)
        actions.login(ADMIN_EMAIL, is_admin=True)
        self.xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(settings.HtmlHookRESTHandler.XSRF_ACTION)
    def setUp(self):
        super(MultipleChoiceTagTests, self).setUp()

        self.base = '/' + COURSE_NAME
        self.app_context = actions.simple_add_course(
            COURSE_NAME, ADMIN_EMAIL, 'Assessment Tags')
        self.namespace = 'ns_%s' % COURSE_NAME

        with utils.Namespace(self.namespace):
            dto = models.QuestionDTO(None, transforms.loads(self.MC_1_JSON))
            self.mc_1_id = models.QuestionDAO.save(dto)
            dto = models.QuestionDTO(None, transforms.loads(self.MC_2_JSON))
            self.mc_2_id = models.QuestionDAO.save(dto)
            dto = models.QuestionGroupDTO(
                None, transforms.loads(
                    self.QG_1_JSON_TEMPLATE % (self.mc_1_id, self.mc_2_id)))
            self.qg_1_id = models.QuestionGroupDAO.save(dto)

        self.course = courses.Course(None, self.app_context)
        self.assessment = self.course.add_assessment()
        self.assessment.now_available = True
        self.assessment.html_content = (
            '<question quid="%s" weight="1" instanceid="q1"></question>'
            '<question-group qgid="%s" instanceid="qg1"></question-group' % (
                self.mc_1_id, self.qg_1_id))
        self.course.save()
示例#16
0
    def setUp(self):
        super(DriveTestBase, self).setUp()
        actions.login(self.ADMIN_EMAIL, is_admin=True)
        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Drive Course')
        self.base = '/{}'.format(self.COURSE_NAME)

        # have a syncing policy in place already
        with utils.Namespace(self.app_context.namespace):
            self.setup_schedule_for_file('3')
            self.setup_schedule_for_file('5')
            self.setup_schedule_for_file('6', synced=True)

        # remove all hooks
        for handler, hooks in self.HANDLER_HOOKS:
            for hook in hooks:
                self.swap(handler, hook, [])

        # Prevent it from consulting the settings or calling out

        self.swap(
            drive_api_manager._DriveManager, 'from_app_context',
            classmethod(mocks.manager_from_mock))

        self.swap(
            drive_api_manager._DriveManager, 'from_code',
            classmethod(mocks.manager_from_mock))

        self.swap(
            handlers.AbstractDriveDashboardHandler, 'setup_drive',
            mocks.setup_drive)

        self.swap(
            drive_settings, 'get_secrets', mocks.get_secrets)
    def test_old_assessment_assignment(self):
        new_course_context = actions.simple_add_course(
            'new_course', ADMIN_EMAIL, 'My New Course')
        new_course = courses.Course(None, new_course_context)
        new_course.import_from(
            sites.get_all_courses(rules_text='course:/:/')[0])
        new_course.save()

        unit_rest_handler = unit_lesson_editor.UnitRESTHandler()
        unit_rest_handler.app_context = new_course_context

        # Use REST handler function to save pre/post handlers on one unit.
        errors = []
        unit = new_course.get_units_of_type(verify.UNIT_TYPE_UNIT)[0]
        assessment = new_course.get_units_of_type(
            verify.UNIT_TYPE_ASSESSMENT)[0]
        unit_rest_handler.apply_updates(
            unit,
            {
                'title': unit.title,
                'now_available': unit.now_available,
                'label_groups': [],
                'pre_assessment': assessment.unit_id,
                'post_assessment': -1,
                'show_contents_on_one_page': False,
                'manual_progress': False,
                'description': None,
                'unit_header': None,
                'unit_footer': None,
            }, errors)
        assert not errors
示例#18
0
    def test_course_larger_than_datastore_max_can_be_exported_and_loaded(self):
        unit = self.course.add_unit()
        num_lessons = vfs._MAX_VFS_SHARD_SIZE / len(LOREM_IPSUM)
        for unused in range(num_lessons):
            lesson = self.course.add_lesson(unit)
            lesson.objectives = LOREM_IPSUM
        self.course.save()

        other_course_name = 'other_course'
        other_course_context = actions.simple_add_course(
            other_course_name, self.ADMIN_EMAIL, 'Other')

        # Verify that a large course can be ETL'd out and recovered.
        fp, archive_file = tempfile.mkstemp(suffix='.zip')
        os.close(fp)
        try:
            parser = etl.create_args_parser()
            etl.main(parser.parse_args([
                'download', 'course', '/' + self.COURSE_NAME, 'localhost',
                '--archive_path', archive_file, '--force_overwrite',
                '--internal', '--disable_remote']))
            etl.main(parser.parse_args([
                'upload', 'course', '/' + other_course_name, 'localhost',
                '--archive_path', archive_file, '--force_overwrite',
                '--internal', '--disable_remote']))
        finally:
            os.unlink(archive_file)

        # Verify contents of course.
        course = courses.Course(handler=None, app_context=other_course_context)
        lessons = course.get_lessons(unit.unit_id)
        self.assertEquals(num_lessons, len(lessons))
        for lesson in lessons:
            self.assertEquals(lesson.objectives, LOREM_IPSUM)
    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()
        self.TEST_USER = actions.login('*****@*****.**')
        actions.register(self, self.TEST_USER.email())
        self.student = (
            models.StudentProfileDAO.get_enrolled_student_by_user_for(
                self.TEST_USER, 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(ExtraTabsTests, self).setUp()

        self.base = '/' + COURSE_NAME
        app_context = actions.simple_add_course(
            COURSE_NAME, ADMIN_EMAIL, 'Extra Tabs Course')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % COURSE_NAME)

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

        courses.Course.ENVIRON_TEST_OVERRIDES = {
            'course': {
                'extra_tabs': [
                    {
                        'label': 'FAQ',
                        'position': 'left',
                        'visibility': 'all',
                        'url': '',
                        'content': 'Frequently asked questions'},
                    {
                        'label': 'Resources',
                        'position': 'right',
                        'visibility': 'student',
                        'url': 'http://www.example.com',
                        'content': 'Links to resources'}]
            }
        }
        self.faq_url = 'modules/extra_tabs/render?index=0'

        actions.login(STUDENT_EMAIL, is_admin=False)
        actions.register(self, STUDENT_NAME)
    def test_descriptions(self):
        context = actions.simple_add_course(
            COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)
        course = courses.Course(None, context)
        unit = course.add_unit()
        unit.title = 'The Unit'
        unit.availability = courses.AVAILABILITY_AVAILABLE
        unit.description = UNIT_DESCRIPTION

        assessment = course.add_assessment()
        assessment.title = 'The Assessment'
        assessment.availability = courses.AVAILABILITY_AVAILABLE
        assessment.description = ASSESSMENT_DESCRIPTION

        link = course.add_link()
        link.title = 'The Link'
        link.availability = courses.AVAILABILITY_AVAILABLE
        link.description = LINK_DESCRIPTION

        course.save()
        actions.login(ADMIN_EMAIL)

        response = self.get(BASE_URL)
        self.assertIn(unit.description, response)
        self.assertIn(assessment.description, response)
        self.assertIn(link.description, response)
    def test_old_assessment_availability(self):
        actions.login(ADMIN_EMAIL, is_admin=True)
        new_course_context = actions.simple_add_course(
            'new_course', ADMIN_EMAIL, 'My New Course')
        new_course = courses.Course(None, new_course_context)
        new_course.import_from(
            sites.get_all_courses(rules_text='course:/:/')[0])
        new_course.save()

        # Prove that there are at least some assessments in this course.
        assessments = new_course.get_units_of_type(verify.UNIT_TYPE_ASSESSMENT)
        self.assertIsNotNone(assessments[0])

        # Get the first Unit
        unit = new_course.get_units_of_type(verify.UNIT_TYPE_UNIT)[0]

        unit_rest_handler = unit_lesson_editor.UnitRESTHandler()
        schema = unit_rest_handler.get_schema(
            new_course, unit.unit_id).get_schema_dict()

        # Verify that there are 4 valid choices for pre- or post-asssments
        # for this unit
        choices = self._get_selection_choices(
            schema, ['properties', 'pre_assessment', '_inputex'])
        self.assertEquals(5, len(choices))
        self.assertEquals(-1, choices['-- None --'])

        choices = self._get_selection_choices(
            schema, ['properties', 'post_assessment', '_inputex'])
        self.assertEquals(5, len(choices))
        self.assertEquals(-1, choices['-- None --'])
示例#23
0
    def setUp(self):
        super(NewsTestBase, self).setUp()
        self.base = '/' + self.COURSE_NAME
        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Title')
        self.maxDiff = None  # Show full text expansion of expect mismatches.

        # Simplify equivalence checks by supplying a deep comparator, rather
        # than getting object instance equality comparison.
        def news_items_are_equal(thing_one, thing_two):
            return (thing_one.resource_key == thing_two.resource_key and
                    thing_one.when == thing_two.when and
                    thing_one.url == thing_two.url and
                    thing_one.labels == thing_two.labels)
        news.NewsItem.__eq__ = news_items_are_equal
        news.NewsItem.__repr__ = lambda x: x.__dict__.__repr__()
        def seen_items_are_equal(thing_one, thing_two):
            return (thing_one.resource_key == thing_two.resource_key and
                    abs((thing_one.when - thing_two.when).total_seconds()) < 2)
        news.SeenItem.__eq__ = seen_items_are_equal
        news.SeenItem.__repr__ = lambda x: x.__dict__.__repr__()
        news.I18nTitleRegistry.register(
            'test', lambda x: 'Test Item ' + x.split(':', 1)[1])

        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace(self.NAMESPACE)

        # News is always enabled during own-module tests so that we do not
        # accumulate any regressions within ourselves.  Other modules are
        # free to simply disable if they wish.
        self.save_is_enabled = news.is_enabled
        news.is_enabled = lambda: True
        if not news.custom_module.enabled:
            news.custom_module.enable()
 def setUp(self):
     super(CourseCachingTest, self).setUp()
     self.app_context = actions.simple_add_course(
         self.COURSE_NAME, self.ADMIN_EMAIL, 'Test Course')
     self.course = courses.Course(handler=None, app_context=self.app_context)
     actions.login(self.ADMIN_EMAIL)
     config.Registry.test_overrides[models.CAN_USE_MEMCACHE.name] = True
示例#25
0
    def setUp(self):
        super(StudentLifecycleObserverTestCase, self).setUp()
        app_context = actions.simple_add_course(
            self.COURSE, self.ADMIN_EMAIL, 'Lifecycle Test')
        self.base = '/' + self.COURSE
        self._user_id = None
        self._num_add_calls = 0
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_ADD][self.COURSE] = (
                self._add_callback)
        self._num_unenroll_calls = 0
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_UNENROLL][self.COURSE] = (
                self._unenroll_callback)
        self._num_reenroll_calls = 0
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_REENROLL][self.COURSE] = (
                self._reenroll_callback)

        self._num_exception_calls = 0
        self._num_exceptions_to_raise = 0
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_ADD]['raises'] = (
                self._raise_exceptions)
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_UNENROLL]['raises'] = (
                self._raise_exceptions)
        models.StudentLifecycleObserver.EVENT_CALLBACKS[
            models.StudentLifecycleObserver.EVENT_REENROLL]['raises'] = (
                self._raise_exceptions)
    def test_jobs_run(self):
        COURSE = 'test'
        app_context = actions.simple_add_course(COURSE, ADMIN_EMAIL, 'Test')
        actions.register(self, 'Joe Admin', COURSE)
        config.set_report_allowed(True)
        response = self.get(usage_reporting.StartReportingJobs.URL,
                            headers={'X-AppEngine-Cron': 'True'})
        self.assertEquals(200, response.status_int)
        self.assertEquals('OK.', response.body)
        now = int(time.time())
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.execute_all_deferred_tasks()

        expected = [{
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: FAKE_TIMESTAMP,
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_STUDENT_COUNT,
            messaging.Message._VALUE: 1,
        }, {
            messaging.Message._INSTALLATION: FAKE_INSTALLATION_ID,
            messaging.Message._COURSE: FAKE_COURSE_ID,
            messaging.Message._TIMESTAMP: now - (now % 3600),
            messaging.Message._VERSION: os.environ['GCB_PRODUCT_VERSION'],
            messaging.Message._METRIC: messaging.Message.METRIC_ENROLLED,
            messaging.Message._VALUE: 1,
        }]
        actual = MockSender.get_sent()
        actual.sort(key=lambda x: x['timestamp'])
        self.assertEquals(expected, actual)
        sites.reset_courses()
    def setUp(self):
        super(StudentRedirectTestBase, self).setUp()
        context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                            COURSE_TITLE)
        course = courses.Course(None, context)
        self.unit = course.add_unit()
        self.unit.title = 'The Unit'
        self.unit.now_available = True
        self.lesson_one = course.add_lesson(self.unit)
        self.lesson_one.title = 'Lesson One'
        self.lesson_one.now_available = True
        self.lesson_two = course.add_lesson(self.unit)
        self.lesson_two.title = 'Lesson Two'
        self.lesson_two.now_available = True
        self.assessment = course.add_assessment()
        self.assessment.title = 'The Assessment'
        self.assessment.now_available = True
        course.save()

        actions.login(REGISTERED_STUDENT_EMAIL)
        actions.register(self, REGISTERED_STUDENT_NAME, COURSE_NAME)
        # Actions.register views the student's profile page; clear this out.
        with common_utils.Namespace(NAMESPACE):
            prefs = models.StudentPreferencesDAO.load_or_default()
            prefs.last_location = None
            models.StudentPreferencesDAO.save(prefs)
    def setUp(self):
        super(PiiExportTest, self).setUp()

        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'The Course')
        self.data_source_context = (
          CharacterDataSource.get_context_class().build_blank_default({}, 20))
示例#29
0
    def setUp(self):
        super(MathTagTests, self).setUp()

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

        test_course = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                'Test Course')
        self.course = courses.Course(None, test_course)
        math_unit = self.course.add_unit()
        math_unit.title = 'math_test_unit'
        no_math_unit = self.course.add_unit()
        no_math_unit.title = 'no_math_test_unit'

        self.math_unit_id = math_unit.unit_id
        self.no_math_unit_id = no_math_unit.unit_id

        no_math_lesson = self.course.add_lesson(no_math_unit)
        no_math_lesson.title = 'Lesson without any mathematical formula.'
        no_math_lesson.objectives = 'This lesson does not contain a math tag.'

        math_lesson = self.course.add_lesson(math_unit)
        math_lesson.title = 'First lesson with mathematical formula'
        math_lesson.objectives = (
            '<gcb-math input_type="TeX" instanceid="X99HibNGBIX4">'
            'x^2+2x+1'
            '</gcb-math><br>')

        self.course.save()
示例#30
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.availability = courses.AVAILABILITY_AVAILABLE
        unit1.labels = str(foo_id)
        lesson11 = course.add_lesson(unit1)
        lesson11.objectives = 'common plugh <gcb-youtube videoid="glados">'
        lesson11.availability = courses.AVAILABILITY_AVAILABLE
        lesson11.notes = search_unit_tests.VALID_PAGE_URL
        lesson11.video = 'portal'
        course.update_unit(unit1)
        unit2 = course.add_unit()
        unit2.availability = courses.AVAILABILITY_AVAILABLE
        unit1.labels = str(bar_id)
        lesson21 = course.add_lesson(unit2)
        lesson21.objectives = 'common plover'
        lesson21.availability = courses.AVAILABILITY_AVAILABLE
        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)
 def setUp(self):
     super(AnnouncementsTests, self).setUp()
     self.app_context = actions.simple_add_course(self.COURSE,
                                                  self.ADMIN_EMAIL,
                                                  'Announcements')
     self.old_namespace = namespace_manager.get_namespace()
     self.base = '/' + self.COURSE
     namespace_manager.set_namespace('ns_%s' % self.COURSE)
     actions.login(self.ADMIN_EMAIL, is_admin=True)
 def setUp(self):
     super(CourseCachingTest, self).setUp()
     self.app_context = actions.simple_add_course(self.COURSE_NAME,
                                                  self.ADMIN_EMAIL,
                                                  'Test Course')
     self.course = courses.Course(handler=None,
                                  app_context=self.app_context)
     actions.login(self.ADMIN_EMAIL)
     config.Registry.test_overrides[models.CAN_USE_MEMCACHE.name] = True
示例#33
0
    def setUp(self):
        super(HtmlHookTest, self).setUp()

        self.app_context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                     COURSE_TITLE)
        self.course = courses.Course(None, self.app_context)
        actions.login(ADMIN_EMAIL, is_admin=True)
        self.xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(
            settings.HtmlHookRESTHandler.XSRF_ACTION)
示例#34
0
 def setUp(self):
     super(MessagingTests, self).setUp()
     messaging.ENABLED_IN_DEV_FOR_TESTING = True
     self.save_urlfetch_fetch = urlfetch.fetch
     urlfetch.fetch = self.mock_urlfetch_fetch
     actions.login(ADMIN_EMAIL, is_admin=True)
     self.app_config = actions.simple_add_course(self.COURSE_NAME,
                                                 ADMIN_EMAIL,
                                                 self.COURSE_NAME)
示例#35
0
    def setUp(self):
        super(PiiExportTest, self).setUp()

        self.app_context = actions.simple_add_course(self.COURSE_NAME,
                                                     self.ADMIN_EMAIL,
                                                     'The Course')
        self.data_source_context = (
            CharacterDataSource.get_context_class().build_blank_default({},
                                                                        20))
 def setUp(self):
     super(BaseSampleDataTestCase, self).setUp()
     self.base = '/' + COURSE_NAME
     self.app_context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                  'Sample Data Course')
     self.old_namespace = namespace_manager.get_namespace()
     namespace_manager.set_namespace('ns_%s' % COURSE_NAME)
     self.course = courses.Course(None, self.app_context)
     actions.login(ADMIN_EMAIL)
示例#37
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 utils.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 = dashboard.DashboardHandler.root_menu_group
        # pylint: disable=W0212
        self.old_get_acitons = dashboard.DashboardHandler._custom_get_actions
        # pylint: enable=W0212

        # put a dummy method in
        menu_group = menus.MenuGroup('test', 'Test Dashboard')
        dashboard.DashboardHandler.root_menu_group = menu_group
        dashboard.DashboardHandler.default_action = self.ACTION
        dashboard.DashboardHandler.add_nav_mapping(self.ACTION, self.ACTION)
        dashboard.DashboardHandler.add_sub_nav_mapping(self.ACTION, self.ACTION,
            self.ACTION, action=self.ACTION, contents=test_content)
        dashboard.DashboardHandler.map_get_action_to_permission(
            self.ACTION, dashboard.custom_module, self.PERMISSION)
        actions.logout()
示例#38
0
    def setUp(self):
        super(ConsentBannerTests, self).setUp()

        self.base = '/' + self.COURSE_NAME
        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, ADMIN_EMAIL, 'Banner Test Course')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)
        courses.Course.ENVIRON_TEST_OVERRIDES = {
            'course': {'admin_user_emails': self.NOT_SUPER_EMAIL}}
示例#39
0
    def setUp(self):
        super(AdminDashboardTabTests, self).setUp()

        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'I18N Course')
        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(GraphQLTests, self).setUp()
        config.Registry.test_overrides.update({
            gql.GQL_SERVICE_ENABLED.name: True,
        })

        self.base = '/' + self.COURSE_NAME
        self.course_id = gql_tests.get_course_id(self.base)
        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Course')
示例#41
0
    def setUp(self):
        super(BaseSkillMapTests, self).setUp()

        self.base = '/' + COURSE_NAME
        context = actions.simple_add_course(
            COURSE_NAME, ADMIN_EMAIL, 'Skills Map Course')
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % COURSE_NAME)

        self.course = courses.Course(None, context)
示例#42
0
    def setUp(self):
        super(BaseInvitationTests, self).setUp()

        self.base = '/' + self.COURSE_NAME
        context = actions.simple_add_course(self.COURSE_NAME, self.ADMIN_EMAIL,
                                            'Invitation Course')
        self.course = courses.Course(None, context)
        self.old_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('ns_%s' % self.COURSE_NAME)
        self._is_registered = False
    def test_markdown(self):
        self.context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                 COURSE_TITLE)
        self.course = courses.Course(None, self.context)
        self.unit = self.course.add_unit()
        self.unit.title = 'The Unit'
        self.unit.now_available = True
        self.lesson = self.course.add_lesson(self.unit)
        self.lesson.title = 'The Lesson'
        self.lesson.now_available = True
        self.lesson.objectives = '''
 Welcome to Markdown!

<gcb-markdown instanceid="BHpNAOMuLdMn">
# This is an H1

## This is an H2

This is [an example](http://example.com/ &quot;Title&quot;) inline link.

[This link](http://example.net/) has no title attribute.

 Text attributes *italic*,
 **bold**, `monospace`.

 Shopping list:

   * apples
   * oranges
   * pears

 Numbered list:

   1. apples
   2. oranges
   3. pears
</gcb-markdown><br>'''
        self.course.save()

        response = self.get(LESSON_URL)
        self.assertIn('<h1>This is an H1</h1>', response.body)
        self.assertIn('<h2>This is an H2</h2>', response.body)
        self.assertIn(
            '<p><a href="http://example.net/">This link</a> '
            'has no title attribute.</p>', response.body)
        self.assertIn('<em>italic</em>', response.body)
        self.assertIn('<strong>bold</strong>', response.body)
        self.assertIn('<code>monospace</code>', response.body)
        self.assertIn('<li>apples</li>', response.body)
        self.assertIn('<li>oranges</li>', response.body)
        self.assertIn('<ul>\n<li>apples</li>', response.body)
        self.assertIn('<ol>\n<li>apples</li>', response.body)
        self.assertIn(
            '<p>This is <a href="http://example.com/" title="Title">'
            'an example</a> inline link.</p>', response.body)
    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()
    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)
示例#46
0
 def _import_sample_course(self):
     dst_app_context = actions.simple_add_course(
         'webserv', '*****@*****.**',
         'Power Searching with Google')
     dst_course = courses.Course(None, dst_app_context)
     src_app_context = sites.get_all_courses('course:/:/:')[0]
     errors = []
     dst_course.import_from(src_app_context, errors)
     dst_course.save()
     self.base = ''
     self.assertEquals(0, len(errors))
     return dst_course
示例#47
0
    def setUp(self):
        super(TextFileUploadTagTestCase, self).setUp()

        self.base = '/' + self._COURSE_NAME
        self.app_context = actions.simple_add_course(self._COURSE_NAME,
                                                     self._ADMIN_EMAIL,
                                                     'Upload File Tag Test')

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

        actions.login(self._STUDENT_EMAIL, is_admin=True)
        actions.register(self, 'S. Tudent')
示例#48
0
    def setUp(self):
        super(StudentAnswersAnalyticsTest, self).setUp()

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

        for assessment in ASSESSMENTS:
            self._add_assessment(self.course, assessment)
        self.course.save()
        for entity in ENTITIES:
            self._add_entity(self.context, entity)
示例#49
0
 def _import_sample_course(self, ns='guide', availability=None):
     dst_app_context = actions.simple_add_course(
         ns, '*****@*****.**' % ns,
         'Power Searching with Google [%s]' % ns)
     dst_course = courses.Course(None, dst_app_context)
     all_courses = sites.get_all_courses('course:/:/:')
     src_app_context = all_courses[len(all_courses) - 1]
     errors = []
     dst_course.import_from(src_app_context, errors)
     dst_course.save()
     dst_course.set_course_availability(availability)
     self.assertEquals(0, len(errors))
示例#50
0
    def setUp(self):
        super(MapReduceMethodTypeTests, self).setUp()
        self.app_context = actions.simple_add_course(
            self.COURSE_NAME, self.ADMIN_EMAIL, 'Test Course')
        self.base = '/%s' % self.COURSE_NAME

        actions.login('*****@*****.**')
        actions.register(self, 'Student One')
        actions.login('*****@*****.**')
        actions.register(self, 'Student Two')
        actions.login('*****@*****.**')
        actions.register(self, 'Student Three')
示例#51
0
 def setUp(self):
     super(TagsMarkdown, self).setUp()
     self.context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                              COURSE_TITLE)
     self.course = courses.Course(None, self.context)
     self.unit = self.course.add_unit()
     self.unit.title = 'The Unit'
     self.unit.availability = courses.AVAILABILITY_AVAILABLE
     self.lesson = self.course.add_lesson(self.unit)
     self.lesson.title = 'The Lesson'
     self.lesson.availability = courses.AVAILABILITY_AVAILABLE
     self.course.save()
示例#52
0
 def setUp(self):
     super(ExampleEmbedAndHandlerV1ChildCoursesTest, self).setUp()
     self.student_email = '*****@*****.**'
     actions.login(self.student_email)
     actions.simple_add_course('parent', self.admin_email, 'Parent')
     actions.simple_add_course('child1', self.admin_email, 'Child1')
     actions.simple_add_course('child2', self.admin_email, 'Child2')
示例#53
0
    def test_debug_info_not_present_for_non_admin(self):
        # NOTE: the is_admin=True version of this test is
        # functional.test_classes.AdminAspectTest.test_access_to_admin_pages

        # create another course which you shouldn't see
        actions.simple_add_course(
            'other-course', '*****@*****.**', 'Other Course')

        actions.login(self.ADMIN_EMAIL, is_admin=False)

        response = self.get('admin?action=deployment')
        dom = self.parse_html_string(response.body)

        # we should see our own course
        self.assertIn(self.COURSE_NAME, response.body)

        # we should not see other courses
        self.assertNotIn('Other Course', response.body)

        # we should not see admin features
        self.assertNotIn('application_id', response.body)
        self.assertNotIn('Modules', response.body)
示例#54
0
        def add_course_and_register_student(admin_email):
            google_app_context = actions.simple_add_course(
                course_name, admin_email, course_title)
            actions.update_course_config(
                course_name,
                {'course': {'now_available': True, 'browsable': True,},})
            actions.register(self, 'John Smith', course_name)

            with actions.OverriddenConfig(config.REPORT_ALLOWED.name, True):
                usage_reporting.StartReportingJobs._for_testing_only_get()
            self.execute_all_deferred_tasks(
                models.StudentLifecycleObserver.QUEUE_NAME)
            self.execute_all_deferred_tasks()
示例#55
0
    def setUp(self):
        super(UnitHeaderFooterTest, self).setUp()

        context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                            COURSE_TITLE)
        self.course = courses.Course(None, context)
        self.unit = self.course.add_unit()
        self.unit.now_available = True
        self.unit.unit_header = UNIT_HEADER_TEXT
        self.unit.unit_footer = UNIT_FOOTER_TEXT
        self.course.save()
        self.url = BASE_URL + '/unit?unit=' + str(self.unit.unit_id)
        actions.login(ADMIN_EMAIL)
示例#56
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
                    }))
    def setUp(self):
        super(TagsInclude, self).setUp()

        self.context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                 COURSE_TITLE)
        self.course = courses.Course(None, self.context)
        self.unit = self.course.add_unit()
        self.unit.title = 'The Unit'
        self.unit.now_available = True
        self.lesson = self.course.add_lesson(self.unit)
        self.lesson.title = 'The Lesson'
        self.lesson.now_available = True
        self.lesson.objectives = GCB_INCLUDE % HTML_FILE
        self.course.save()
示例#58
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()
示例#59
0
    def setUp(self):
        super(EmbeddedAssessmentTests, self).setUp()

        self.base = '/' + COURSE_NAME
        self.app_context = actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL,
                                                     'Learning Resources')
        self.course = courses.Course(None, self.app_context)
        self.assessment = self.course.add_assessment()
        self.assessment.availability = courses.AVAILABILITY_AVAILABLE
        self.course.save()

        self.embed_url = 'modules/embed/v1/resource/assessment/%s' % (
            self.assessment.unit_id)

        actions.login(STUDENT_EMAIL, is_admin=False)
    def test_multiple_courses(self):
        user = self.make_test_user(self.STUDENT_EMAIL)

        COURSE_TWO = 'course_two'
        COURSE_TWO_NS = 'ns_' + COURSE_TWO

        actions.simple_add_course(COURSE_TWO, self.ADMIN_EMAIL,
                                  'Data Removal Test Two')

        actions.login(user.email())
        actions.register(self, user.email(), course=self.COURSE)
        actions.register(self, user.email(), course=COURSE_TWO)
        actions.unregister(self, self.COURSE, do_data_removal=True)

        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.get(data_removal.DataRemovalCronHandler.URL,
                 headers={'X-AppEngine-Cron': 'True'})
        self.execute_all_deferred_tasks()

        with common_utils.Namespace(self.NAMESPACE):
            self.assertIsNone(models.Student.get_by_user(user))
        with common_utils.Namespace(COURSE_TWO_NS):
            self.assertIsNotNone(models.Student.get_by_user(user))