コード例 #1
0
 def test_description_locator_url(self):
     object_id = '{:024x}'.format(random.randrange(16**24))
     definition_locator = DefinitionLocator(object_id)
     self.assertEqual('defx://' + VERSION_PREFIX + object_id,
                      definition_locator.url())
     self.assertEqual(definition_locator,
                      DefinitionLocator(definition_locator.url()))
コード例 #2
0
 def __init__(self, modulestore, block_type, 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 = DefinitionLocator(block_type, definition_id)
コード例 #3
0
 def test_description_locator_url(self):
     object_id = '{:024x}'.format(random.randrange(16**24))
     definition_locator = DefinitionLocator('html', object_id)
     self.assertEqual(
         'defx:{}+{}+html'.format(object_id,
                                  DefinitionLocator.BLOCK_TYPE_PREFIX),
         unicode(definition_locator))
     self.assertEqual(
         definition_locator,
         DefinitionKey.from_string(unicode(definition_locator)))
コード例 #4
0
    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"))
コード例 #5
0
 def test_description_locator_version(self):
     object_id = '{:024x}'.format(random.randrange(16**24))
     definition_locator = DefinitionLocator(object_id)
     self.assertEqual(object_id, str(definition_locator.version()))
コード例 #6
0
 def test_description_locator_version(self):
     object_id = '{:024x}'.format(random.randrange(16 ** 24))
     definition_locator = DefinitionLocator(object_id)
     self.assertEqual(object_id, str(definition_locator.version()))
コード例 #7
0
 def test_description_locator_url(self):
     object_id = '{:024x}'.format(random.randrange(16 ** 24))
     definition_locator = DefinitionLocator(object_id)
     self.assertEqual('defx://' + VERSION_PREFIX + object_id, definition_locator.url())
     self.assertEqual(definition_locator, DefinitionLocator(definition_locator.url()))
コード例 #8
0
 def test_description_locator_version(self):
     definition_locator = DefinitionLocator("chapter12345_2")
     self.assertEqual("chapter12345_2", definition_locator.version())
コード例 #9
0
 def test_description_locator_url(self):
     definition_locator = DefinitionLocator("chapter12345_2")
     self.assertEqual("edx://" + URL_VERSION_PREFIX + "chapter12345_2", definition_locator.url())
コード例 #10
0
 def test_description_locator_version(self):
     definition_locator = DefinitionLocator("chapter12345_2")
     self.assertEqual("chapter12345_2", definition_locator.version())
コード例 #11
0
 def test_description_locator_url(self):
     definition_locator = DefinitionLocator("chapter12345_2")
     self.assertEqual('edx://' + URL_VERSION_PREFIX + 'chapter12345_2', definition_locator.url())