aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolodymyr Mytnyk <volodymyrx.mytnyk@intel.com>2019-01-24 10:11:23 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-01-24 10:11:23 +0000
commite097cbcff4b911c91a87fee5e9218f79b8d0eeef (patch)
treedb40328dcf05895269b71072d130973d412a09ae
parent347c2d26ca095ec8d3c7e189bbf1ded7e0a1a8e8 (diff)
parent285a0026d13173fb3bca4c74562874cb10641384 (diff)
Merge "Add functional tests for HTML report"
-rw-r--r--yardstick/tests/functional/benchmark/core/__init__.py0
-rw-r--r--yardstick/tests/functional/benchmark/core/test_report.py100
2 files changed, 100 insertions, 0 deletions
diff --git a/yardstick/tests/functional/benchmark/core/__init__.py b/yardstick/tests/functional/benchmark/core/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/core/__init__.py
diff --git a/yardstick/tests/functional/benchmark/core/test_report.py b/yardstick/tests/functional/benchmark/core/test_report.py
new file mode 100644
index 000000000..401b97da9
--- /dev/null
+++ b/yardstick/tests/functional/benchmark/core/test_report.py
@@ -0,0 +1,100 @@
+##############################################################################
+# Copyright (c) 2018 Intel Corporation.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import ast
+import tempfile
+import unittest
+
+import mock
+from six.moves import configparser
+
+from yardstick.benchmark import core
+from yardstick.benchmark.core import report
+from yardstick.cmd.commands import change_osloobj_to_paras
+
+
+GOOD_YAML_NAME = 'fake_name'
+GOOD_TASK_ID = "9cbe74b6-df09-4535-8bdc-dc3a43b8a4e2"
+GOOD_DB_FIELDKEYS = [
+ {u'fieldKey': u'metric1', u'fieldType': u'integer'},
+ {u'fieldKey': u'metric2', u'fieldType': u'integer'},
+ {u'fieldKey': u'metric3', u'fieldType': u'integer'},
+ {u'fieldKey': u'metric4', u'fieldType': u'integer'},
+]
+GOOD_DB_METRICS = [
+ {u'time': u'2018-08-20T16:49:26.372662016Z',
+ u'metric1': 1, u'metric2': 0, u'metric3': 8, u'metric4': 5},
+ {u'time': u'2018-08-20T16:49:27.374208000Z',
+ u'metric1': 1, u'metric2': 1, u'metric3': 5, u'metric4': 4},
+ {u'time': u'2018-08-20T16:49:28.375742976Z',
+ u'metric1': 2, u'metric2': 2, u'metric3': 3, u'metric4': 3},
+ {u'time': u'2018-08-20T16:49:29.377299968Z',
+ u'metric1': 3, u'metric2': 3, u'metric3': 2, u'metric4': 2},
+ {u'time': u'2018-08-20T16:49:30.378252032Z',
+ u'metric1': 5, u'metric2': 4, u'metric3': 1, u'metric4': 1},
+ {u'time': u'2018-08-20T16:49:30.379359421Z',
+ u'metric1': 8, u'metric2': 5, u'metric3': 1, u'metric4': 0},
+]
+
+yardstick_config = """
+[DEFAULT]
+dispatcher = influxdb
+"""
+
+
+def my_query(query_sql):
+ get_fieldkeys_cmd = 'show field keys'
+ get_metrics_cmd = 'select * from'
+
+ if get_fieldkeys_cmd in query_sql:
+ return GOOD_DB_FIELDKEYS
+ elif get_metrics_cmd in query_sql:
+ return GOOD_DB_METRICS
+ return []
+
+
+class ReportTestCase(unittest.TestCase):
+
+ @mock.patch.object(report.influx, 'query', new=my_query)
+ @mock.patch.object(configparser.ConfigParser,
+ 'read', side_effect=mock.mock_open(read_data=yardstick_config))
+ def test_report_generate_nsb_simple(self, *args):
+ tmpfile = tempfile.NamedTemporaryFile(delete=True)
+
+ args = core.Param({"task_id": [GOOD_TASK_ID], "yaml_name": [GOOD_YAML_NAME]})
+ params = change_osloobj_to_paras(args)
+
+ with mock.patch.object(report.consts, 'DEFAULT_HTML_FILE', tmpfile.name):
+ report.Report().generate_nsb(params)
+
+ with open(tmpfile.name) as f:
+ for l in f.readlines():
+ if " arr = {" in l:
+ arr_act = ast.literal_eval(l.strip()[6:-1])
+ elif " jstree_data = [" in l:
+ jstree_data_act = ast.literal_eval(l.strip()[14:-1])
+
+ arr_exp = {
+ 'Timestamp':
+ ['16:49:26.372662', '16:49:27.374208', '16:49:28.375742',
+ '16:49:29.377299', '16:49:30.378252', '16:49:30.379359'],
+ 'metric1': [1, 1, 2, 3, 5, 8],
+ 'metric2': [0, 1, 2, 3, 4, 5],
+ 'metric3': [8, 5, 3, 2, 1, 1],
+ 'metric4': [5, 4, 3, 2, 1, 0],
+ }
+ jstree_data_exp = [
+ {'parent': '#', 'text': 'metric1', 'id': 'metric1'},
+ {'parent': '#', 'text': 'metric2', 'id': 'metric2'},
+ {'parent': '#', 'text': 'metric3', 'id': 'metric3'},
+ {'parent': '#', 'text': 'metric4', 'id': 'metric4'},
+ ]
+
+ self.assertEqual(arr_exp, arr_act)
+ self.assertEqual(jstree_data_exp, jstree_data_act)