Remove main() and __main__ from tests.
[yardstick.git] / yardstick / tests / unit / apiserver / 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 import unittest
10 import mock
11
12 from api.utils import influx
13 from six.moves import configparser as ConfigParser
14
15
16 class GetDataDbClientTestCase(unittest.TestCase):
17
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
24         try:
25             influx.get_data_db_client()
26         except Exception as e:  # pylint: disable=broad-except
27             self.assertIsInstance(e, RuntimeError)
28
29
30 class GetIpTestCase(unittest.TestCase):
31
32     def test_get_url(self):
33         url = 'http://localhost:8086/hello'
34         output = influx._get_ip(url)
35
36         result = 'localhost'
37         self.assertEqual(result, output)
38
39
40 class QueryTestCase(unittest.TestCase):
41
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
48         try:
49             sql = 'select * form tasklist'
50             influx.query(sql)
51         except Exception as e:  # pylint: disable=broad-except
52             self.assertIsInstance(e, RuntimeError)