Exemple #1
0
    def test_get_messages(self):

        user = User(first_name="me", full_name="me too", facebook_id=8766)
        user.initialise_new_token()
        user.put()

        parent_key = ndb.Key("some_kind3", "some_id3")

        self.api.add_message(
            messages.AuthChatMessage(body="hello!",
                                     recipients=[3452746],
                                     token=user.get_token(),
                                     parent_key=parent_key.urlsafe()))

        self.api.add_message(
            messages.AuthChatMessage(body="what's up?",
                                     recipients=[3452746],
                                     token=user.get_token(),
                                     parent_key=parent_key.urlsafe()))

        msg = self.api.get_messages(
            messages.ChatMessageRequest(token=user.get_token(),
                                        parent_key=parent_key.urlsafe()))

        assert msg.messages[0].body == "hello!"
        assert msg.messages[1].body == "what's up?"
    def test_chat_message_to_model(self):

        user = User(first_name="me", full_name="me too", facebook_id=976)
        user.initialise_new_token()
        user.put()

        msg = message.AuthChatMessage(body="hello",
                                      token=user.get_token(),
                                      recipients=[123, 456])

        model = actions.auth_chat_message_to_model(msg, user)

        assert model.sender_id == user.key.id()
        assert model.body == "hello"
        assert model.recipients == "123,456"
    def test_add_message(self):

        user = User(first_name="me", full_name="me too", facebook_id=87654)
        user.initialise_new_token()
        user.put()

        parent_key = ndb.Key("some_kind1", "some_id2")

        msg = message.AuthChatMessage(body="hello!",
                                      token=user.get_token(),
                                      recipients=[3452746],
                                      parent_key=parent_key.urlsafe())

        actions.add_message(msg, user)

        thread = models.Thread.get_by_key(parent_key, 1)

        assert thread.messages[0].body == "hello!"
        assert thread.messages[0].sender_id == user.key.id()
Exemple #4
0
    def test_get_user_thread_key(self):

        user = User(first_name="Adrian",
                    full_name="Adrian Letchford",
                    facebook_id=8766)
        user.initialise_new_token()
        user.put()

        user2 = User(first_name="Benjamin",
                     full_name="Benjamin Letchford",
                     facebook_id=87668)
        user2.initialise_new_token()
        user2.put()

        msg = UserId(token=user.get_token(), user=user2.key.id())

        thread = self.api.get_user_thread_key(msg)

        assert len(thread.participants) == 2
        assert "Adrian Letchford" in [u.full_name for u in thread.participants]
        assert type(thread.key) is str
        assert len(thread.key) > 10
    def test_get_messages(self):

        user = User(first_name="me", full_name="me too", facebook_id=8765)
        user.initialise_new_token()
        user.put()

        parent_key = ndb.Key("some_kind3", "some_id3")

        actions.add_message(
            message.AuthChatMessage(body="hello!",
                                    recipients=[3452746],
                                    message_id="563",
                                    parent_key=parent_key.urlsafe()), user)

        actions.add_message(
            message.AuthChatMessage(body="what's up?",
                                    recipients=[3452746],
                                    message_id="08764",
                                    parent_key=parent_key.urlsafe()), user)

        msg = actions.get_messages(parent_key)

        assert msg.messages[0].body == "hello!"
        assert msg.messages[1].body == "what's up?"