Skip to content

Commit 16c02ec

Browse files
pmenglundxginn8
authored andcommitted
add ping method to the client (influxdata#409)
* add ping method to the client * capitalize and pep257 compliance * one more try for pep257 compliance for the ping function * Update client.py * Update client_test.py fixing up failing CI tests * Update client_test.py fixing up failing CI tests
1 parent 2b95797 commit 16c02ec

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

influxdb/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,19 @@ def write_points(self,
457457
retention_policy=retention_policy,
458458
tags=tags, protocol=protocol)
459459

460+
def ping(self):
461+
"""Check connectivity to InfluxDB.
462+
463+
:returns: The version of the InfluxDB the client is connected to
464+
"""
465+
response = self.request(
466+
url="ping",
467+
method='GET',
468+
expected_response_code=204
469+
)
470+
471+
return response.headers['X-Influxdb-Version']
472+
460473
@staticmethod
461474
def _batches(iterable, size):
462475
for i in xrange(0, len(iterable), size):

influxdb/tests/client_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,18 @@ def test_query_fail(self):
418418
with _mocked_session(self.cli, 'get', 401):
419419
self.cli.query('select column_one from foo;')
420420

421+
def test_ping(self):
422+
"""Test ping querying InfluxDB version."""
423+
with requests_mock.Mocker() as m:
424+
m.register_uri(
425+
requests_mock.GET,
426+
"http://localhost:8086/ping",
427+
status_code=204,
428+
headers={'X-Influxdb-Version': '1.2.3'}
429+
)
430+
version = self.cli.ping()
431+
self.assertEqual(version, '1.2.3')
432+
421433
def test_create_database(self):
422434
"""Test create database for TestInfluxDBClient object."""
423435
with requests_mock.Mocker() as m:

0 commit comments

Comments
 (0)