예제 #1
0
async def test_list_participants_with_results_per_page():
    thread_id = "19:[email protected]"
    participant_id_1 = "8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-5399-552c-b274-5a3a0d0000dc"
    participant_id_2 = "8:acs:9b665d53-8164-4923-ad5d-5e983b07d2e7_00000006-9d32-35c9-557d-5a3a0d0002f1"
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200, json_payload={
                "value": [
                    {"id": participant_id_1},
                    {"id": participant_id_2}
                ]})
    chat_thread_client = ChatThreadClient("https://endpoint", credential, thread_id, transport=Mock(send=mock_send))

    chat_thread_participants = None
    try:
        chat_thread_participants = chat_thread_client.list_participants(results_per_page=2)
    except:
        raised = True

    assert raised == False

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

    assert len(items) == 2
async def test_list_participants():
    thread_id = "19:[email protected]"
    participant_id="8:acs:57b9bac9-df6c-4d39-a73b-26e944adf6ea_9b0110-08007f1041"
    raised = False

    async def mock_send(*_, **__):
        return mock_response(status_code=200, json_payload={"value": [
            {
                "communicationIdentifier": {
                    "rawId": participant_id,
                    "communicationUser": {
                        "id": participant_id
                    }
                },
                "displayName": "Bob",
                "shareHistoryTime": "2020-10-30T10:50:50Z"
            }
        ]})
    chat_thread_client = ChatThreadClient("https://endpoint", credential, thread_id, transport=Mock(send=mock_send))

    chat_thread_participants = None
    try:
        chat_thread_participants = chat_thread_client.list_participants()
    except:
        raised = True

    assert raised == False

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

    assert len(items) == 1
예제 #3
0
    async def list_participants_async(self):
        from azure.communication.chat.aio import ChatThreadClient, CommunicationTokenCredential, CommunicationTokenRefreshOptions
        refresh_options = CommunicationTokenRefreshOptions(self.token)
        chat_thread_client = ChatThreadClient(
            self.endpoint, CommunicationTokenCredential(refresh_options),
            self._thread_id)

        async with chat_thread_client:
            # [START list_participants]
            chat_thread_participants = chat_thread_client.list_participants()
            print("list_participants succeeded, participants:")
            async for chat_thread_participant in chat_thread_participants:
                print(chat_thread_participant)