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 --'])
    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)
示例#3
0
    def test_notifications_succeed(self):
        actions.login(self.STUDENT_EMAIL)
        user_id = None

        actions.register(self, self.STUDENT_EMAIL)
        self.assertIsNone(self._user_id)
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.assertIsNotNone(self._user_id)
        user_id = self._user_id
        self.assertEquals(1, self._num_add_calls)
        self.assertEquals(0, self._num_unenroll_calls)
        self.assertEquals(0, self._num_reenroll_calls)

        actions.unregister(self)
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.assertEquals(1, self._num_add_calls)
        self.assertEquals(1, self._num_unenroll_calls)
        self.assertEquals(0, self._num_reenroll_calls)


        with common_utils.Namespace(self.NAMESPACE):
            models.StudentProfileDAO.update(
                user_id, self.STUDENT_EMAIL, is_enrolled=True)
        self.execute_all_deferred_tasks(
            models.StudentLifecycleObserver.QUEUE_NAME)
        self.assertEquals(1, self._num_add_calls)
        self.assertEquals(1, self._num_unenroll_calls)
        self.assertEquals(1, self._num_reenroll_calls)
示例#4
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()
示例#5
0
    def test_announcements(self):
        email = '*****@*****.**'
        actions.login(email, is_admin=True)

        self._add_announcement({
            'title': 'My Test Title',
            'date': '2015-02-03 00:00',
            'is_draft': False,
            'html': 'Four score and seven years ago, our founding fathers'
            })
        self._add_announcement({
            'title': 'My Test Title',
            'date': '2015-02-03 00:00',
            'is_draft': True,
            'html': 'Standing beneath this serene sky, overlooking these',
            })

        response = self.get('dashboard?action=settings_search')
        index_token = self.get_xsrf_token(response.body, 'gcb-index-course')
        response = self.post('dashboard?action=index_course',
                             {'xsrf_token': index_token})
        self.execute_all_deferred_tasks()

        # This matches an announcement in the Power Searching course
        response = self.get(
            'search?query=Four%20score%20seven%20years')
        self.assertIn('gcb-search-result', response.body)
        self.assertIn('announcements#', response.body)

        # The draft announcement in Power Searching should not be indexed
        response = self.get('search?query=Standing%20beneath%20serene')
        self.assertNotIn('gcb-search-result', response.body)
        self.assertNotIn('announcements#', response.body)
