Example #1
0
 def test_description_locator_url(self):
     random_value = random.randrange(16**24)
     object_id = f'{random_value:024x}'
     definition_locator = DefinitionLocator('html', object_id)
     self.assertEqual(
         f'def-v1:{object_id}+{DefinitionLocator.BLOCK_TYPE_PREFIX}@html',
         str(definition_locator))
     self.assertEqual(definition_locator,
                      DefinitionKey.from_string(str(definition_locator)))
Example #2
0
 def test_description_locator_url(self):
     object_id = '{:024x}'.format(random.randrange(16**24))
     definition_locator = DefinitionLocator('html', object_id)
     self.assertEqual(
         'def-v1:{}+{}@html'.format(object_id,
                                    DefinitionLocator.BLOCK_TYPE_PREFIX),
         text_type(definition_locator))
     self.assertEqual(
         definition_locator,
         DefinitionKey.from_string(text_type(definition_locator)))
Example #3
0
    def _from_string(cls, serialized):
        """
        Return an instance of `cls` parsed from its `serialized` form.

        Args:
            cls: The :class:`OpaqueKey` subclass.
            serialized (unicode): A serialized :class:`OpaqueKey`, with namespace already removed.

        Raises:
            InvalidKeyError: Should be raised if `serialized` is not a valid serialized key
                understood by `cls`.
        """
        def_key, __, aside_type = serialized.partition("::")
        return cls(DefinitionKey.from_string(_decode(def_key)), _decode(aside_type))
Example #4
0
    def _from_string(cls, serialized):
        """
        Return an instance of `cls` parsed from its `serialized` form.

        Args:
            cls: The :class:`OpaqueKey` subclass.
            serialized (unicode): A serialized :class:`OpaqueKey`, with namespace already removed.

        Raises:
            InvalidKeyError: Should be raised if `serialized` is not a valid serialized key
                understood by `cls`.
        """
        def_key, __, aside_type = serialized.partition('::')
        return cls(DefinitionKey.from_string(_decode(def_key)),
                   _decode(aside_type))
Example #5
0
    def _from_string(cls, serialized):
        """
        Return an instance of `cls` parsed from its `serialized` form.

        Args:
            cls: The :class:`OpaqueKey` subclass.
            serialized (unicode): A serialized :class:`OpaqueKey`, with namespace already removed.

        Raises:
            InvalidKeyError: Should be raised if `serialized` is not a valid serialized key
                understood by `cls`.
        """
        try:
            def_key, aside_type = _split_keys_v1(serialized)
            return cls(DefinitionKey.from_string(def_key), aside_type)
        except ValueError as exc:
            raise InvalidKeyError(cls, exc.args) from exc
Example #6
0
 def test_roundtrip_from_key(self, key_args):
     key = BundleDefinitionLocator(**key_args)
     serialized = text_type(key)
     deserialized = DefinitionKey.from_string(serialized)
     self.assertEqual(key, deserialized)
Example #7
0
 def test_roundtrip_from_string(self, key):
     def_key = DefinitionKey.from_string(key)
     serialized = text_type(def_key)
     self.assertEqual(key, serialized)
 def test_description_locator_url(self):
     object_id = '{:024x}'.format(random.randrange(16 ** 24))
     definition_locator = DefinitionLocator('html', object_id)
     self.assertEqual('def-v1:{}+{}@html'.format(object_id, DefinitionLocator.BLOCK_TYPE_PREFIX),
                      unicode(definition_locator))
     self.assertEqual(definition_locator, DefinitionKey.from_string(unicode(definition_locator)))