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
13 from toscaparser.common import exception
14 from toscaparser.tests.base import TestCase
15 from toscaparser.utils.gettextutils import _
18 class ExceptionTest(TestCase):
21 super(TestCase, self).setUp()
22 exception.TOSCAException.set_fatal_format_exception(False)
24 def test_message(self):
25 ex = exception.MissingRequiredFieldError(what='Template',
27 self.assertEqual(_('Template is missing required field "type".'),
30 def test_set_flag(self):
31 exception.TOSCAException.set_fatal_format_exception('True')
33 exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS)
35 def test_format_error(self):
36 ex = exception.UnknownFieldError(what='Template')
37 self.assertEqual(_('An unknown exception occurred.'), ex.__str__(),)
38 self.assertRaises(KeyError, self._formate_exception)
40 def _formate_exception(self):
41 exception.UnknownFieldError.set_fatal_format_exception(True)
42 raise exception.UnknownFieldError(what='Template')