def testMessageParser(self):
        WidgetMessage = messages.model_message(Widget)

        message = WidgetMessage(title='The Doctor', content='Time Lord')
        request = Bunch(body=unicode(protojson.encode_message(message)))

        parser = MessageParser().process(request, WidgetMessage)

        assert parser.validate()
        assert parser.container == message

        w = Widget()
        parser.update(w)

        assert w.title == message.title
        assert w.content == message.content

        # Partial update
        message = WidgetMessage(title='Susan')
        request = Bunch(body=unicode(protojson.encode_message(message)))
        parser = MessageParser().process(request, WidgetMessage)
        parser.update(w)

        assert w.title == 'Susan'
        assert w.content == 'Time Lord'
    def testMessageParser(self):
        WidgetMessage = messages.model_message(Widget)

        message = WidgetMessage(title='The Doctor', content='Time Lord')
        request = Bunch(body=unicode(protojson.encode_message(message)))

        parser = MessageParser().process(request, WidgetMessage)

        assert parser.validate()
        assert parser.container == message

        w = Widget()
        parser.update(w)

        assert w.title == message.title
        assert w.content == message.content

        # Partial update
        message = WidgetMessage(title='Susan')
        request = Bunch(body=unicode(protojson.encode_message(message)))
        parser = MessageParser().process(request, WidgetMessage)
        parser.update(w)

        assert w.title == 'Susan'
        assert w.content == 'Time Lord'
    def testMessageParser(self):
        WidgetMessage = messages.model_message(Widget)

        message = WidgetMessage(title='The Doctor', content='Time Lord')
        request = Bunch(body=unicode(protojson.encode_message(message)))

        parser = MessageParser().process(request, WidgetMessage)

        assert parser.validate()
        assert parser.container == message
    def testMessageView(self):
        WidgetMessage = messages.model_message(Widget)
        controller = Bunch(events=NamedEvents(), response=Bunch())
        view = MessageView(controller)

        view.context['data'] = WidgetMessage(title='Bad Wolf', content='Rose Tyler')

        result = view.render()

        assert result.content_type == 'application/json'
        assert result.unicode_body

        data = json.loads(result.unicode_body)
        assert data['title'] == 'Bad Wolf'
        assert data['content'] == 'Rose Tyler'
    def testMessageView(self):
        WidgetMessage = messages.model_message(Widget)
        controller = Bunch(events=NamedEvents(), response=Bunch())
        view = MessageView(controller)

        view.context['data'] = WidgetMessage(title='Bad Wolf', content='Rose Tyler')

        result = view.render()

        assert result.content_type == 'application/json'
        assert result.unicode_body

        data = json.loads(result.unicode_body)
        assert data['title'] == 'Bad Wolf'
        assert data['content'] == 'Rose Tyler'
Esempio n. 6
0
    def test_monkey(self):
        user = users.User(email='*****@*****.**')
        assert user.domain_info

        user = users.User(email='*****@*****.**')
        assert not user.domain_info

        class DummyModel(ndb.Model):
            user = ndb.UserProperty()

        DummyMessage = messages.model_message(DummyModel)
        instance = DummyModel(user=users.User(email='*****@*****.**'))
        message = messages.to_message(instance, DummyMessage)

        assert message.user.name == 'Jonathan Parrott'
        assert len(message.user.groups)


        instance = DummyModel(user=users.User(email='*****@*****.**'))
        message = messages.to_message(instance, DummyMessage)

        assert not message.user.name
        assert not message.user.groups
Esempio n. 7
0
    def test_monkey(self):
        user = users.User(email='*****@*****.**')
        assert user.domain_info

        user = users.User(email='*****@*****.**')
        assert not user.domain_info

        class DummyModel(ndb.Model):
            user = ndb.UserProperty()

        DummyMessage = messages.model_message(DummyModel)
        instance = DummyModel(user=users.User(
            email='*****@*****.**'))
        message = messages.to_message(instance, DummyMessage)

        assert message.user.name == 'Jonathan Parrott'
        assert len(message.user.groups)

        instance = DummyModel(user=users.User(
            email='*****@*****.**'))
        message = messages.to_message(instance, DummyMessage)

        assert not message.user.name
        assert not message.user.groups
Esempio n. 8
0
 def api_update_land(self, p_key):
     self.meta.Model = Land
     land = self.util.decode_key(p_key).get()
     land.update(json_loads(self.request.body, self.meta.keys))
     self.meta.Message = messages.model_message(Land)
     self.context['data'] = land
Esempio n. 9
0
 def api_create_land(self):
     self.meta.Model = Land
     land = Land.create(json_loads(self.request.body, self.meta.keys))
     self.meta.Message = messages.model_message(Land)
     self.context['data'] = land
Esempio n. 10
0
 def api_update_land(self, p_key):
     self.meta.Model = Land
     land = self.util.decode_key(p_key).get()
     land.update(json_loads(self.request.body, self.meta.keys))
     self.meta.Message = messages.model_message(Land)
     self.context['data'] = land
Esempio n. 11
0
 def api_create_land(self):
     self.meta.Model = Land
     land = Land.create(json_loads(self.request.body, self.meta.keys))
     self.meta.Message = messages.model_message(Land)
     self.context['data'] = land