Ejemplo n.º 1
0
    def test_get_endpoint(self):
        """
        Tests that storage_url method returns appropriate values.
        """
        # url ends with "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE",
                        {"url": "http://example.com/"}):
            self.assertEqual("http://example.com/", helpers.get_endpoint())

        # url doesn't have "/" at the end
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE",
                        {"url": "http://example.com"}):
            self.assertEqual("http://example.com/", helpers.get_endpoint())

        # url with path that starts with "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE",
                        {"url": "http://example.com"}):
            self.assertEqual("http://example.com/some_path/",
                             helpers.get_endpoint("/some_path"))

        # url with path without "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE",
                        {"url": "http://example.com"}):
            self.assertEqual("http://example.com/some_path/",
                             helpers.get_endpoint("some_path/"))

        # url is not configured
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE",
                        {"url": None}):
            self.assertRaises(ImproperlyConfigured, helpers.get_endpoint)
Ejemplo n.º 2
0
    def get_html(self, *args, **kwargs):
        """
        Returns raw html for the component.
        """
        is_studio = getattr(self.system, "is_author_mode", False)
        course = self.descriptor.runtime.modulestore.get_course(self.runtime.course_id)

        # Must be disabled:
        # - in Studio;
        # - when Harvard Annotation Tool is enabled for the course;
        # - when the feature flag or `edxnotes` setting of the course is set to False.
        if is_studio or not is_feature_enabled(course):
            return original_get_html(self, *args, **kwargs)
        else:
            return render_to_string("edxnotes_wrapper.html", {
                "content": original_get_html(self, *args, **kwargs),
                "uid": generate_uid(),
                "edxnotes_visibility": json.dumps(
                    getattr(self, 'edxnotes_visibility', course.edxnotes_visibility)
                ),
                "params": {
                    # Use camelCase to name keys.
                    "usageId": unicode(self.scope_ids.usage_id).encode("utf-8"),
                    "courseId": unicode(self.runtime.course_id).encode("utf-8"),
                    "token": get_id_token(self.runtime.get_real_user(self.runtime.anonymous_student_id)),
                    "tokenUrl": get_token_url(self.runtime.course_id),
                    "endpoint": get_endpoint(),
                    "debug": settings.DEBUG,
                    "eventStringLimit": settings.TRACK_MAX_EVENT / 6,
                },
            })
Ejemplo n.º 3
0
    def test_get_endpoint(self):
        """
        Tests that storage_url method returns appropriate values.
        """
        # url ends with "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE", {"url": "http://example.com/"}):
            self.assertEqual("http://example.com/", helpers.get_endpoint())

        # url doesn't have "/" at the end
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE", {"url": "http://example.com"}):
            self.assertEqual("http://example.com/", helpers.get_endpoint())

        # url with path that starts with "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE", {"url": "http://example.com"}):
            self.assertEqual("http://example.com/some_path/", helpers.get_endpoint("/some_path"))

        # url with path without "/"
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE", {"url": "http://example.com"}):
            self.assertEqual("http://example.com/some_path/", helpers.get_endpoint("some_path/"))

        # url is not configured
        with patch.dict("django.conf.settings.EDXNOTES_INTERFACE", {"url": None}):
            self.assertRaises(ImproperlyConfigured, helpers.get_endpoint)