def test_from_json_studio_editor_style(self): """ Test that LibraryList can parse raw libraries list as passed by studio editor """ lib_list = LibraryList() lib1_key, lib1_version = u'library-v1:Org1+Lib1', '5436ffec56c02c13806a4c1b' lib2_key, lib2_version = u'library-v1:Org2+Lib2', '112dbaf312c0daa019ce9992' raw = [lib1_key + ',' + lib1_version, lib2_key + ',' + lib2_version] parsed = lib_list.from_json(raw) self.assertEqual(len(parsed), 2) self.assertEquals(parsed[0].library_id, LibraryLocator.from_string(lib1_key)) self.assertEquals(parsed[0].version, ObjectId(lib1_version)) self.assertEquals(parsed[1].library_id, LibraryLocator.from_string(lib2_key)) self.assertEquals(parsed[1].version, ObjectId(lib2_version))
def test_from_json_studio_editor_style(self): """ Test that LibraryList can parse raw libraries list as passed by studio editor """ lib_list = LibraryList() lib1_key, lib1_version = u'library-v1:Org1+Lib1', '5436ffec56c02c13806a4c1b' lib2_key, lib2_version = u'library-v1:Org2+Lib2', '112dbaf312c0daa019ce9992' raw = [lib1_key + ',' + lib1_version, lib2_key + ',' + lib2_version] parsed = lib_list.from_json(raw) self.assertEqual(len(parsed), 2) self.assertEquals(parsed[0].library_id, LibraryLocator.from_string(lib1_key)) self.assertEquals(parsed[0].version, ObjectId(lib1_version)) self.assertEquals(parsed[1].library_id, LibraryLocator.from_string(lib2_key)) self.assertEquals(parsed[1].version, ObjectId(lib2_version))
def test_no_libraries(self): """ Verify that only Course IDs are returned, not anything else like libraries. """ # Make this user a course staff user for a course, AND a library. course_staff_user = self.create_user(username='******', is_staff=False) add_users(self.global_admin, CourseStaffRole(self.course.id), course_staff_user) add_users( self.global_admin, CourseStaffRole( LibraryLocator.from_string( 'library-v1:library_org+library_name')), course_staff_user, ) # Requesting the courses should return *only* courses and not libraries. self.setup_user(self.staff_user) filtered_response = self.verify_response( params={ 'username': course_staff_user.username, 'role': 'staff' }) self.assertEqual(len(filtered_response.data['results']), 1) self.assertTrue(filtered_response.data['results'][0].startswith( self.course.org))
def _get_library(self, library_key): """ Given a library key like "library-v1:ProblemX+PR0B", return the 'library' XBlock with meta-information about the library. Returns None on error. """ if not isinstance(library_key, LibraryLocator): library_key = LibraryLocator.from_string(library_key) assert library_key.version_guid is None try: return self.store.get_library(library_key, remove_version=False, remove_branch=False) except ItemNotFoundError: return None
def __new__(cls, library_id, version=None): # pylint: disable=super-on-old-class if not isinstance(library_id, LibraryLocator): library_id = LibraryLocator.from_string(library_id) if library_id.version_guid: assert (version is None) or (version == library_id.version_guid) if not version: version = library_id.version_guid library_id = library_id.for_version(None) if version and not isinstance(version, ObjectId): try: version = ObjectId(version) except InvalidId: raise ValueError(version) return super(LibraryVersionReference, cls).__new__(cls, library_id, version)
def source_library_key(self): """ Convenience method to get the library ID as a LibraryLocator and not just a string """ return LibraryLocator.from_string(self.source_library_id)
def source_library_key(self): """ Convenience method to get the library ID as a LibraryLocator and not just a string """ return LibraryLocator.from_string(self.source_library_id)
def test_lib_key_with_trailing_whitespace(self, lib_id_fmt, whitespace): with self.assertRaises(InvalidKeyError): LibraryLocator.from_string(lib_id_fmt.format(whitespace))
def test_lib_key_from_invalid_string(self, lib_id_str): with self.assertRaises(InvalidKeyError): LibraryLocator.from_string(lib_id_str)
def test_lib_key_with_trailing_whitespace(self, lib_id_fmt, whitespace): with self.assertRaises(InvalidKeyError): LibraryLocator.from_string(lib_id_fmt.format(whitespace))
def test_lib_key_from_invalid_string(self, lib_id_str): with self.assertRaises(InvalidKeyError): LibraryLocator.from_string(lib_id_str)