def __init__(self, modulestore, definition_id): """ Simple placeholder for yet-to-be-fetched data :param modulestore: the pymongo db connection with the definitions :param definition_locator: the id of the record in the above to fetch """ self.modulestore = modulestore self.definition_locator = DescriptionLocator(definition_id)
def test_create_parented_item(self): """ Test create_item w/ specifying the parent of the new item """ locator = BlockUsageLocator(course_id="wonderful", usage_id="head23456", branch='draft') premod_course = modulestore().get_course(locator) category = 'chapter' new_module = modulestore().create_item( locator, category, 'user123', fields={'display_name': 'new chapter'}, definition_locator=DescriptionLocator("chapter12345_2") ) # check that course version changed and course's previous is the other one self.assertNotEqual(new_module.location.version_guid, premod_course.location.version_guid) parent = modulestore().get_item(locator) self.assertIn(new_module.location.usage_id, parent.children) self.assertEqual(new_module.definition_locator.definition_id, "chapter12345_2")
def test_update_manifold(self): """ Test updating metadata, children, and definition in a single call ensuring all the versioning occurs """ # first add 2 children to the course for the update to manipulate locator = BlockUsageLocator(course_id="contender", usage_id="head345679", branch='draft') category = 'problem' new_payload = "<problem>empty</problem>" modulestore().create_item( locator, category, 'test_update_manifold', fields={'display_name': 'problem 1', 'data': new_payload}, ) another_payload = "<problem>not empty</problem>" modulestore().create_item( locator, category, 'test_update_manifold', fields={'display_name': 'problem 2', 'data': another_payload}, definition_locator=DescriptionLocator("problem12345_3_1"), ) # pylint: disable=W0212 modulestore()._clear_cache() # now begin the test block = modulestore().get_item(locator) pre_def_id = block.definition_locator.definition_id pre_version_guid = block.location.version_guid self.assertNotEqual(block.grading_policy['GRADER'][0]['min_count'], 13) block.grading_policy['GRADER'][0]['min_count'] = 13 block.children = block.children[1:] + [block.children[0]] block.advertised_start = "Soon" block.save() # decache model changes updated_block = modulestore().update_item(block, "test_update_manifold") self.assertNotEqual(updated_block.definition_locator.definition_id, pre_def_id) self.assertNotEqual(updated_block.location.version_guid, pre_version_guid) self.assertEqual(updated_block.grading_policy['GRADER'][0]['min_count'], 13) self.assertEqual(updated_block.children[0], block.children[0]) self.assertEqual(updated_block.advertised_start, "Soon")
def test_unique_naming(self): """ Check that 2 modules of same type get unique usage_ids. Also check that if creation provides a definition id and new def data that it branches the definition in the db. Actually, this tries to test all create_item features not tested above. """ locator = BlockUsageLocator(course_id="contender", usage_id="head345679", branch='draft') category = 'problem' premod_time = datetime.datetime.now(UTC) - datetime.timedelta(seconds=1) new_payload = "<problem>empty</problem>" new_module = modulestore().create_item( locator, category, 'anotheruser', fields={'display_name': 'problem 1', 'data': new_payload}, ) another_payload = "<problem>not empty</problem>" another_module = modulestore().create_item( locator, category, 'anotheruser', fields={'display_name': 'problem 2', 'data': another_payload}, definition_locator=DescriptionLocator("problem12345_3_1"), ) # check that course version changed and course's previous is the other one parent = modulestore().get_item(locator) self.assertNotEqual(new_module.location.usage_id, another_module.location.usage_id) self.assertIn(new_module.location.usage_id, parent.children) self.assertIn(another_module.location.usage_id, parent.children) self.assertEqual(new_module.data, new_payload) self.assertEqual(another_module.data, another_payload) # check definition histories new_history = modulestore().get_definition_history_info(new_module.definition_locator) self.assertIsNone(new_history['previous_version']) self.assertEqual(new_history['original_version'], new_module.definition_locator.definition_id) self.assertEqual(new_history['edited_by'], "anotheruser") self.assertLessEqual(new_history['edited_on'], datetime.datetime.now(UTC)) self.assertGreaterEqual(new_history['edited_on'], premod_time) another_history = modulestore().get_definition_history_info(another_module.definition_locator) self.assertEqual(another_history['previous_version'], 'problem12345_3_1')
def test_description_locator_version(self): definition_locator = DescriptionLocator("chapter12345_2") self.assertEqual("chapter12345_2", definition_locator.version())
def test_description_locator_url(self): definition_locator = DescriptionLocator("chapter12345_2") self.assertEqual('edx://' + URL_VERSION_PREFIX + 'chapter12345_2', definition_locator.url())