netsted template validate type error
[parser.git] / tosca2heat / tosca-parser / toscaparser / tests / test_exception.py
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
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
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
11 #    under the License.
12
13 from toscaparser.common import exception
14 from toscaparser.tests.base import TestCase
15 from toscaparser.utils.gettextutils import _
16
17
18 class ExceptionTest(TestCase):
19
20     def setUp(self):
21         super(TestCase, self).setUp()
22         exception.TOSCAException.set_fatal_format_exception(False)
23
24     def test_message(self):
25         ex = exception.MissingRequiredFieldError(what='Template',
26                                                  required='type')
27         self.assertEqual(_('Template is missing required field "type".'),
28                          ex.__str__())
29
30     def test_set_flag(self):
31         exception.TOSCAException.set_fatal_format_exception('True')
32         self.assertFalse(
33             exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS)
34
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)
39
40     def _formate_exception(self):
41         exception.UnknownFieldError.set_fatal_format_exception(True)
42         raise exception.UnknownFieldError(what='Template')