def test_send_text_message_to_channel_calls_ts3exec(self):
        ts3_connection_mock = MagicMock()
        repo = TS3Facade(ts3_connection_mock)

        repo.send_text_message_to_current_channel("test")

        ts3_connection_mock.ts3exec.assert_called_once(
        )  # TODO: we can not check for the parameters because it is a lambda
    def test_find_channel_calls_ts3exec_other_exception_raised(self):
        ts3_connection_mock = MagicMock()
        any_exception = RuntimeError("Something else went wrong")
        ts3_connection_mock.ts3exec = MagicMock(
            return_value=[None, any_exception])

        repo = TS3Facade(ts3_connection_mock)

        with self.assertRaises(RuntimeError):
            repo.channel_find_first("test123")
        ts3_connection_mock.ts3exec.assert_called_once(
        )  # TODO: we can not check for the parameters because it is a lambda
    def test_find_channel_calls_ts3exec_other_error_reraised(self):
        query_error = TS3QueryError(PropertyMock())
        query_error.resp.error = {"id": '42'}

        ts3_connection_mock = MagicMock()
        ts3_connection_mock.ts3exec = MagicMock(
            return_value=[None, query_error])

        repo = TS3Facade(ts3_connection_mock)

        with self.assertRaises(TS3QueryError):
            repo.channel_find_first("test123")

        ts3_connection_mock.ts3exec.assert_called_once(
        )  # TODO: we can not check for the parameters because it is a lambda
예제 #4
0
def create_connection_pool(config):
    def _test_connection(obj: TS3Facade):
        if not obj.is_healthy():
            return False
        whoami_response = obj.whoami()
        return whoami_response['virtualserver_id'] == config.server_id

    return ConnectionPool(create=lambda: TS3Facade(
        create_connection(config, config.bot_nickname)),
                          destroy_function=lambda obj: obj.close(),
                          test_function=_test_connection,
                          max_size=config.pool_size,
                          max_usage=config.pool_max_usage,
                          idle=config.pool_tti,
                          ttl=config.pool_ttl)
    def test_find_channel_calls_ts3exec_noresult_returns_none(self):
        query_error = MagicMock()
        query_error.resp = PropertyMock()
        query_error.resp.error = {"id": '768'}

        ts3_connection_mock = MagicMock()
        ts3_connection_mock.ts3exec = MagicMock(
            return_value=[None, query_error])

        repo = TS3Facade(ts3_connection_mock)

        result = repo.channel_find_first("test123")

        ts3_connection_mock.ts3exec.assert_called_once(
        )  # TODO: we can not check for the parameters because it is a lambda
        self.assertIsNone(result)
    def test_find_channel_calls_ts3exec(self):
        ts3_connection_mock = MagicMock()
        ts3_connection_mock.ts3exec = MagicMock(
            return_value=[{
                "cid": "42",
                "channel_name": "I am channel test123 !"
            }, None])

        repo = TS3Facade(ts3_connection_mock)

        result = repo.channel_find_first("test123")

        ts3_connection_mock.ts3exec.assert_called_once(
        )  # TODO: we can not check for the parameters because it is a lambda
        self.assertEqual(result.channel_id, "42")
        self.assertEqual(result.channel_name, "I am channel test123 !")
예제 #7
0
 def _test_connection(obj: TS3Facade):
     if not obj.is_healthy():
         return False
     whoami_response = obj.whoami()
     return whoami_response['virtualserver_id'] == config.server_id