Merge "remove failing influx testcases"
[yardstick.git] / tests / unit / api / utils / test_influx.py
1 ##############################################################################
2 # Copyright (c) 2016 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 from __future__ import absolute_import
10 import unittest
11 import mock
12
13 from api.utils import influx
14
15 import six.moves.configparser as ConfigParser
16
17
18 class GetDataDbClientTestCase(unittest.TestCase):
19
20     @mock.patch('api.utils.influx.ConfigParser')
21     def test_get_data_db_client_dispatcher_not_influxdb(self, mock_parser):
22         mock_parser.ConfigParser().get.return_value = 'file'
23         # reset exception to avoid
24         # TypeError: catching classes that do not inherit from BaseException
25         mock_parser.NoOptionError = ConfigParser.NoOptionError
26         try:
27             influx.get_data_db_client()
28         except Exception as e:
29             self.assertIsInstance(e, RuntimeError)
30
31
32 class GetIpTestCase(unittest.TestCase):
33
34     def test_get_url(self):
35         url = 'http://localhost:8086/hello'
36         output = influx._get_ip(url)
37
38         result = 'localhost'
39         self.assertEqual(result, output)
40
41
42 class QueryTestCase(unittest.TestCase):
43
44     @mock.patch('api.utils.influx.ConfigParser')
45     def test_query_dispatcher_not_influxdb(self, mock_parser):
46         mock_parser.ConfigParser().get.return_value = 'file'
47         # reset exception to avoid
48         # TypeError: catching classes that do not inherit from BaseException
49         mock_parser.NoOptionError = ConfigParser.NoOptionError
50         try:
51             sql = 'select * form tasklist'
52             influx.query(sql)
53         except Exception as e:
54             self.assertIsInstance(e, RuntimeError)
55
56
57 def main():
58     unittest.main()
59
60
61 if __name__ == '__main__':
62     main()