示例#6
0
 def test_post_tracks_sets(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     xsrf_token = crypto.XsrfTokenManager.create_xsrf_token('student-edit')
     self.post(STUDENT_SETTRACKS_URL,
               {'labels': '%d' % self.foo_id,
                'xsrf_token': xsrf_token})
     self._verify_labels(self.get(STUDENT_LABELS_URL), [self.foo_id])
    def test_parameters_can_be_omitted_if_using_source_context(self):
        email = '*****@*****.**'
        actions.login(email, is_admin=True)

        response = transforms.loads(self.get(
            '/rest/data/character/items?filter=rank>=5&ordering=rank'
            '&chunk_size=3&page_number=1').body)
        source_context = response['source_context']
        self._verify_data([self.characters[4], self.characters[6]],
                          response['data'])

        # This should load identical items, without having to respecify
        # filters, ordering, chunk_size.
        response = transforms.loads(self.get(
            '/rest/data/character/items?page_number=1'
            '&source_context=%s' % source_context).body)
        self.assertEquals(1, response['page_number'])
        self._verify_data([self.characters[4], self.characters[6]],
                          response['data'])
        self._assert_have_only_logs(response, [
            'Continuing use of existing context',
            'fetch page 1 start cursor present; end cursor missing',
            'fetch page 1 using limit 3',
            'fetch page 1 is partial; not saving end cursor',
            ])
示例#8
0
    def test_analytics(self):
        actions.login(REGISTERED_STUDENT_EMAIL)
        self.put(STUDENT_LABELS_URL,
                 {'labels': '%d,%d' % (
                     self.foo_id, self.quux_id)})

        actions.login(ADMIN_EMAIL)
        response = self.get(ANALYTICS_URL)
        self.submit(response.forms['gcb-run-visualization-labels_on_students'],
                    response)
        self.execute_all_deferred_tasks()

        rest_url = (
            '/%s/rest/data/labels_on_students/items' % COURSE_NAME +
            '?data_source_token=%s&page_number=0&chunk_size=0' %
            crypto.XsrfTokenManager.create_xsrf_token('data_source_access'))
        label_counts = transforms.loads(self.get(rest_url).body)
        self.assertEquals(
            [{'title': 'Quux',
              'count': 1,
              'type': 'General',
              'description': ''},
             {'title': 'Bar',
              'count': 0,
              'type': 'Course Track',
              'description': ''},
             {'title': 'Baz',
              'count': 0,
              'type': 'Course Track',
              'description': ''},
             {'title': 'Foo',
              'count': 1,
              'type': 'Course Track',
              'description': ''}],
            label_counts['data'])
 def test_unit_matching_baz(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     self._choose_tracks([self.baz_id])
     response = self.get(COURSE_OVERVIEW_URL)
     self.assertIn(self._unit_no_labels.title, response.body)
     self.assertNotIn(self._unit_labels_foo.title, response.body)
     self.assertNotIn(self._unit_labels_foo_bar.title, response.body)
示例#10
0
 def test_delete_labels_deletes(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     self._verify_labels(
         self.put(STUDENT_LABELS_URL,
                  {'labels': '%d,%d' % (self.foo_id, self.bar_id)}),
         [self.foo_id, self.bar_id])
     self._verify_labels(self.delete(STUDENT_LABELS_URL), [])
    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_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))
示例#13
0
    def test_is_current_user_admin_delegates_to_gae_users_service(self):
        actions.login(self.email, is_admin=True)
        users_result = users.is_current_user_admin()
        gae_users_result = users.is_current_user_admin()

        self.assertTrue(users_result)
        self.assertTrue(gae_users_result)
示例#14
0
    def test_get_current_user_delegates_to_gae_users_service(self):
        actions.login(self.email)
        users_result = users.get_current_user()
        gae_users_result = gae_users.get_current_user()

        self.assert_service_results_equal_and_not_none(
            users_result, gae_users_result)
    def test_rest_handler_requires_enrolled_user_in_session(self):
        response = self._post_to_rest_handler(self._get_rest_request({}))
        self.assertEquals(401, response['status'])

        actions.login(self.STUDENT_EMAIL, is_admin=False)
        response = self._post_to_rest_handler(self._get_rest_request({}))
        self.assertEquals(401, response['status'])
示例#16
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()
    def test_certificate_should_have_student_nickname(self):
        actions.login('*****@*****.**')
        models.Student.add_new_student_for_current_user('Jane Doe', None, self)

        response = self.get('/certificate')
        self.assertEquals(200, response.status_code)
        self.assertIn('Jane Doe', response.body)
    def test_multiple_course(self):
        """Tests when multiple courses are available."""
        sites.setup_courses('course:/test::ns_test, course:/:/')
        name = 'Test completed course'
        email = 'Student'

        # Make the course available.
        get_environ_old = sites.ApplicationContext.get_environ

        def get_environ_new(self):
            environ = get_environ_old(self)
            environ['course']['now_available'] = True
            return environ

        sites.ApplicationContext.get_environ = get_environ_new

        actions.login(email)
        actions.register(self, name)
        response = self.get('/explorer/courses')
        # Assert if 'View course list' text is shown on my course page.
        actions.assert_contains('View course list', response.body)

        # Clean up app_context.
        sites.ApplicationContext.get_environ = get_environ_old
        sites.reset_courses()
    def test_oeditor_returns_state(self):
        actions.login('*****@*****.**', is_admin=True)
        xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(
                oeditor.EditorPrefsRestHandler.XSRF_TOKEN)

        self._post(xsrf_token=xsrf_token)
        response = self.get('dashboard?action=edit_lesson&key=%s' % (
            self.lesson.lesson_id))

        expected = {
          'xsrf_token': xsrf_token,
          'location': self.location,
          'key': str(self.key),
          'prefs': self.EDITOR_STATE
        }
        expected = transforms.loads(transforms.dumps(expected))

        match = re.search(
            r'cb_global.editor_prefs = JSON.parse\((.*)\);', response.body)

        actual = match.group(1)
        actual = transforms.loads('"%s"' % actual)
        actual = transforms.loads(actual[1:-1])

        self.assertEquals(expected, actual)
示例#20
0
 def test_course_whitelist_with_multiple_entries(self):
     WhitelistTest._whitelist = (
         '[%s] ' % NONSTUDENT_EMAIL * 100 +
         '[%s] ' % STUDENT_EMAIL +
         '[%s] ' % NONSTUDENT_EMAIL * 100)
     actions.login(STUDENT_EMAIL)
     self._expect_visible()
    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)
