コード例 #1
0
 async def test_matrix_nio_backend_send_message_error(self):
     backend = matrix_nio.MatrixNioBackend(self.bot_config)
     test_server = "test.matrix.org"
     test_user = f"@test_user:{test_server}"
     event_id = "1234567890"
     room_id = "test_room"
     backend.client = nio.AsyncClient(test_server,
                                      user=test_user,
                                      device_id="test_device")
     backend.client.rooms = {
         "test_room": "Test Room",
         "other_test_room": "Test Room"
     }
     backend.client.room_send = mock.Mock(
         return_value=aiounittest.futurized(
             ErrorResponse.from_dict({
                 "errcode": "ERROR_SENDING_MESSAGE",
                 "error": "Error sending message",
                 "retry_after_ms": 10000
             })))
     message_text = "Test message"
     test_message = Message(
         message_text,
         matrix_nio.MatrixNioPerson("an_id",
                                    client=backend.client,
                                    emails=["*****@*****.**"],
                                    full_name=""))
     test_message.to = matrix_nio.MatrixNioRoom("test_room",
                                                client=backend.client,
                                                title="A title")
     test_message.to.room = "test_room"
     with self.assertRaises(ValueError):
         result = await backend._send_message(test_message)
     backend.client.room_send.assert_called_once()
コード例 #2
0
 async def test_matrix_nio_backend_send_message(self):
     backend = matrix_nio.MatrixNioBackend(self.bot_config)
     test_server = "test.matrix.org"
     test_user = f"@test_user:{test_server}"
     event_id = "1234567890"
     room_id = "test_room"
     backend.client = nio.AsyncClient(test_server,
                                      user=test_user,
                                      device_id="test_device")
     backend.client.rooms = {
         "test_room": "Test Room",
         "other_test_room": "Test Room"
     }
     backend.client.room_send = mock.Mock(
         return_value=aiounittest.futurized(
             RoomSendResponse.from_dict({"event_id": event_id}, room_id)))
     message_text = "Test message"
     test_message = Message(
         message_text,
         matrix_nio.MatrixNioPerson("an_id",
                                    client=backend.client,
                                    emails=["*****@*****.**"],
                                    full_name=""))
     test_message.to = matrix_nio.MatrixNioRoom("test_room",
                                                client=backend.client,
                                                title="A title")
     test_message.to.room = "test_room"
     result = await backend._send_message(test_message)
     self.assertIsInstance(result, RoomSendResponse)
     self.assertEqual(result.room_id, room_id)
     self.assertEqual(result.event_id, event_id)
     # TODO: Add assert called once with
     backend.client.room_send.assert_called_once()