def test_to_model(self):
        WidgetMessage, widget = self.make_test_model()

        # Simple test
        message = WidgetMessage(string='Dalek', integer=1)

        simple_widget = protopigeon.to_entity(message, MessageModelTest)

        assert message.string == simple_widget.string
        assert message.integer == simple_widget.integer

        # Updating an existing instance
        simple_widget = protopigeon.to_entity(message, MessageModelTest(string='Meow'))

        assert message.string == simple_widget.string
        assert message.integer == simple_widget.integer

        # Full serialization/deserialization comparion test.
        message = protopigeon.to_message(widget, WidgetMessage)
        print message
        deserialized = protopigeon.to_entity(message, MessageModelTest)

        for prop in MessageModelTest._properties.keys():
            assert getattr(deserialized, prop) == getattr(widget, prop)

        assert deserialized.key.urlsafe() == widget.key.urlsafe()
示例#2
0
    def test_to_model(self):
        WidgetMessage, widget = self.make_test_model()

        # Simple test
        message = WidgetMessage(string='Dalek', integer=1)

        simple_widget = protopigeon.to_entity(message, MessageModelTest)

        assert message.string == simple_widget.string
        assert message.integer == simple_widget.integer

        # Updating an existing instance
        simple_widget = protopigeon.to_entity(message,
                                              MessageModelTest(string='Meow'))

        assert message.string == simple_widget.string
        assert message.integer == simple_widget.integer

        # Full serialization/deserialization comparion test.
        message = protopigeon.to_message(widget, WidgetMessage)
        print message
        deserialized = protopigeon.to_entity(message, MessageModelTest)

        for prop in MessageModelTest._properties.keys():
            assert getattr(deserialized, prop) == getattr(widget, prop)

        assert deserialized.key.urlsafe() == widget.key.urlsafe()
示例#3
0
    def test_partials(self):
        WidgetMessage, widget = self.make_test_model()

        msg = WidgetMessage(string='meow')
        widget = protopigeon.to_entity(msg, widget, only=('string', ))

        assert widget.repeatedString
        assert widget.string == 'meow'

        widget = protopigeon.to_entity(msg, widget)

        assert not widget.repeatedString
    def test_partials(self):
        WidgetMessage, widget = self.make_test_model()

        msg = WidgetMessage(string='meow')
        widget = protopigeon.to_entity(msg, widget, only=('string',))

        assert widget.repeatedString
        assert widget.string == 'meow'

        widget = protopigeon.to_entity(msg, widget)

        assert not widget.repeatedString
    def test_keys(self):
        test_key = ndb.Key(MessageModelTest, '123')

        WidgetMessage = protopigeon.model_message(MessageModelTest)
        assert hasattr(WidgetMessage, 'id')

        m = WidgetMessage(id=test_key.urlsafe())
        assert protopigeon.to_entity(m, MessageModelTest).key == test_key

        WidgetMessage = protopigeon.model_message(MessageModelTest, key_field='key')
        assert hasattr(WidgetMessage, 'key')

        m = WidgetMessage(key=test_key.urlsafe())
        assert protopigeon.to_entity(m, MessageModelTest, key_field='key').key == test_key
    def test_keys(self):
        test_key = ndb.Key(MessageModelTest, '123')

        WidgetMessage = protopigeon.model_message(MessageModelTest)
        assert hasattr(WidgetMessage, 'id')

        m = WidgetMessage(id=test_key.urlsafe())
        assert protopigeon.to_entity(m, MessageModelTest).key == test_key

        WidgetMessage = protopigeon.model_message(MessageModelTest, key_field='key')
        assert hasattr(WidgetMessage, 'key')

        m = WidgetMessage(key=test_key.urlsafe())
        assert protopigeon.to_entity(m, MessageModelTest, key_field='key').key == test_key
示例#7
0
    def test_empty_values(self):
        WidgetMessage, widget = self.make_test_model()

        empty_widget = MessageModelTest()
        message = protopigeon.to_message(empty_widget, WidgetMessage)

        for prop in MessageModelTest._properties.keys():
            assert not getattr(message, prop)

        empty_message = WidgetMessage()
        widget = protopigeon.to_entity(empty_message, MessageModelTest)

        for field in WidgetMessage.all_fields():
            assert not getattr(widget, prop)
    def test_empty_values(self):
        WidgetMessage, widget = self.make_test_model()

        empty_widget = MessageModelTest()
        message = protopigeon.to_message(empty_widget, WidgetMessage)

        for prop in MessageModelTest._properties.keys():
            assert not getattr(message, prop)

        empty_message = WidgetMessage()
        widget = protopigeon.to_entity(empty_message, MessageModelTest)

        for field in WidgetMessage.all_fields():
            assert not getattr(widget, prop)
示例#9
0
def deserialize(Model, message):
    return protopigeon.to_entity(message, Model)
示例#10
0
def deserialize(Model, message, **kwargs):
    return protopigeon.to_entity(message, Model, **kwargs)