示例#22
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")
 def test_delete_link_when_registered_then_cancel_deletion(self):
     actions.login(self.STUDENT_EMAIL)
     actions.register(self, self.STUDENT_EMAIL)
     response = self.get('course')
     response = self.click(response, 'Delete My Data')
     self._unregister_flow(response, with_deletion_checked=True,
                           cancel_on_deletion=True)
    def test_multiple_students(self):
        # Register two students
        user = actions.login(self.STUDENT_EMAIL)
        actions.register(self, user.email(), course=self.COURSE)

        other_user = actions.login('*****@*****.**')
        actions.register(self, other_user.email(), course=self.COURSE)

        # Get IDs of those students; make an event for each.
        with common_utils.Namespace(self.NAMESPACE):
            student1_id = (
                models.Student.get_by_user(user).user_id)
            student2_id = (
                models.Student.get_by_user(other_user).user_id)
            models.EventEntity(user_id=student1_id, source='test').put()
            models.EventEntity(user_id=student2_id, source='test').put()

        # Unregister one of them.
        actions.login(self.STUDENT_EMAIL)
        self._unregister_and_request_data_removal(self.COURSE)
        self._complete_removal()

        # Unregistered student and his data are gone; still-registered
        # student's data is still present.
        with common_utils.Namespace(self.NAMESPACE):
            self.assertIsNone(models.Student.get_by_user(user))
            self.assertIsNotNone(models.Student.get_by_user(other_user))
            entities = list(models.EventEntity.all().run())
            self.assertEquals(1, len(entities))
            self.assertEquals(student2_id, entities[0].user_id)
    def test_pagination_filtering_and_ordering(self):
        email = '*****@*****.**'
        actions.login(email, is_admin=True)

        response = transforms.loads(self.get(
            '/rest/data/character/items?filter=rank>=5&ordering=rank'
            '&chunk_size=3&page_number=1').body)
        source_context = response['source_context']
        self.assertEquals(1, response['page_number'])
        self._verify_data([self.characters[4], self.characters[6]],
                          response['data'])
        self._assert_have_only_logs(response, [
            'Creating new context for given parameters',
            'fetch page 0 start cursor missing; end cursor missing',
            'fetch page 0 using limit 3',
            'fetch page 0 saving end cursor',
            'fetch page 1 start cursor present; end cursor missing',
            'fetch page 1 using limit 3',
            'fetch page 1 is partial; not saving end cursor',
            ])

        response = transforms.loads(self.get(
            '/rest/data/character/items?filter=rank>=5&ordering=rank'
            '&chunk_size=3&page_number=0'
            '&source_context=%s' % source_context).body)
        source_context = response['source_context']
        self.assertEquals(0, response['page_number'])
        self._verify_data([self.characters[7], self.characters[1],
                           self.characters[8]], response['data'])
        self._assert_have_only_logs(response, [
            'Existing context matches parameters; using existing context',
            'fetch page 0 start cursor missing; end cursor present',
            ])
 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
示例#27
0
    def test_enrollment(self):
        actions.logout()

        response = self.get_response(
            '{course(id: "%s") {enrollment {email enrolled}}}' % (
                self.course_id))
        enrollment = response['data']['course']['enrollment']
        self.assertEquals({'enrolled': False, 'email': None}, enrollment)

        actions.login(STUDENT_EMAIL)

        response = self.get_response(
            '{course(id: "%s") {enrollment {email enrolled}}}' % (
                self.course_id))
        enrollment = response['data']['course']['enrollment']
        self.assertEquals({'enrolled': False, 'email': None}, enrollment)

        actions.register(self, STUDENT_NAME)

        response = self.get_response(
            '{course (id: "%s") { enrollment { email enrolled}}}' % (
                self.course_id))
        enrollment = response['data']['course']['enrollment']
        self.assertEquals(
            {'enrolled': True, 'email': STUDENT_EMAIL}, enrollment)
 def test_is_user_allowed_assigned_permission(self):
     self.assertFalse(roles.Roles.is_user_allowed(
         self._get_course(), PERMISSION_MODULE, PERMISSION))
     self._create_role()
     actions.login(STUDENT_EMAIL)
     self.assertTrue(roles.Roles.is_user_allowed(
         self._get_course(), PERMISSION_MODULE, PERMISSION))
    def setUp(self):
        super(RolesTest, self).setUp()

        actions.login(COURSE_ADMIN_EMAIL, is_admin=True)
        payload_dict = {
            'name': COURSE_NAME,
            'title': 'Roles Test',
            'admin_email': COURSE_ADMIN_EMAIL}
        request = {
            'payload': transforms.dumps(payload_dict),
            'xsrf_token': crypto.XsrfTokenManager.create_xsrf_token(
                'add-course-put')}
        response = self.testapp.put('/rest/courses/item?%s' % urllib.urlencode(
            {'request': transforms.dumps(request)}), {})
        self.assertEquals(response.status_int, 200)
        sites.setup_courses('course:/%s::ns_%s, course:/:/' % (
                COURSE_NAME, COURSE_NAME))
        actions.logout()

        config.Registry.test_overrides[roles.GCB_ADMIN_LIST.name] = (
            '[%s]' % SITE_ADMIN_EMAIL)

        # pylint: disable-msg=protected-access
        self.old_registered_permission = roles.Roles._REGISTERED_PERMISSIONS
        roles.Roles._REGISTERED_PERMISSIONS = {}

        config.Registry.test_overrides[models.CAN_USE_MEMCACHE.name] = True
示例#30
0
    def test_non_admin_permissions_failures(self):
        actions.login(STUDENT_EMAIL)
        student_xsrf_token = crypto.XsrfTokenManager.create_xsrf_token(
            settings.HtmlHookRESTHandler.XSRF_ACTION)

        response = self.get(ADMIN_SETTINGS_URL)
        self.assertEquals(200, response.status_int)
        payload = transforms.loads(response.body)
        self.assertEquals(401, payload['status'])
        self.assertEquals('Access denied.', payload['message'])

        response = self.put(ADMIN_SETTINGS_URL, {'request': transforms.dumps({
                'key': 'base:after_body_tag_begins',
                'xsrf_token': cgi.escape(student_xsrf_token),
                'payload': '{}'})})
        payload = transforms.loads(response.body)
        self.assertEquals(401, payload['status'])
        self.assertEquals('Access denied.', payload['message'])

        response = self.delete(ADMIN_SETTINGS_URL + '?xsrf_token=' +
                               cgi.escape(student_xsrf_token))
        self.assertEquals(200, response.status_int)
        payload = transforms.loads(response.body)
        self.assertEquals(401, payload['status'])
        self.assertEquals('Access denied.', payload['message'])
