def test_old_location_helpers(self): """ Test the functions intended to help with the conversion from old locations to locators """ location_tuple = ('i4x', 'mit', 'eecs.6002x', 'course', 't3_2013') location = Location(location_tuple) self.assertEqual(location, Locator.to_locator_or_location(location)) self.assertEqual(location, Locator.to_locator_or_location(location_tuple)) self.assertEqual(location, Locator.to_locator_or_location(list(location_tuple))) self.assertEqual(location, Locator.to_locator_or_location(location.dict())) locator = BlockUsageLocator(package_id='foo.bar', branch='alpha', block_id='deep') self.assertEqual(locator, Locator.to_locator_or_location(locator)) self.assertEqual(locator.as_course_locator(), Locator.to_locator_or_location(locator.as_course_locator())) self.assertEqual(location, Locator.to_locator_or_location(location.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.__dict__)) asset_location = Location(['c4x', 'mit', 'eecs.6002x', 'asset', 'selfie.jpeg']) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location)) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location.url())) def_location_url = "defx://version/" + '{:024x}'.format(random.randrange(16 ** 24)) self.assertEqual(DefinitionLocator(def_location_url), Locator.to_locator_or_location(def_location_url)) with self.assertRaises(ValueError): Locator.to_locator_or_location(22) with self.assertRaises(ValueError): Locator.to_locator_or_location("hello.world.not.a.url") self.assertIsNone(Locator.parse_url("unknown://foo.bar/baz"))
def test_get_item(self): ''' get_item(blocklocator) ''' # positive tests of various forms locator = BlockUsageLocator(version_guid=self.GUID_D1, usage_id='head12345') block = modulestore().get_item(locator) self.assertIsInstance(block, CourseDescriptor) locator = BlockUsageLocator(course_id='GreekHero', usage_id='head12345', branch='draft') block = modulestore().get_item(locator) self.assertEqual(block.location.course_id, "GreekHero") # look at this one in detail self.assertEqual(len(block.tabs), 6, "wrong number of tabs") self.assertEqual(block.display_name, "The Ancient Greek Hero") self.assertEqual(block.advertised_start, "Fall 2013") self.assertEqual(len(block.children), 3) self.assertEqual(block.definition_locator.definition_id, "head12345_12") # check dates and graders--forces loading of descriptor self.assertEqual(block.edited_by, "*****@*****.**") self.assertDictEqual( block.grade_cutoffs, {"Pass": 0.45}, ) # try to look up other branches self.assertRaises(ItemNotFoundError, modulestore().get_item, BlockUsageLocator(course_id=locator.as_course_locator(), usage_id=locator.usage_id, branch='published')) locator.branch = 'draft' self.assertIsInstance( modulestore().get_item(locator), CourseDescriptor )
def test_old_location_helpers(self): """ Test the functions intended to help with the conversion from old locations to locators """ location_tuple = ('i4x', 'mit', 'eecs.6002x', 'course', 't3_2013') location = Location(location_tuple) self.assertEqual(location, Locator.to_locator_or_location(location)) self.assertEqual(location, Locator.to_locator_or_location(location_tuple)) self.assertEqual(location, Locator.to_locator_or_location(list(location_tuple))) self.assertEqual(location, Locator.to_locator_or_location(location.dict())) locator = BlockUsageLocator(course_id='foo.bar', branch='alpha', usage_id='deep') self.assertEqual(locator, Locator.to_locator_or_location(locator)) self.assertEqual( locator.as_course_locator(), Locator.to_locator_or_location(locator.as_course_locator())) self.assertEqual(location, Locator.to_locator_or_location(location.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.url())) self.assertEqual(locator, Locator.to_locator_or_location(locator.__dict__)) asset_location = Location( ['c4x', 'mit', 'eecs.6002x', 'asset', 'selfie.jpeg']) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location)) self.assertEqual(asset_location, Locator.to_locator_or_location(asset_location.url())) def_location_url = "defx://version/" + '{:024x}'.format( random.randrange(16**24)) self.assertEqual(DefinitionLocator(def_location_url), Locator.to_locator_or_location(def_location_url)) with self.assertRaises(ValueError): Locator.to_locator_or_location(22) with self.assertRaises(ValueError): Locator.to_locator_or_location("hello.world.not.a.url") self.assertIsNone(Locator.parse_url("unknown://foo.bar/baz"))
def test_get_item(self): ''' get_item(blocklocator) ''' # positive tests of various forms locator = BlockUsageLocator(version_guid=self.GUID_D1, usage_id='head12345') block = modulestore().get_item(locator) self.assertIsInstance(block, CourseDescriptor) # get_instance just redirects to get_item, ignores course_id self.assertIsInstance(modulestore().get_instance("course_id", locator), CourseDescriptor) def verify_greek_hero(block): self.assertEqual(block.location.course_id, "GreekHero") self.assertEqual(len(block.tabs), 6, "wrong number of tabs") self.assertEqual(block.display_name, "The Ancient Greek Hero") self.assertEqual(block.advertised_start, "Fall 2013") self.assertEqual(len(block.children), 3) self.assertEqual(block.definition_locator.definition_id, "head12345_12") # check dates and graders--forces loading of descriptor self.assertEqual(block.edited_by, "*****@*****.**") self.assertDictEqual( block.grade_cutoffs, {"Pass": 0.45}, ) locator = BlockUsageLocator(course_id='GreekHero', usage_id='head12345', branch='draft') verify_greek_hero(modulestore().get_item(locator)) # get_instance just redirects to get_item, ignores course_id verify_greek_hero(modulestore().get_instance("course_id", locator)) # try to look up other branches self.assertRaises(ItemNotFoundError, modulestore().get_item, BlockUsageLocator(course_id=locator.as_course_locator(), usage_id=locator.usage_id, branch='published')) locator.branch = 'draft' self.assertIsInstance( modulestore().get_item(locator), CourseDescriptor )