def test_roundtrip_from_key(self, family, block_type): key = BlockTypeKeyV1(family, block_type) serialized = text_type(key) deserialized = BlockTypeKey.from_string(serialized) self.assertEqual(key, deserialized)
def test_parse_deprecated_type(self, key): block_type = BlockTypeKey.from_string(key) self.assertEqual(key, block_type.block_type) self.assertEqual('xblock.v1', block_type.block_family)
def test_roundtrip_from_string(self, key): block_type = BlockTypeKey.from_string(key) serialized = text_type(block_type) self.assertEqual(key, serialized)
Return an instance of `cls` parsed from its deprecated `serialized` form. This will be called only if :meth:`OpaqueKey.from_string` is unable to parse a key out of `serialized`, and only if `set_deprecated_fallback` has been called to register a fallback class. 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`. """ return cls(XBLOCK_V1, serialized) def _to_deprecated_string(self): """ Return a deprecated serialization of `self`. This will be called only if `set_deprecated_fallback` has been called to register a fallback class, and the key being serialized has the attribute `deprecated=True`. This serialization should not include the namespace prefix. """ return self.block_type BlockTypeKey.set_deprecated_fallback(BlockTypeKeyV1)
def test_deprecated_roundtrip(self, key): block_type = BlockTypeKey.from_string(key) serialized = str(block_type) self.assertEqual(key, serialized)
def test_roundtrip_from_key(self, family, block_type): key = BlockTypeKeyV1(family, block_type) serialized = unicode(key) deserialized = BlockTypeKey.from_string(serialized) self.assertEqual(key, deserialized)
def test_roundtrip_from_string(self, key): block_type = BlockTypeKey.from_string(key) serialized = unicode(block_type) self.assertEqual(key, serialized)
""" Return an instance of `cls` parsed from its deprecated `serialized` form. This will be called only if :meth:`OpaqueKey.from_string` is unable to parse a key out of `serialized`, and only if `set_deprecated_fallback` has been called to register a fallback class. 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`. """ return cls(XBLOCK_V1, serialized) def _to_deprecated_string(self): """ Return a deprecated serialization of `self`. This will be called only if `set_deprecated_fallback` has been called to register a fallback class, and the key being serialized has the attribute `deprecated=True`. This serialization should not include the namespace prefix. """ return self.block_type BlockTypeKey.set_deprecated_fallback(BlockTypeKeyV1)
def test_deprecated_roundtrip(self, key): block_type = BlockTypeKey.from_string(key) serialized = text_type(block_type) self.assertEqual(key, serialized)