'Test that a random number of connection errors will be handled.'

@mock.patch(u'requests.Session.request')
def test_random_request_retry(self, mock_request):

    class CustomMock(object, ):
        u'Create    custom    mock    object    for    test.'
        def __init__(self, retries):
            self.i = 0
            self.retries = retries
        def connection_error(self, *args, **kwargs):
            u'Handle    a    connection    error    for    the    CustomMock    object.'
            self.i += 1
            if (self.i < self.retries):
                raise requests.exceptions.ConnectionError
            else:
                r = requests.Response()
                r.status_code = 204
                return r
    retries = random.randint(1, 100)
    mock_request.side_effect = CustomMock(retries).connection_error
    cli = InfluxDBClient(database=u'db', retries=retries)
    cli.write_points(self.dummy_points)
