1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
15 from toscaparser.common import exception
16 import toscaparser.shell as shell
17 from toscaparser.tests.base import TestCase
18 from toscaparser.utils.gettextutils import _
21 class ShellTest(TestCase):
23 tosca_helloworld = os.path.join(
24 os.path.dirname(os.path.abspath(__file__)),
25 "data/tosca_helloworld.yaml")
27 errornous_template = os.path.join(
28 os.path.dirname(os.path.abspath(__file__)),
29 "data/test_multiple_validation_errors.yaml")
31 def test_missing_arg(self):
32 error = self.assertRaises(ValueError, shell.main, '')
33 err_msg = _('The program requires a template or a CSAR file as an '
34 'argument. Please refer to the usage documentation.')
35 self.assertEqual(err_msg, str(error))
37 def test_invalid_arg(self):
38 error = self.assertRaises(ValueError, shell.main, 'parse me')
39 err_msg = _('The program expects "--template-file" as the first '
40 'argument. Please refer to the usage documentation.')
41 self.assertEqual(err_msg, str(error))
43 def test_template_not_exist(self):
44 error = self.assertRaises(
45 ValueError, shell.main, ['--template-file=template.txt'])
46 self.assertEqual(_('"template.txt" is not a valid file.'), str(error))
48 def test_template_invalid(self):
49 arg = '--template-file=' + self.errornous_template
50 self.assertRaises(exception.ValidationError, shell.main, [arg])
52 def test_template_valid(self):
53 arg = '--template-file=' + self.tosca_helloworld
57 self.fail(_('The program raised an exception unexpectedly.'))