def testModulestoreImportLookups(self): testFilePath = os.path.join(os.path.dirname(__file__), 'data/modulestore_sample.json') pickleFilePath = os.path.join(os.path.dirname(__file__), 'data/modulestore_sample.pkl') importer = ModulestoreImporter(testFilePath, useCache=True, pickleCachePath=pickleFilePath) # The hash info: self.assertEqual(importer.getDisplayName("Introduction_to_Sociology"), 'Introduction to Sociology') self.assertEqual(importer.getDisplayName("0c6cf38317be42e0829d10cc68e7451b"), 'Quiz') self.assertEqual(importer.getDisplayName("0d6e5f3139e74c88adfdf4c90773f87f"), 'New Unit') self.assertEqual(importer.getOrg("0d6e5f3139e74c88adfdf4c90773f87f"), 'Medicine') self.assertEqual(importer.getCourseShortName("dc9cb4ff0c9241d2b9e075806490f992"), 'HRP258') self.assertEqual(importer.getCategory("Annotation"), 'annotatable') self.assertEqual(importer.getRevision("18b21999d6424f4ca04fe2bbe188fc9e"), 'draft') # Short coursenames to long coursenames: self.assertEqual(importer['SOC131'], 'LaneCollege/SOC131/Introduction_to_Sociology') self.assertEqual(importer.keys(), [u'SOC131']) self.assertEqual(importer.values(), [u'LaneCollege/SOC131/Introduction_to_Sociology']) self.assertEqual(importer.items(), [(u'SOC131', u'LaneCollege/SOC131/Introduction_to_Sociology')])
# Add json_to_relation source dir to $PATH # for duration of this execution: source_dir = [ os.path.join(os.path.dirname(os.path.abspath(__file__)), "../json_to_relation/") ] source_dir.extend(sys.path) sys.path = source_dir from modulestoreImporter import ModulestoreImporter from edxTrackLogJSONParser import EdXTrackLogJSONParser if __name__ == '__main__': USAGE = 'Usage: lookupOpenEdxHash.py hashStr1 hashstr2 ...' if len(sys.argv) < 2: print(USAGE) sys.exit() hashLookup = ModulestoreImporter(os.path.join( os.path.dirname(__file__), '../json_to_relation/data/modulestore_latest.json'), useCache=True) for hashStr in sys.argv[1:]: match = EdXTrackLogJSONParser.findHashPattern.search(hashStr) if match is not None: print(hashLookup.getDisplayName(match.group(1))) else: print 'None'
# long strings in tracking logs that contain that hex number somewhere # inside it # Add json_to_relation source dir to $PATH # for duration of this execution: source_dir = [os.path.join(os.path.dirname(os.path.abspath(__file__)), "../json_to_relation/")] source_dir.extend(sys.path) sys.path = source_dir from modulestoreImporter import ModulestoreImporter from edxTrackLogJSONParser import EdXTrackLogJSONParser if __name__ == '__main__': USAGE = 'Usage: lookupOpenEdxHash.py hashStr1 hashstr2 ...' if len(sys.argv) < 2: print(USAGE) sys.exit() hashLookup = ModulestoreImporter(os.path.join(os.path.dirname(__file__),'../json_to_relation/data/modulestore_latest.json'), useCache=True) for hashStr in sys.argv[1:]: match = EdXTrackLogJSONParser.findHashPattern.search(hashStr) if match is not None: print(hashLookup.getDisplayName(match.group(1))) else: print 'None'