示例#31
0
 def test_put_blank_labels_param(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     self._verify_labels(self.put(STUDENT_LABELS_URL, 'labels'), [])
示例#32
0
    def test_can_edit_true_if_user_is_admin(self):
        actions.login(self.email, is_admin=True)
        # Treat as module-protected. pylint: disable=protected-access
        runtime = core_tags._Runtime(self.app_context)

        self.assertTrue(runtime.can_edit())
示例#33
0
 def test_delete_fails_logged_in_unregistered(self):
     actions.login(UNREGISTERED_STUDENT_EMAIL)
     self._verify_error(self.delete(STUDENT_LABELS_URL),
                        'User is not enrolled')
    def test_can_edit_true_if_user_is_admin(self):
        actions.login(self.email, is_admin=True)
        runtime = core_tags._Runtime(self.app_context)

        self.assertTrue(runtime.can_edit())
    def test_can_edit_false_if_user_is_not_admin(self):
        actions.login(self.email, is_admin=False)

        self.assertFalse(core_tags._Runtime(self.app_context).can_edit())
 def get_oeditor_dom(self):
     actions.login('*****@*****.**', is_admin=True)
     response = self.get(
         '/admin?action=config_edit&name=gcb_admin_user_emails')
     return self.parse_html_string(response.body)
 def test_rest_handler_requires_course_admin(self):
     actions.login('*****@*****.**', is_admin=False)
     response = self._post()
     self.assertEquals(200, response.status_int)
     body = transforms.loads(response.body)
     self.assertEquals(401, body['status'])
    def test_role_permissions(self):
        with common_utils.Namespace(self.NAMESPACE):

            # Admin and assistant can read 'a', but student cannot.
            checker = permissions.SchemaPermissionRegistry.build_view_checker(
                self.PERMISSION_SCOPE, ['a'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))

            # Admin and assistant can read 'b', but student cannot.
            checker = permissions.SchemaPermissionRegistry.build_view_checker(
                self.PERMISSION_SCOPE, ['b'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))

            # Admin can read 'c', but neither assistant nor student may.
            checker = permissions.SchemaPermissionRegistry.build_view_checker(
                self.PERMISSION_SCOPE, ['c'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))

            # Admin and assistant can write 'a', but student cannot.
            checker = permissions.SchemaPermissionRegistry.build_edit_checker(
                self.PERMISSION_SCOPE, ['a'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))

            # Admin can write 'b', but neither assistant nor student may.
            checker = permissions.SchemaPermissionRegistry.build_edit_checker(
                self.PERMISSION_SCOPE, ['b'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))

            # Admin can write 'c', but neither assistant nor student may.
            checker = permissions.SchemaPermissionRegistry.build_edit_checker(
                self.PERMISSION_SCOPE, ['c'])
            actions.login(self.ADMIN_EMAIL)
            self.assertTrue(checker(self.app_context))
            actions.login(self.IN_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))
            actions.login(self.NON_ROLE_EMAIL)
            self.assertFalse(checker(self.app_context))
示例#39
0
 def setUp(self):
     super(ExitUrlTest, self).setUp()
     actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)
     actions.login(ADMIN_EMAIL, is_admin=True)
示例#40
0
    def test_can_edit_false_if_user_is_not_admin(self):
        actions.login(self.email, is_admin=False)

        # Treat as module-protected. pylint: disable=protected-access
        self.assertFalse(core_tags._Runtime(self.app_context).can_edit())
示例#41
0
 def configure_environ_for_current_user(self):
     actions.login(self.email)
示例#42
0
 def setUp(self):
     super(AdminSettingsTests, self).setUp()
     actions.simple_add_course(COURSE_NAME, ADMIN_EMAIL, COURSE_TITLE)
     actions.login(ADMIN_EMAIL)
 def register(self):
     user = actions.login(STUDENT_EMAIL, is_admin=False)
     actions.register(self, STUDENT_NAME)
     return models.Student.get_enrolled_student_by_user(user)
 def test_submit_answers_button_in_session_no_student(self):
     actions.login(STUDENT_EMAIL, is_admin=False)
     button = self.get_button()
     self.assertEquals(UNIQUE_FORM_ID, button.attrib['data-form-id'])
     self.assertEquals('false', button.attrib['data-registered'])
 def setUp(self):
     super(ExampleEmbedAndHandlerV1SingleCourseTest, self).setUp()
     actions.login(self.admin_email, is_admin=True)
     actions.simple_add_course('course', self.admin_email, 'Course')
     self.user = users.get_current_user()
 def test_admin_tab_is_present_for_admin(self):
     actions.login(self.ADMIN_EMAIL, is_admin=True)
     dom = self.parse_html_string(self.get('/dashboard').body)
     self.assertIsNotNone(dom.find('.//a[@href="admin?action=admin"]'))
示例#47
0
 def test_global_whitelist_as_student(self):
     config.Registry.test_overrides[
         roles.GCB_WHITELISTED_USERS.name] = STUDENT_WHITELIST
     actions.login(STUDENT_EMAIL)
     self._expect_visible()
示例#48
0
 def test_whitelist_is_case_insensitive(self):
     WhitelistTest._whitelist = STUDENT_WHITELIST
     actions.login(STUDENT_EMAIL.upper())
     self._expect_visible()
示例#49
0
 def test_course_whitelist_as_student(self):
     WhitelistTest._whitelist = STUDENT_WHITELIST
     actions.login(STUDENT_EMAIL)
     self._expect_visible()
示例#50
0
 def test_global_whitelist_as_admin(self):
     config.Registry.test_overrides[
         roles.GCB_WHITELISTED_USERS.name] = STUDENT_WHITELIST
     actions.login(ADMIN_EMAIL, is_admin=True)
     self._expect_visible()
