Пример #1
0
    async def prepair_data(self):
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2, 3],
                body='a message 1').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=2, recipients_ids=[3],
                body='a message 2').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=3, recipients_ids=[1, 2],
                body='b message 3').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2, 4],
                body='b message 4').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)
Пример #2
0
    async def create_messages(self):
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2, 3],
                body='message 1').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=2, recipients_ids=[3],
                body='message 2').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)
Пример #3
0
    async def prepair_data(self):
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2],
                body='a message 1').SerializeToString())
        data = await self.check_answer(
            request, personal_messages_pb2.SendMessageResponse)

        self.message_id = data.message_id
Пример #4
0
    async def prepair_data(self):
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2, 3],
                body='message 1').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=2, recipients_ids=[3],
                body='message 2').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=3, recipients_ids=[1, 2],
                body='message 3').SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.SendMessageResponse)

        now = datetime.datetime.now()

        time_1 = now - datetime.timedelta(days=2)
        time_2 = now - datetime.timedelta(days=1)
        time_3 = now

        await db.sql(
            "UPDATE messages SET created_at=%(time)s WHERE body='message 1'",
            {'time': time_1})
        await db.sql(
            "UPDATE messages SET created_at=%(time)s WHERE body='message 2'",
            {'time': time_2})
        await db.sql(
            "UPDATE messages SET created_at=%(time)s WHERE body='message 3'",
            {'time': time_3})

        return time_2
Пример #5
0
    async def test_hide(self):
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=1, recipients_ids=[2, 3],
                body='message 1').SerializeToString())
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=2, recipients_ids=[3],
                body='message 2').SerializeToString())
        request = await self.client.post(
            '/send-message',
            data=personal_messages_pb2.SendMessageRequest(
                sender_id=3, recipients_ids=[2, 1],
                body='message 3').SerializeToString())

        request = await self.client.post(
            '/hide-conversation',
            data=personal_messages_pb2.HideConversationRequest(
                account_id=1, partner_id=3).SerializeToString())
        await self.check_answer(request,
                                personal_messages_pb2.HideConversationResponse)

        result = await db.sql(
            'SELECT v.account as account, m.body as body, v.visible as visible FROM visibilities AS v JOIN messages AS m ON v.message=m.id'
        )

        self.assertCountEqual([dict(row) for row in result], [
            {
                'account': 1,
                'body': 'message 1',
                'visible': False
            },
            {
                'account': 2,
                'body': 'message 1',
                'visible': True
            },
            {
                'account': 3,
                'body': 'message 1',
                'visible': True
            },
            {
                'account': 2,
                'body': 'message 2',
                'visible': True
            },
            {
                'account': 3,
                'body': 'message 2',
                'visible': True
            },
            {
                'account': 1,
                'body': 'message 3',
                'visible': False
            },
            {
                'account': 2,
                'body': 'message 3',
                'visible': True
            },
            {
                'account': 3,
                'body': 'message 3',
                'visible': True
            },
        ])
Пример #6
0
def get_message(account_id, message_id):
    data = personal_messages_pb2.GetMessageRequest(account_id=account_id, message_id=message_id)

    answer = tt_api.sync_request(url=conf.settings.TT_GET_MESSAGE_URL,
                                 data=data,
                                 AnswerType=personal_messages_pb2.GetMessageResponse)

    if answer.HasField('message'):
        return answer.message

    return None


def send_message(sender_id, recipients_ids, body, async=False):
    data = personal_messages_pb2.SendMessageRequest(sender_id=sender_id,
                                                    recipients_ids=recipients_ids,
                                                    body=body)

    if async and not project_settings.TESTS_RUNNING:
        tt_api.async_request(url=conf.settings.TT_SEND_MESSAGE_URL,
                             data=data,
                             AnswerType=personal_messages_pb2.SendMessageResponse,
                             callback=lambda answer: logic.notify_post_service(answer=answer, recipients_ids=recipients_ids))
    else:
        answer = tt_api.sync_request(url=conf.settings.TT_SEND_MESSAGE_URL,
                                     data=data,
                                     AnswerType=personal_messages_pb2.SendMessageResponse)
        logic.notify_post_service(answer, recipients_ids)
        return answer.message_id