Update missing license headers
[yardstick.git] / tests / unit / dispatcher / test_influxdb_line_protocol.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 # Unittest for yardstick.dispatcher.influxdb_line_protocol
10
11 # yardstick comment: this file is a modified copy of
12 # influxdb-python/influxdb/tests/test_line_protocol.py
13
14 from __future__ import absolute_import
15 import unittest
16 from third_party.influxdb.influxdb_line_protocol import make_lines
17
18
19 class TestLineProtocol(unittest.TestCase):
20
21     def test_make_lines(self):
22         data = {
23             "tags": {
24                 "empty_tag": "",
25                 "none_tag": None,
26                 "integer_tag": 2,
27                 "string_tag": "hello"
28             },
29             "points": [
30                 {
31                     "measurement": "test",
32                     "fields": {
33                         "string_val": "hello!",
34                         "int_val": 1,
35                         "float_val": 1.1,
36                         "none_field": None,
37                         "bool_val": True,
38                     }
39                 }
40             ]
41         }
42
43         self.assertEqual(
44             make_lines(data),
45             'test,integer_tag=2,string_tag=hello '
46             'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
47         )
48
49     def test_string_val_newline(self):
50         data = {
51             "points": [
52                 {
53                     "measurement": "m1",
54                     "fields": {
55                         "multi_line": "line1\nline1\nline3"
56                     }
57                 }
58             ]
59         }
60
61         self.assertEqual(
62             make_lines(data),
63             'm1 multi_line="line1\\nline1\\nline3"\n'
64         )