def test_list_messages(self): thread_id = "19:[email protected]" message_id = '1596823919339' raised = False def mock_send(*_, **__): return mock_response(status_code=200, json_payload={"value": [{ "id": message_id }]}) chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.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 self.assertFalse(raised, 'Expected is no excpetion raised') for chat_message in chat_messages.by_page(): l = list(chat_message) assert len(l) == 1 assert l[0].id == message_id
def test_list_messages(self): thread_id = "19:[email protected]" message_id='1596823919339' raised = False def mock_send(*_, **__): return mock_response(status_code=200, json_payload={"value": [{ "id": message_id, "type": "text", "sequenceId": "3", "version": message_id, "content": { "message": "Hi I am Bob." }, "senderDisplayName": "Bob", "createdOn": "2021-01-27T01:37:33Z", "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b" }]}) chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.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 self.assertFalse(raised, 'Expected is no excpetion raised') for chat_message in chat_messages.by_page(): l = list(chat_message) assert len(l) == 1 assert l[0].id == message_id
def test_list_messages_with_start_time(self): thread_id = "19:[email protected]" raised = False message_id = '1596823919339' def mock_send(*_, **__): return mock_response(status_code=200, json_payload={ "value": [ { "id": message_id, "type": "text", "sequenceId": "3", "version": message_id, "content": { "message": "Hi I am Bob." }, "senderDisplayName": "Bob", "createdOn": "2021-01-27T01:37:33Z", "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b" }, { "id": message_id, "type": "text", "sequenceId": "3", "version": message_id, "content": { "message": "Come one guys, lets go for lunch together.", "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": "2021-01-27T01:37:33Z", "senderId": "8:acs:46849534-eb08-4ab7-bde7-c36928cd1547_00000007-e155-1f06-1db7-3a3a0d00004b" } ]}) chat_thread_client = ChatThreadClient("https://endpoint", TestChatThreadClient.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 self.assertFalse(raised, 'Expected is no excpetion raised') for chat_message in chat_messages.by_page(): l = list(chat_message) assert len(l) == 2
def list_messages(self): from azure.communication.chat import ChatThreadClient from azure.communication.chat import CommunicationTokenCredential, CommunicationTokenRefreshOptions refresh_options = CommunicationTokenRefreshOptions(self.token) chat_thread_client = ChatThreadClient(self.endpoint, CommunicationTokenCredential(refresh_options), self._thread_id) # [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") for chat_message_page in chat_messages.by_page(): l = list(chat_message_page) print("page size: ", len(l))
def test_list_messages_with_start_time(self): thread_id = "19:[email protected]" raised = False 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", TestChatThreadClient.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 self.assertFalse(raised, 'Expected is no excpetion raised') for chat_message in chat_messages.by_page(): l = list(chat_message) assert len(l) == 2
def test_list_messages(self): thread_id = "19:[email protected]" message_id = '1596823919339' message_str = "Hi I am Bob." raised = False 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", TestChatThreadClient.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 self.assertFalse(raised, 'Expected is no excpetion raised') for chat_message in chat_messages.by_page(): l = list(chat_message) assert len(l) == 1 assert l[0].id == message_id