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 ##############################################################################
14 from api.utils import influx
17 class GetDataDbClientTestCase(unittest.TestCase):
19 @mock.patch('api.utils.influx.ConfigParser')
20 def test_get_data_db_client_dispatcher_not_influxdb(self, mock_parser):
21 mock_parser.ConfigParser().get.return_value = 'file'
23 influx.get_data_db_client()
24 except Exception as e:
25 self.assertIsInstance(e, RuntimeError)
28 class GetIpTestCase(unittest.TestCase):
30 def test_get_url(self):
31 url = 'http://localhost:8086/hello'
32 output = influx._get_ip(url)
35 self.assertEqual(result, output)
38 class WriteDataTestCase(unittest.TestCase):
40 @mock.patch('api.utils.influx.get_data_db_client')
41 def test_write_data(self, mock_get_client):
42 measurement = 'tasklist'
44 timestamp = datetime.datetime.now()
45 tags = {'task_id': str(uuid.uuid4())}
47 influx._write_data(measurement, field, timestamp, tags)
48 mock_get_client.assert_called_with()
51 class WriteDataTasklistTestCase(unittest.TestCase):
53 @mock.patch('api.utils.influx._write_data')
54 def test_write_data_tasklist(self, mock_write_data):
55 task_id = str(uuid.uuid4())
56 timestamp = datetime.datetime.now()
58 influx.write_data_tasklist(task_id, timestamp, status)
60 field = {'status': status, 'error': ''}
61 tags = {'task_id': task_id}
62 mock_write_data.assert_called_with('tasklist', field, timestamp, tags)
65 class QueryTestCase(unittest.TestCase):
67 @mock.patch('api.utils.influx.ConfigParser')
68 def test_query_dispatcher_not_influxdb(self, mock_parser):
69 mock_parser.ConfigParser().get.return_value = 'file'
71 sql = 'select * form tasklist'
73 except Exception as e:
74 self.assertIsInstance(e, RuntimeError)
81 if __name__ == '__main__':