Move tests: unit/dispatcher
[yardstick.git] / yardstick / 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 import unittest
15 from third_party.influxdb.influxdb_line_protocol import make_lines
16
17
18 class TestLineProtocol(unittest.TestCase):
19
20     def test_make_lines(self):
21         data = {
22             "tags": {
23                 "empty_tag": "",
24                 "none_tag": None,
25                 "integer_tag": 2,
26                 "string_tag": "hello"
27             },
28             "points": [
29                 {
30                     "measurement": "test",
31                     "fields": {
32                         "string_val": "hello!",
33                         "int_val": 1,
34                         "float_val": 1.1,
35                         "none_field": None,
36                         "bool_val": True,
37                     }
38                 }
39             ]
40         }
41
42         self.assertEqual(
43             make_lines(data),
44             'test,integer_tag=2,string_tag=hello '
45             'bool_val=True,float_val=1.1,int_val=1i,string_val="hello!"\n'
46         )
47
48     def test_string_val_newline(self):
49         data = {
50             "points": [
51                 {
52                     "measurement": "m1",
53                     "fields": {
54                         "multi_line": "line1\nline1\nline3"
55                     }
56                 }
57             ]
58         }
59
60         self.assertEqual(
61             make_lines(data),
62             'm1 multi_line="line1\\nline1\\nline3"\n'
63         )