From 881934bc11c7eacd178aa3f75b724761dabfc714 Mon Sep 17 00:00:00 2001 From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk> Date: Tue, 13 Mar 2018 10:15:21 +0000 Subject: [PATCH] Slight refactoring of telegraph agent test --- test/telegraf-agents/test_telegraf_agents.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/telegraf-agents/test_telegraf_agents.py b/test/telegraf-agents/test_telegraf_agents.py index 2f35d01..77b6290 100644 --- a/test/telegraf-agents/test_telegraf_agents.py +++ b/test/telegraf-agents/test_telegraf_agents.py @@ -9,16 +9,23 @@ import pytest ('mongodb', 'SELECT mean("net_in_bytes") AS "mean" FROM "CLMCMetrics"."autogen"."mongodb"', 0) ]) def test_all_inputs(influxdb, measurement, query, expected_result): - """Tests measurements are received from an input plugin aggregated across all services """ + Tests measurements are received from an input plugin aggregated across all services + + :param influxdb: the influx db client fixture + :param measurement: the measurement to test + :param query: the query to execute + :param expected_result: the expected result from the query + """ + query_result = influxdb.query('SHOW measurements ON "CLMCMetrics"') points = list(query_result.get_points()) assert any(p['name'] == measurement for p in points), "{0} not in measurement list".format(measurement) query_result = influxdb.query(query) - points = list(query_result.get_points()) - actual_result = points[0]['mean'] - assert actual_result > expected_result, "actual result {0} is not > expected result {1} for query {2}".format(actual_result, str(expected_result), query) + points = next(query_result.get_points()) # get_points() returns a generator, to take the first element we can use the next() function + actual_result = points['mean'] + assert actual_result > expected_result, "actual result {0} is not > expected result {1} for query {2}".format(actual_result, str(expected_result), query) @pytest.mark.parametrize("ipendpoint, measurements", [ -- GitLab