def test_polymorphic_serializer_primitive_types(self): serializer = serialization.get_polymorphic_serializer() self.assertEqual(17, serializer.deserialize(serializer.serialize(17))) self.assertEqual( 0.34, serializer.deserialize(serializer.serialize(0.34)) ) self.assertEqual(-5, serializer.deserialize(serializer.serialize(-5))) self.assertEqual( -6.3, serializer.deserialize(serializer.serialize(-6.3)) ) self.assertFalse(serializer.deserialize(serializer.serialize(False))) self.assertTrue(serializer.deserialize(serializer.serialize(True))) self.assertEqual( 'abc', serializer.deserialize(serializer.serialize('abc')) ) self.assertEqual( {'a': 'b', 'c': 'd'}, serializer.deserialize(serializer.serialize({'a': 'b', 'c': 'd'})) ) self.assertEqual( ['a', 'b', 'c'], serializer.deserialize(serializer.serialize(['a', 'b', 'c'])) )
def test_polymorphic_serializer_custom_object(self): serializer = serialization.get_polymorphic_serializer() obj = MyClass('a', 'b') s = serializer.serialize(obj) self.assertIn('__serial_key', s) self.assertIn('__serial_data', s) self.assertEqual(obj, serializer.deserialize(s)) self.assertIsNone(serializer.serialize(None)) self.assertIsNone(serializer.deserialize(None))
def _register_mistral_serialization(self): """Adds mistral serializer to available serializers in kombu.""" self.serializer = mistral_serialization.get_polymorphic_serializer()
def __init__(self, entity_serializer=None): self.entity_serializer = ( entity_serializer or serialization.get_polymorphic_serializer() )
def _register_mistral_serialization(self): """Adds mistral serializer to available serializers in kombu.""" self.serializer = mistral_serialization.get_polymorphic_serializer()
def __init__(self, entity_serializer=None): self.entity_serializer = (entity_serializer or serialization.get_polymorphic_serializer())
def deserialize_from_dict(self, entity_dict): p_serializer = serialization.get_polymorphic_serializer() return AdHocAction(p_serializer.deserialize( entity_dict['base_action']))
def serialize_to_dict(self, entity): p_serializer = serialization.get_polymorphic_serializer() return {'base_action': p_serializer.serialize(entity.base_action)}