async def test_list_messages_with_start_time():
    thread_id = "19:[email protected]"
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200,
                             json_payload={
                                 "value": [{
                                     "id": "message_id1",
                                     "createdOn": "2020-08-17T18:05:44Z"
                                 }, {
                                     "id": "message_id2",
                                     "createdOn": "2020-08-17T23:13:33Z"
                                 }]
                             })

    chat_thread_client = ChatThreadClient("https://endpoint",
                                          credential,
                                          thread_id,
                                          transport=Mock(send=mock_send))

    chat_messages = None
    try:
        chat_messages = chat_thread_client.list_messages(
            start_time=datetime(2020, 8, 17, 18, 0, 0))
    except:
        raised = True

    assert raised == False

    items = []
    async for item in chat_messages:
        items.append(item)

    assert len(items) == 2
async def test_list_messages():
    thread_id = "19:[email protected]"
    message_id = '1596823919339'
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200,
                             json_payload={"value": [{
                                 "id": message_id
                             }]})

    chat_thread_client = ChatThreadClient("https://endpoint",
                                          credential,
                                          thread_id,
                                          transport=Mock(send=mock_send))

    chat_messages = None
    try:
        chat_messages = chat_thread_client.list_messages(results_per_page=1)
    except:
        raised = True

    assert raised == False

    items = []
    async for item in chat_messages:
        items.append(item)

    assert len(items) == 1
    assert items[0].id == message_id
    async def list_messages_async(self):
        from azure.communication.chat.aio import ChatThreadClient, CommunicationUserCredential
        chat_thread_client = ChatThreadClient(self.endpoint, CommunicationUserCredential(self.token), self._thread_id)

        async with chat_thread_client:
            # [START list_messages]
            from datetime import datetime, timedelta
            start_time = datetime.utcnow() - timedelta(days=1)
            chat_messages = chat_thread_client.list_messages(results_per_page=1, start_time=start_time)
            print("list_messages succeeded with results_per_page is 1, and start time is yesterday UTC")
            async for chat_message_page in chat_messages.by_page():
                l = [ i async for i in chat_message_page]
                print("page size: ", len(l))
async def test_list_messages():
    thread_id = "19:[email protected]"
    message_id='1596823919339'
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200, json_payload={"value": [{
                        "id": message_id,
                        "type": "text",
                        "sequenceId": "3",
                        "version": message_id,
                        "content": {
                            "message": "message_str",
                            "topic": "Lunch Chat thread",
                            "participants": [
                                {
                                    "communicationIdentifier": {"rawId": "string", "communicationUser": {
                            "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"}},
                                    "displayName": "Bob",
                                    "shareHistoryTime": "2020-10-30T10:50:50Z"
                                }
                            ],
                            "initiatorCommunicationIdentifier": {"rawId": "string", "communicationUser": {
                            "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"}}
                        },
                        "senderDisplayName": "Bob",
                        "createdOn": "2021-01-27T01:37:33Z",
                        "senderCommunicationIdentifier": {"rawId": "string", "communicationUser": {
                            "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"}},
                        "deletedOn": "2021-01-27T01:37:33Z",
                        "editedOn": "2021-01-27T01:37:33Z"
                    }]})
    chat_thread_client = ChatThreadClient("https://endpoint", credential, thread_id, transport=Mock(send=mock_send))

    chat_messages = None
    try:
        chat_messages = chat_thread_client.list_messages(results_per_page=1)
    except:
        raised = True

    assert raised == False

    items = []
    async for item in chat_messages:
        items.append(item)

    assert len(items) == 1
    assert items[0].id == message_id
Example #5
0
async def test_list_messages_with_start_time():
    thread_id = "19:[email protected]"
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200, json_payload={
            "value": [
                {
                    "id": "message_id1",
                    "type": "text",
                    "sequenceId": "3",
                    "version": "message_id1",
                    "content": {
                        "message": "message_str",
                        "topic": "Lunch Chat thread",
                        "participants": [
                            {
                                "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b",
                                "displayName": "Bob",
                                "shareHistoryTime": "2020-10-30T10:50:50Z"
                            }
                        ],
                        "initiator": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"
                    },
                    "senderDisplayName": "Bob",
                    "createdOn": "2020-08-17T18:05:44Z",
                    "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b"
                },
                {
                    "id": "message_id2",
                    "type": "text",
                    "sequenceId": "3",
                    "version": "message_id2",
                    "content": {
                        "message": "message_str",
                        "topic": "Lunch Chat thread",
                        "participants": [
                            {
                                "id": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b",
                                "displayName": "Bob",
                                "shareHistoryTime": "2020-10-30T10:50:50Z"
                            }
                        ],
                        "initiator": "8:acs:8540c0de-899f-5cce-acb5-3ec493af3800_0e59221d-0c1d-46ae-9544-c963ce56c10b"
                    },
                    "senderDisplayName": "Bob",
                    "createdOn": "2020-08-17T23:13:33Z",
                    "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b"
                }]})
    chat_thread_client = ChatThreadClient("https://endpoint", credential, thread_id, transport=Mock(send=mock_send))

    chat_messages = None
    try:
        chat_messages = chat_thread_client.list_messages(
            start_time=datetime(2020, 8, 17, 18, 0, 0)
        )
    except:
        raised = True

    assert raised == False

    items = []
    async for item in chat_messages:
        items.append(item)

    assert len(items) == 2