示例#1
0
def get_sent_messages(account_id, text=None, offset=None, limit=None):
    data = personal_messages_pb2.GetMessagesRequest(account_id=account_id,
                                                    type=personal_messages_pb2.OwnerType.DESCRIPTOR.values_by_name['SENDER'].number,
                                                    text=text,
                                                    offset=offset,
                                                    limit=limit)

    answer = tt_api.sync_request(url=conf.settings.TT_GET_MESSAGES_URL,
                                 data=data,
                                 AnswerType=personal_messages_pb2.GetMessagesResponse)

    return answer.total, answer.messages
示例#2
0
    async def test_no_messages(self):
        await self.prepair_data()
        request = await self.client.post(
            '/get-messages',
            data=personal_messages_pb2.GetMessagesRequest(
                account_id=666,
                type=relations.OWNER_TYPE.random().protocol_value,
                text=None,
                offset=None,
                limit=None).SerializeToString())
        data = await self.check_answer(
            request, personal_messages_pb2.GetMessagesResponse)

        self.assertEqual(data.total, 0)
        self.assertEqual(list(data.messages), [])
示例#3
0
    async def test_text_filter__single(self):
        await self.prepair_data()
        request = await self.client.post(
            '/get-messages',
            data=personal_messages_pb2.GetMessagesRequest(
                account_id=2,
                type=relations.OWNER_TYPE.RECIPIENT.protocol_value,
                text='3',
                offset=None,
                limit=None).SerializeToString())
        data = await self.check_answer(
            request, personal_messages_pb2.GetMessagesResponse)

        self.assertEqual(data.total, 1)
        self.assertEqual(list(data.messages), await
                         load_protocol_messages_by_bodies(['message 3']))
示例#4
0
    async def test_sender_type(self):
        await self.prepair_data()
        request = await self.client.post(
            '/get-messages',
            data=personal_messages_pb2.GetMessagesRequest(
                account_id=1,
                type=relations.OWNER_TYPE.SENDER.protocol_value,
                text=None,
                offset=None,
                limit=None).SerializeToString())
        data = await self.check_answer(
            request, personal_messages_pb2.GetMessagesResponse)

        self.assertEqual(data.total, 2)
        self.assertEqual(
            list(data.messages), await
            load_protocol_messages_by_bodies(['message 4', 'message 1']))