Skip to content

Instantly share code, notes, and snippets.

@bradenmacdonald
Created October 19, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradenmacdonald/d280ae7124257f06f70dd9ce08178fd8 to your computer and use it in GitHub Desktop.
Save bradenmacdonald/d280ae7124257f06f70dd9ce08178fd8 to your computer and use it in GitHub Desktop.
Test new MySQL-based Split Mongo modulestore Case Sensitivity
from datetime import datetime
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from common.djangoapps.split_modulestore_django.models import SplitModulestoreCourseIndex
from bson.objectid import ObjectId
split_modulestore = modulestore()._get_modulestore_by_type(ModuleStoreEnum.Type.split)
course_index_common = {
"course": "TL101",
"run": "2015",
"edited_by": ModuleStoreEnum.UserID.mgmt_command,
"edited_on": datetime.now(),
"last_update": datetime.now(),
"versions": {},
"schema_version": 1,
"search_targets": {"wiki_slug": "TLslug"},
}
course_index_1 = {**course_index_common, "_id": ObjectId("553115a9d15a010b5c6f7228"), "org": "edx"}
course_index_2 = {**course_index_common, "_id": ObjectId("550869e42d00970b5b082d2a"), "org": "edX"}
data1 = SplitModulestoreCourseIndex.fields_from_v1_schema(course_index_1)
data2 = SplitModulestoreCourseIndex.fields_from_v1_schema(course_index_2)
print(data1["course_id"])
print(data2["course_id"])
SplitModulestoreCourseIndex(**data1).save()
SplitModulestoreCourseIndex(**data2).save()
# ^ The above will fail if the course key is still case insensitive
# Cleanup:
from opaque_keys.edx.keys import CourseKey
split_modulestore.db_connection.delete_course_index(CourseKey.from_string("course-v1:edX+TL101+2015"))
split_modulestore.db_connection.delete_course_index(CourseKey.from_string("course-v1:edx+TL101+2015"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment