Does 3 things: (1) Use django for modulestore tests (2) Use normal LMS settings for modulestore tests instead of openedx/tests/settings.py (3) Simplify some TestCase subclasses by converting them to use ModuleStoreTestCase Details and rationale: (1) Currently parts of the modulestore test suite are designed to run "without django", although there is still a lot of django functionality imported at times, and many of the tests do in fact use django. But for the upcoming PR #27565 (moving split's course indexes from MongoDB to MySQL), we will need to always have Django enabled. So this commit paves the way for that change. (2) The previous tests that did use Django used a special settings file, openedx/tests/settings.py which made some debugging confusing because those tests had quite different django settings than other tests. This change deletes that file and runs the tests using the LMS test settings. (3) The test suite also contains many different ways of initializing and testing a modulestore, with significant differences in their configuration, and also a lot of repetition. I find this makes understanding, debugging and writing tests more difficult. So this commit also reduces the number of different "test case using modulestore" base classes: * Simplifies MixedWithOptionsTestCase and MixedSplitTestCase by making them simple subclasses of ModuleStoreTestCase. * Removes PureModulestoreTestCase.
68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
"""
|
|
Decorators related to edXNotes.
|
|
"""
|
|
|
|
|
|
import json
|
|
|
|
from django.conf import settings
|
|
|
|
from common.djangoapps.edxmako.shortcuts import render_to_string
|
|
|
|
|
|
def edxnotes(cls):
|
|
"""
|
|
Decorator that makes components annotatable.
|
|
"""
|
|
original_get_html = cls.get_html
|
|
|
|
def get_html(self, *args, **kwargs):
|
|
"""
|
|
Returns raw html for the component.
|
|
"""
|
|
# Import is placed here to avoid model import at project startup.
|
|
from .helpers import (
|
|
generate_uid, get_edxnotes_id_token, get_public_endpoint, get_token_url, is_feature_enabled
|
|
)
|
|
|
|
if not settings.FEATURES.get("ENABLE_EDXNOTES"):
|
|
return original_get_html(self, *args, **kwargs)
|
|
|
|
runtime = getattr(self, 'descriptor', self).runtime
|
|
if not hasattr(runtime, 'modulestore'):
|
|
return original_get_html(self, *args, **kwargs)
|
|
|
|
is_studio = getattr(self.system, "is_author_mode", False)
|
|
course = getattr(self, 'descriptor', self).runtime.modulestore.get_course(self.runtime.course_id)
|
|
|
|
# Must be disabled when:
|
|
# - in Studio
|
|
# - Harvard Annotation Tool is enabled for the course
|
|
# - the feature flag or `edxnotes` setting of the course is set to False
|
|
# - the user is not authenticated
|
|
user = self.runtime.get_real_user(self.runtime.anonymous_student_id)
|
|
|
|
if is_studio or not is_feature_enabled(course, user):
|
|
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": str(self.scope_ids.usage_id),
|
|
"courseId": str(self.runtime.course_id),
|
|
"token": get_edxnotes_id_token(user),
|
|
"tokenUrl": get_token_url(self.runtime.course_id),
|
|
"endpoint": get_public_endpoint(),
|
|
"debug": settings.DEBUG,
|
|
"eventStringLimit": settings.TRACK_MAX_EVENT / 6,
|
|
},
|
|
})
|
|
|
|
cls.get_html = get_html
|
|
return cls
|