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()
 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()
 def test_matrix_nio_person_empty_acls(self):
     person_id = "12345"
     full_name = "Charles de Gaulle"
     emails = []
     person1 = matrix_nio.MatrixNioPerson(person_id,
                                          client=self.client,
                                          full_name=full_name,
                                          emails=emails)
     self.assertEqual(person1.aclattr, "")
 def test_matrix_nio_backend_prefix_groupchat_reply(self):
     backend = matrix_nio.MatrixNioBackend(self.bot_config)
     backend.client = nio.AsyncClient("test.matrix.org",
                                      user="******",
                                      device_id="test_device")
     full_name = "Charles de Gaulle"
     person = matrix_nio.MatrixNioPerson("an_id", backend.client, full_name,
                                         ["*****@*****.**"])
     message = Message("A message")
     message_body = f"@{person.fullname} {message.body}"
     backend.prefix_groupchat_reply(message, person)
     self.assertEqual(message.body, message_body)
 def test_matrix_nio_backend_is_not_from_self(self):
     backend = matrix_nio.MatrixNioBackend(self.bot_config)
     test_user_id = "test_user"
     backend.client = nio.AsyncClient("test.matrix.org",
                                      user=test_user_id,
                                      device_id="test_device")
     message_text = "Test message"
     response_text = "A response"
     test_message = Message(
         message_text,
         matrix_nio.MatrixNioPerson("another_test_user_id",
                                    client=backend.client,
                                    emails=["*****@*****.**"],
                                    full_name=""))
     self.assertFalse(backend.is_from_self(test_message))
 def test_matrix_nio_backend_build_reply(self):
     backend = matrix_nio.MatrixNioBackend(self.bot_config)
     backend.client = nio.AsyncClient("test.matrix.org",
                                      user="******",
                                      device_id="test_device")
     message_text = "Test message"
     response_text = "A response"
     test_message = Message(
         message_text,
         matrix_nio.MatrixNioPerson("an_id",
                                    client=backend.client,
                                    emails=["*****@*****.**"],
                                    full_name=""))
     response = backend.build_reply(test_message, response_text)
     self.assertIsInstance(response, Message)
     self.assertEqual(response.to, test_message.frm)
     self.assertEqual(response.body, f"{message_text}\n{response_text}")
    def __init__(self, method_name):
        super().__init__(method_name)
        self.client = nio.AsyncClient("test.matrix.org",
                                      user="******",
                                      device_id="test_device")
        self.client.rooms = {
            "test_room": "empty_room",
            "other_test_room": "also_empty_room"
        }

        self.person_id = "12345"
        self.full_name = "Charles de Gaulle"
        self.emails = ["*****@*****.**", "*****@*****.**"]
        self.person1 = matrix_nio.MatrixNioPerson(self.person_id,
                                                  client=self.client,
                                                  full_name=self.full_name,
                                                  emails=self.emails)
 def test_matrix_nio_person_inequality(self):
     person2 = matrix_nio.MatrixNioPerson(54321,
                                          client=self.client,
                                          full_name=self.full_name,
                                          emails=self.emails)
     self.assertNotEqual(self.person1, person2)
 def test_matrix_nio_person_equality(self):
     person2 = matrix_nio.MatrixNioPerson(12345,
                                          client=self.client,
                                          full_name="Not Charles de Gaulle",
                                          emails=[])
     self.assertEqual(self.person1, person2)