Acquire NSB specific data from Heat.
[yardstick.git] / tests / unit / benchmark / scenarios / parser / test_parser.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.parser.Parser
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19 from oslo_serialization import jsonutils
20
21 from yardstick.benchmark.scenarios.parser import parser
22
23
24 @mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess')
25 class ParserTestCase(unittest.TestCase):
26
27     def setUp(self):
28         pass
29
30     def test_parser_successful_setup(self, mock_subprocess):
31
32         p = parser.Parser({}, {})
33         mock_subprocess.call().return_value = 0
34         p.setup()
35         self.assertEqual(p.setup_done, True)
36
37     def test_parser_successful(self, mock_subprocess):
38         args = {
39             'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
40                         'toscafile': '/root/yardstick/samples/tosca.yaml'},
41         }
42         p = parser.Parser(args, {})
43         result = {}
44         mock_subprocess.call().return_value = 0
45         sample_output = '{"yangtotosca": "success"}'
46
47         p.run(result)
48         expected_result = jsonutils.loads(sample_output)
49
50     def test_parser_teardown_successful(self, mock_subprocess):
51
52         p = parser.Parser({}, {})
53         mock_subprocess.call().return_value = 0
54         p.teardown()
55         self.assertEqual(p.teardown_done, True)
56
57
58 def main():
59     unittest.main()
60
61 if __name__ == '__main__':
62     main()