示例#51
0
    def test_authenticated_response_looks_correct(self):
        actions.login(self.user_email)

        self.assert_authenticated_response_looks_correct(
            self.testapp.get(student_dashboard.GlobalHandler.URL))
示例#52
0
 def test_course_whitelist_as_admin(self):
     WhitelistTest._whitelist = STUDENT_WHITELIST
     actions.login(ADMIN_EMAIL, is_admin=True)
     self._expect_visible()
 def register(self):
     if not self._is_registered:
         actions.login(self.STUDENT_EMAIL, is_admin=False)
         actions.register(self, self.STUDENT_NAME)
         self._is_registered = True
示例#54
0
    def test_authenticated_response_looks_correct(self):
        actions.login(self.user_email)

        self.assert_authenticated_response_looks_correct(
            self.testapp.get(self.namespaced_url),
            course_title=self.course_title)
示例#55
0
    def test_admin_actions_available_for_admin(self):
        actions.login(self.ADMIN_EMAIL, is_admin=True)

        dom = self.parse_html_string(self.get('admin').body)
        group = dom.find('.//*[@id="menu-group__admin"]')
        self.assertIsNotNone(group)
    def test_announcement_news(self):
        actions.login('*****@*****.**')
        actions.register(self, 'John Doe')
        time.sleep(1)
        locale = 'de'
        announcement = self._add_announcement_and_translation(locale,
                                                              is_draft=True)
        sent_data = {
            'key': str(announcement.key()),
            'title': 'Test Announcement',
            'date': utc.to_text(seconds=utc.now_as_timestamp()),
            'is_draft': False,
        }
        actions.login(self.ADMIN_EMAIL)
        response = self._put_announcement(sent_data)
        actions.login('*****@*****.**')

        # Verify announcement news item using news API directly
        news_items = news.CourseNewsDao.get_news_items()
        self.assertEquals(1, len(news_items))
        item = news_items[0]
        now_timestamp = utc.now_as_timestamp()
        self.assertEquals(
            announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
            item.url)
        self.assertEquals(
            str(
                announcements.TranslatableResourceAnnouncement.key_for_entity(
                    announcement)), item.resource_key)
        self.assertAlmostEqual(now_timestamp,
                               utc.datetime_to_timestamp(item.when),
                               delta=10)

        # Verify announcement news item looking at HTTP response to /course
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([
            news_tests_lib.NewsItem(
                'Test Announcement',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)
        ], news_tests_lib.extract_news_items_from_soup(soup))

        # Verify announcement news item translated title.
        self._set_prefs_locale(locale)
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([
            news_tests_lib.NewsItem(
                'TEST ANNOUNCEMENT',
                announcements.AnnouncementsStudentHandler.URL.lstrip('/'),
                True)
        ], news_tests_lib.extract_news_items_from_soup(soup))

        # Delete the announcement; news item should also go away.
        actions.login(self.ADMIN_EMAIL)
        self._delete_announcement(str(announcement.key()))
        actions.login('*****@*****.**')
        response = self.get('course')
        soup = self.parse_html_string_to_soup(response.body)
        self.assertEquals([],
                          news_tests_lib.extract_news_items_from_soup(soup))
示例#57
0
 def test_post_invalid_label_id(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     self._verify_error(self.post(STUDENT_LABELS_URL, {'labels': '123'}),
                        'Unknown label id(s): [\'123\']', 400)
示例#58
0
    def test_registration_sets_last_seen_on(self):
        actions.login('*****@*****.**')
        actions.register(self, 'User 1')
        student = models.Student.all().get()

        self.assertTrue(isinstance(student.last_seen_on, datetime.datetime))
示例#59
0
 def test_post_no_labels_param(self):
     actions.login(REGISTERED_STUDENT_EMAIL)
     self._verify_labels(self.post(STUDENT_LABELS_URL, {}), [])
示例#60
0
文件: roles.py 项目: thejeshgn/seek
 def test_is_user_allowed_logged_in(self):
     actions.login(STUDENT_EMAIL)
     self.assertFalse(
         roles.Roles.is_user_allowed(self._get_course(), PERMISSION_MODULE,
                                     PERMISSION))