1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
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
13 from api.utils import influx
15 import six.moves.configparser as ConfigParser
18 class GetDataDbClientTestCase(unittest.TestCase):
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
27 influx.get_data_db_client()
28 except Exception as e:
29 self.assertIsInstance(e, RuntimeError)
32 class GetIpTestCase(unittest.TestCase):
34 def test_get_url(self):
35 url = 'http://localhost:8086/hello'
36 output = influx._get_ip(url)
39 self.assertEqual(result, output)
42 class QueryTestCase(unittest.TestCase):
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
51 sql = 'select * form tasklist'
53 except Exception as e:
54 self.assertIsInstance(e, RuntimeError)
61 if __name__ == '__main__':