1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
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 ##############################################################################
15 from oslo_serialization import jsonutils
17 from yardstick.benchmark.scenarios.parser import parser
20 class ParserTestCase(unittest.TestCase):
24 'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
25 'toscafile': '/root/yardstick/samples/tosca.yaml'},
27 self.scenario = parser.Parser(scenario_cfg=args, context_cfg={})
29 self._mock_popen = mock.patch.object(subprocess, 'Popen')
30 self.mock_popen = self._mock_popen.start()
31 self._mock_call = mock.patch.object(subprocess, 'call')
32 self.mock_call = self._mock_call.start()
34 self.addCleanup(self._stop_mock)
37 self._mock_popen.stop()
38 self._mock_call.stop()
40 def test_setup_successful(self):
42 self.mock_call.return_value = 0
44 self.assertTrue(self.scenario.setup_done)
46 def test_run_successful(self):
50 self.mock_popen().returncode = 0
52 expected_result = jsonutils.loads('{"yangtotosca": "success"}')
54 self.scenario.run(result)
55 self.assertEqual(result, expected_result)
57 def test_run_fail(self):
60 self.mock_popen().returncode = 1
61 expected_result = jsonutils.loads('{"yangtotosca": "fail"}')
63 self.scenario.run(result)
64 self.assertEqual(result, expected_result)
66 def test_teardown_successful(self):
68 self.mock_call.return_value = 0
69 self.scenario.teardown()
70 self.assertTrue(self.scenario.teardown_done)