3 ##############################################################################
4 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
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 ##############################################################################
17 from oslo_serialization import jsonutils
19 from yardstick.benchmark.scenarios.parser import parser
22 class ParserTestCase(unittest.TestCase):
26 'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
27 'toscafile': '/root/yardstick/samples/tosca.yaml'},
29 self.scenario = parser.Parser(scenario_cfg=args, context_cfg={})
31 self._mock_popen = mock.patch.object(subprocess, 'Popen')
32 self.mock_popen = self._mock_popen.start()
33 self._mock_call = mock.patch.object(subprocess, 'call')
34 self.mock_call = self._mock_call.start()
36 self.addCleanup(self._stop_mock)
39 self._mock_popen.stop()
40 self._mock_call.stop()
42 def test_setup_successful(self):
44 self.mock_call.return_value = 0
46 self.assertTrue(self.scenario.setup_done)
48 def test_run_successful(self):
52 self.mock_popen().returncode = 0
54 expected_result = jsonutils.loads('{"yangtotosca": "success"}')
56 self.scenario.run(result)
57 self.assertEqual(result, expected_result)
59 def test_run_fail(self):
62 self.mock_popen().returncode = 1
63 expected_result = jsonutils.loads('{"yangtotosca": "fail"}')
65 self.scenario.run(result)
66 self.assertEqual(result, expected_result)
68 def test_teardown_successful(self):
70 self.mock_call.return_value = 0
71 self.scenario.teardown()
72 self.assertTrue(self.scenario.teardown_done)
78 if __name__ == '__main__':