Esempio n. 1
0
    def test_jump_to_for_learner_with_staff_only_content(self, is_staff_user, position):
        """
        Test for checking correct position in redirect_url for learner when a course has staff-only units.
        """
        course = CourseFactory.create()
        request = RequestFactory().get('/')
        request.user = UserFactory(is_staff=is_staff_user, username="******")
        request.session = {}
        course_key = CourseKey.from_string(six.text_type(course.id))
        chapter = ItemFactory.create(category='chapter', parent_location=course.location)
        section = ItemFactory.create(category='sequential', parent_location=chapter.location)
        __ = ItemFactory.create(category='vertical', parent_location=section.location)
        staff_only_vertical = ItemFactory.create(category='vertical', parent_location=section.location,
                                                 metadata=dict(visible_to_staff_only=True))
        __ = ItemFactory.create(category='vertical', parent_location=section.location)

        usage_key = UsageKey.from_string(six.text_type(staff_only_vertical.location)).replace(course_key=course_key)
        expected_url = reverse(
            'courseware_position',
            kwargs={
                'course_id': six.text_type(course.id),
                'chapter': chapter.url_name,
                'section': section.url_name,
                'position': position,
            }
        )
        expected_url += "?{}".format(urlencode({'activate_block_id': six.text_type(staff_only_vertical.location)}))

        self.assertEqual(expected_url, get_redirect_url(course_key, usage_key, request))
Esempio n. 2
0
def _reverse_usage(item):
    from lms.djangoapps.courseware.url_helpers import get_redirect_url
    course_key = item.location.course_key
    url = get_redirect_url(course_key, item.location)
    try:
        url = url.split('?')[0]
    except AttributeError:
        pass
    return url
Esempio n. 3
0
def _reverse_usage(item):
    from lms.djangoapps.courseware.url_helpers import get_redirect_url
    course_key = item.location.course_key
    url = get_redirect_url(course_key, item.location)
    try:
        url = url.split('?')[0]
    except AttributeError:
        pass
    return url
Esempio n. 4
0
    def test_courseware_html(self, default_store, mongo_calls):
        """
        To verify that the removal of courseware chrome elements is working,
        we include this test here to make sure the chrome elements that should
        be removed actually exist in the full courseware page.
        If this test fails, it's probably because the HTML template for courseware
        has changed and COURSEWARE_CHROME_HTML_ELEMENTS needs to be updated.
        """
        with self.store.default_store(default_store):
            self.setup_course(default_store)
            self.setup_user(admin=True, enroll=True, login=True)

            with check_mongo_calls(mongo_calls):
                url = get_redirect_url(self.course.id, self.html_block.location)
                response = self.client.get(url)
                for chrome_element in self.COURSEWARE_CHROME_HTML_ELEMENTS:
                    self.assertContains(response, chrome_element)
Esempio n. 5
0
    def test_courseware_html(self, default_store, mongo_calls):
        """
        To verify that the removal of courseware chrome elements is working,
        we include this test here to make sure the chrome elements that should
        be removed actually exist in the full courseware page.
        If this test fails, it's probably because the HTML template for courseware
        has changed and COURSEWARE_CHROME_HTML_ELEMENTS needs to be updated.
        """
        with self.store.default_store(default_store):
            self.setup_course(default_store)
            self.setup_user(admin=True, enroll=True, login=True)

            with check_mongo_calls(mongo_calls):
                url = get_redirect_url(self.course.id, self.html_block.location)
                response = self.client.get(url)
                for chrome_element in self.COURSEWARE_CHROME_HTML_ELEMENTS:
                    self.assertContains(response, chrome_element)
Esempio n. 6
0
def eol_jump_to(request, course_id, location):
    """
    EOL UPDATE: If item not found redirect to course home page
    Show the page that contains a specific location.
    If the location is invalid or not in any class, return a 404.
    Otherwise, delegates to the index view to figure out whether this user
    has access, and what they should see.
    """
    try:
        course_key = CourseKey.from_string(course_id)
        usage_key = UsageKey.from_string(location).replace(course_key=course_key)
    except InvalidKeyError:
        raise Http404(u"Invalid course_key or usage_key")
    try:
        redirect_url = get_redirect_url(course_key, usage_key, request)
    except ItemNotFoundError:
        # If item not found redirect to course home page
        redirect_url = reverse(course_home_url_name(course_key), kwargs={'course_id': course_id})
    except NoPathToItem:
        raise Http404(u"This location is not in any class: {0}".format(usage_key))
    return redirect(redirect_url)