2014-07-03 08:47:05 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2015-08-25 08:16:57 -07:00
|
|
|
from toscaparser.common import exception
|
|
|
|
from toscaparser.tests.base import TestCase
|
2015-11-18 16:25:16 -08:00
|
|
|
from toscaparser.utils.gettextutils import _
|
2014-07-03 08:47:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ExceptionTest(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestCase, self).setUp()
|
2015-02-12 18:06:51 -08:00
|
|
|
exception.TOSCAException.set_fatal_format_exception(False)
|
2014-07-03 08:47:05 +00:00
|
|
|
|
|
|
|
def test_message(self):
|
2015-02-12 18:06:51 -08:00
|
|
|
ex = exception.MissingRequiredFieldError(what='Template',
|
|
|
|
required='type')
|
2015-11-18 16:25:16 -08:00
|
|
|
self.assertEqual(_('Template is missing required field "type".'),
|
2014-07-03 08:47:05 +00:00
|
|
|
ex.__str__())
|
|
|
|
|
|
|
|
def test_set_flag(self):
|
2015-02-12 18:06:51 -08:00
|
|
|
exception.TOSCAException.set_fatal_format_exception('True')
|
|
|
|
self.assertFalse(
|
|
|
|
exception.TOSCAException._FATAL_EXCEPTION_FORMAT_ERRORS)
|
2014-07-03 08:47:05 +00:00
|
|
|
|
|
|
|
def test_format_error(self):
|
2015-02-12 18:06:51 -08:00
|
|
|
ex = exception.UnknownFieldError(what='Template')
|
2015-11-18 16:25:16 -08:00
|
|
|
self.assertEqual(_('An unknown exception occurred.'), ex.__str__(),)
|
2014-07-03 08:47:05 +00:00
|
|
|
self.assertRaises(KeyError, self._formate_exception)
|
|
|
|
|
|
|
|
def _formate_exception(self):
|
2015-02-12 18:06:51 -08:00
|
|
|
exception.UnknownFieldError.set_fatal_format_exception(True)
|
|
|
|
raise exception.UnknownFieldError(what='Template')
|