def test_relative(self): """ Test making a relative usage locator. """ org = 'mit.eecs' course = 'ponypower' run = "2014_T2" branch = 'foo' baseobj = CourseLocator(org=org, course=course, run=run, branch=branch) block_id = 'problem:with-colon~2' testobj = BlockUsageLocator.make_relative(baseobj, 'problem', block_id) self.check_block_locn_fields(testobj, org=org, course=course, run=run, branch=branch, block=block_id) block_id = 'completely_different' testobj = BlockUsageLocator.make_relative(testobj, 'problem', block_id) self.check_block_locn_fields(testobj, org=org, course=course, run=run, branch=branch, block=block_id)
def test_block_generations(self): """ Test get_block_generations """ test_course = persistent_factories.PersistentCourseFactory.create( offering="history.hist101", org="edu.harvard", display_name="history test course", user_id="testbot" ) chapter = persistent_factories.ItemFactory.create( display_name="chapter 1", parent_location=test_course.location, user_id="testbot" ) sub = persistent_factories.ItemFactory.create( display_name="subsection 1", parent_location=chapter.location, user_id="testbot", category="vertical" ) first_problem = persistent_factories.ItemFactory.create( display_name="problem 1", parent_location=sub.location, user_id="testbot", category="problem", data="<problem></problem>", ) first_problem.max_attempts = 3 first_problem.save() # decache the above into the kvs updated_problem = self.split_store.update_item(first_problem, "**replace_user**") self.assertIsNotNone(updated_problem.previous_version) self.assertEqual(updated_problem.previous_version, first_problem.update_version) self.assertNotEqual(updated_problem.update_version, first_problem.update_version) updated_loc = self.split_store.delete_item(updated_problem.location, "**replace_user**", "testbot") second_problem = persistent_factories.ItemFactory.create( display_name="problem 2", parent_location=BlockUsageLocator.make_relative( updated_loc, block_type="problem", block_id=sub.location.block_id ), user_id="testbot", category="problem", data="<problem></problem>", ) # course root only updated 2x version_history = self.split_store.get_block_generations(test_course.location) self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid) self.assertEqual(len(version_history.children), 1) self.assertEqual(version_history.children[0].children, []) self.assertEqual(version_history.children[0].locator.version_guid, chapter.location.version_guid) # sub changed on add, add problem, delete problem, add problem in strict linear seq version_history = self.split_store.get_block_generations(sub.location) self.assertEqual(len(version_history.children), 1) self.assertEqual(len(version_history.children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children[0].children), 0) # first and second problem may show as same usage_id; so, need to ensure their histories are right version_history = self.split_store.get_block_generations(updated_problem.location) self.assertEqual(version_history.locator.version_guid, first_problem.location.version_guid) self.assertEqual(len(version_history.children), 1) # updated max_attempts self.assertEqual(len(version_history.children[0].children), 0) version_history = self.split_store.get_block_generations(second_problem.location) self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid)
def test_block_generations(self): """ Test get_block_generations """ test_course = persistent_factories.PersistentCourseFactory.create( course='history', run='hist101', org='edu.harvard', display_name='history test course', user_id='testbot' ) chapter = persistent_factories.ItemFactory.create(display_name='chapter 1', parent_location=test_course.location, user_id='testbot') sub = persistent_factories.ItemFactory.create(display_name='subsection 1', parent_location=chapter.location, user_id='testbot', category='vertical') first_problem = persistent_factories.ItemFactory.create( display_name='problem 1', parent_location=sub.location, user_id='testbot', category='problem', data="<problem></problem>" ) first_problem.max_attempts = 3 first_problem.save() # decache the above into the kvs updated_problem = self.split_store.update_item(first_problem, 'testbot') self.assertIsNotNone(updated_problem.previous_version) self.assertEqual(updated_problem.previous_version, first_problem.update_version) self.assertNotEqual(updated_problem.update_version, first_problem.update_version) self.split_store.delete_item(updated_problem.location, 'testbot') second_problem = persistent_factories.ItemFactory.create( display_name='problem 2', parent_location=BlockUsageLocator.make_relative( test_course.location.version_agnostic(), block_type='problem', block_id=sub.location.block_id ), user_id='testbot', category='problem', data="<problem></problem>" ) # course root only updated 2x version_history = self.split_store.get_block_generations(test_course.location) # create course causes 2 versions for the time being; skip the first. version_history = version_history.children[0] self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid) self.assertEqual(len(version_history.children), 1) self.assertEqual(version_history.children[0].children, []) self.assertEqual(version_history.children[0].locator.version_guid, chapter.location.version_guid) # sub changed on add, add problem, delete problem, add problem in strict linear seq version_history = self.split_store.get_block_generations(sub.location) self.assertEqual(len(version_history.children), 1) self.assertEqual(len(version_history.children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children[0].children), 0) # first and second problem may show as same usage_id; so, need to ensure their histories are right version_history = self.split_store.get_block_generations(updated_problem.location) self.assertEqual(version_history.locator.version_guid, first_problem.location.version_guid) self.assertEqual(len(version_history.children), 1) # updated max_attempts self.assertEqual(len(version_history.children[0].children), 0) version_history = self.split_store.get_block_generations(second_problem.location) self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid)
def test_block_generations(self): """ Test get_block_generations """ test_course = persistent_factories.PersistentCourseFactory.create( course='history', run='hist101', org='edu.harvard', display_name='history test course', user_id='testbot' ) chapter = persistent_factories.ItemFactory.create(display_name='chapter 1', parent_location=test_course.location, user_id='testbot') sub = persistent_factories.ItemFactory.create(display_name='subsection 1', parent_location=chapter.location, user_id='testbot', category='vertical') first_problem = persistent_factories.ItemFactory.create( display_name='problem 1', parent_location=sub.location, user_id='testbot', category='problem', data="<problem></problem>" ) first_problem.max_attempts = 3 first_problem.save() # decache the above into the kvs updated_problem = self.split_store.update_item(first_problem, 'testbot') self.assertIsNotNone(updated_problem.previous_version) self.assertEqual(updated_problem.previous_version, first_problem.update_version) self.assertNotEqual(updated_problem.update_version, first_problem.update_version) self.split_store.delete_item(updated_problem.location, 'testbot') second_problem = persistent_factories.ItemFactory.create( display_name='problem 2', parent_location=BlockUsageLocator.make_relative( test_course.location.version_agnostic(), block_type='problem', block_id=sub.location.block_id ), user_id='testbot', category='problem', data="<problem></problem>" ) # course root only updated 2x version_history = self.split_store.get_block_generations(test_course.location) # create course causes 2 versions for the time being; skip the first. version_history = version_history.children[0] self.assertEqual(version_history.locator.version_guid, test_course.location.version_guid) self.assertEqual(len(version_history.children), 1) self.assertEqual(version_history.children[0].children, []) self.assertEqual(version_history.children[0].locator.version_guid, chapter.location.version_guid) # sub changed on add, add problem, delete problem, add problem in strict linear seq version_history = self.split_store.get_block_generations(sub.location) self.assertEqual(len(version_history.children), 1) self.assertEqual(len(version_history.children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children), 1) self.assertEqual(len(version_history.children[0].children[0].children[0].children), 0) # first and second problem may show as same usage_id; so, need to ensure their histories are right version_history = self.split_store.get_block_generations(updated_problem.location) self.assertEqual(version_history.locator.version_guid, first_problem.location.version_guid) self.assertEqual(len(version_history.children), 1) # updated max_attempts self.assertEqual(len(version_history.children[0].children), 0) version_history = self.split_store.get_block_generations(second_problem.location) self.assertNotEqual(version_history.locator.version_guid, first_problem.location.version_guid)
def test_relative(self): """ Test making a relative usage locator. """ org = 'mit.eecs' offering = '1' branch = 'foo' baseobj = CourseLocator(org=org, offering=offering, branch=branch) block_id = 'problem:with-colon~2' testobj = BlockUsageLocator.make_relative(baseobj, 'problem', block_id) self.check_block_locn_fields( testobj, org=org, offering=offering, branch=branch, block=block_id ) block_id = 'completely_different' testobj = BlockUsageLocator.make_relative(testobj, 'problem', block_id) self.check_block_locn_fields( testobj, org=org, offering=offering, branch=branch, block=block_id )
def test_relative(self): """ Test making a relative usage locator. """ org = 'mit.eecs' course = 'ponypower' run = "2014_T2" branch = 'foo' baseobj = CourseLocator(org=org, course=course, run=run, branch=branch) block_id = 'problem:with-colon~2' testobj = BlockUsageLocator.make_relative(baseobj, 'problem', block_id) self.check_block_locn_fields( testobj, org=org, course=course, run=run, branch=branch, block=block_id ) block_id = 'completely_different' testobj = BlockUsageLocator.make_relative(testobj, 'problem', block_id) self.check_block_locn_fields( testobj, org=org, course=course, run=run, branch=branch, block=block_id )
def test_relative(self): """ Test making a relative usage locator. """ org = 'mit.eecs' offering = '1' branch = 'foo' baseobj = CourseLocator(org=org, offering=offering, branch=branch) block_id = 'problem:with-colon~2' testobj = BlockUsageLocator.make_relative(baseobj, 'problem', block_id) self.check_block_locn_fields(testobj, org=org, offering=offering, branch=branch, block=block_id) block_id = 'completely_different' testobj = BlockUsageLocator.make_relative(testobj, 'problem', block_id) self.check_block_locn_fields(testobj, org=org, offering=offering, branch=branch, block=block_id)
def test_superclass_make_relative(self): lib_key = LibraryLocator(org="TestX", library="problem-bank-15") obj = BlockUsageLocator.make_relative(lib_key, "block_type", "block_id") self.assertIsInstance(obj, LibraryUsageLocator)
def test_superclass_make_relative(self): lib_key = LibraryLocator(org="TestX", library="problem-bank-15") obj = BlockUsageLocator.make_relative(lib_key, "block_type", "block_id") self.assertIsInstance(obj, LibraryUsageLocator)