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 ##############################################################################
12 from api.utils import influx
13 from six.moves import configparser as ConfigParser
16 class GetDataDbClientTestCase(unittest.TestCase):
18 @mock.patch('api.utils.influx.ConfigParser')
19 def test_get_data_db_client_dispatcher_not_influxdb(self, mock_parser):
20 mock_parser.ConfigParser().get.return_value = 'file'
21 # reset exception to avoid
22 # TypeError: catching classes that do not inherit from BaseException
23 mock_parser.NoOptionError = ConfigParser.NoOptionError
25 influx.get_data_db_client()
26 except Exception as e: # pylint: disable=broad-except
27 self.assertIsInstance(e, RuntimeError)
30 class GetIpTestCase(unittest.TestCase):
32 def test_get_url(self):
33 url = 'http://localhost:8086/hello'
34 output = influx._get_ip(url)
37 self.assertEqual(result, output)
40 class QueryTestCase(unittest.TestCase):
42 @mock.patch('api.utils.influx.ConfigParser')
43 def test_query_dispatcher_not_influxdb(self, mock_parser):
44 mock_parser.ConfigParser().get.return_value = 'file'
45 # reset exception to avoid
46 # TypeError: catching classes that do not inherit from BaseException
47 mock_parser.NoOptionError = ConfigParser.NoOptionError
49 sql = 'select * form tasklist'
51 except Exception as e: # pylint: disable=broad-except
52 self.assertIsInstance(e, RuntimeError)
59 if __name__ == '__main__':