Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_query(self):
from influxdb.resultset import ResultSet
databases = query('show databases')
self.assertEqual(type(databases), ResultSet)
databases = [database['name'] for database in list(databases.get_points())]
self.assertIn(TEST_DATABASE, databases)
response = self.request(
url="query",
method=method,
params=params,
data=None,
expected_response_code=expected_response_code
)
data = response._msgpack
if not data:
if chunked:
return self._read_chunked_response(response)
data = response.json()
results = [
ResultSet(result, raise_errors=raise_errors)
for result
in data.get('results', [])
]
# TODO(aviau): Always return a list. (This would be a breaking change)
if len(results) == 1:
return results[0]
return results
def _read_chunked_response(response, raise_errors=True):
result_set = {}
for line in response.iter_lines():
if isinstance(line, bytes):
line = line.decode('utf-8')
data = json.loads(line)
for result in data.get('results', []):
for _key in result:
if isinstance(result[_key], list):
result_set.setdefault(
_key, []).extend(result[_key])
return ResultSet(result_set, raise_errors=raise_errors)