Exemple #1
0
    def test_status_functions(self):
        topic_d = STATUS_TOPIC
        data = generate_test_data()

        self.assertIsNone(functions.get('status')(data, 'number'))

        with open(
                path.join(path.dirname(__file__),
                          'status_functions_testdata.yaml')) as f:
            tests = yaml.safe_load(f)['tests']

        for kwargs, status in tests:
            result = functions.get('status')(data, 'number', **kwargs)
            self.assertEqual(result.get('payload').get('status'),
                             status,
                             msg=str(kwargs))

            topic_d['data_tools'] = [
                dict(field='number', method='status', **kwargs)
            ]
            results, warnings = run_data_tools(topic_d, data)
            validate_statistics_array(results)
            self.assertEqual(len(results), 1)
            self.assertEqual(results[0].get('payload').get('status'),
                             status,
                             msg=str(kwargs))
            self.assertEqual(len(warnings), 0)
Exemple #2
0
    def test_collection_functions_unit(self):
        topic_d = STATUS_TOPIC
        data = generate_test_data()

        topic_d['data_tools'] = [
            dict(field='number', method="average"),
            dict(field='number',
                 method='list_item',
                 parameters=dict(name="test_list", method="average")),
            dict(field='number',
                 method='table_item',
                 parameters=dict(name="test_table", method="average")),
        ]

        results, warnings = run_data_tools(topic_d, data)
        self.assertEqual(len(warnings), 0)

        results, warnings = post_process(results)
        self.assertEqual(len(warnings), 0)
        validate_statistics_array(results)

        self.assertEqual(len(results), 3)

        value = next(i for i in results if i["type"] == "value")
        self.assertEqual(value["payload"]["unit"], "scalar")
        list_ = next(i for i in results if i["type"] == "list")
        self.assertEqual(list_["payload"]["data"][0]["payload"]["unit"],
                         "scalar")
        table = next(i for i in results if i["type"] == "table")
        self.assertEqual(
            table["payload"]["data"][0]["data"][0]["payload"]["unit"],
            "scalar")
Exemple #3
0
    def test_get_overview_produces_overview(self):
        data_tools = [{"field": "number", "method": "latest"}]
        result = self._test_run_data_tools_for_many('get_overview', data_tools)
        statistics = result["statistics"]

        validate_statistics_array(statistics)
        self.assertEqual(len(statistics), 3)
Exemple #4
0
    def test_get_comparison_produces_comparison(self):
        data_tools = [{
            "field": "number",
            "method": "doughnut",
            "metadata": dict(asd=123)
        }]
        result = self._test_run_data_tools_for_many('get_comparison',
                                                    data_tools)
        statistics = result["statistics"]

        validate_statistics_array(statistics)
        self.assertEqual(len(statistics), 1)
        self.assertEqual(statistics[0]["metadata"]["asd"], 123)
Exemple #5
0
    def test_get_overview_combines_table_items_to_table(self):
        data_tools = [{
            "field": "number",
            "method": "table_item",
            "parameters": {
                "name": "asd"
            },
            "metadata": dict(qwe=456)
        }]
        result = self._test_run_data_tools_for_many('get_overview', data_tools)
        statistics = result["statistics"]

        validate_statistics_array(statistics)
        self.assertEqual(len(statistics), 1)

        table_data = statistics[0].get("payload").get("data")
        table_meta = statistics[0].get("metadata")
        self.assertEqual(len(table_data), 3)
        self.assertEqual(table_meta, {"qwe": 456})