Fix broken unittests due to tosca-parser 0.3.0 release

Fix a number of unittests that were broken due to updated
error message formatting in version 0.3.0 of tosca-parser.

Change-Id: I706e193ae6d7e8858b317f79b40390e550173886
Closes-Bug: #1522217
This commit is contained in:
Vahid Hashemian 2015-12-03 11:32:21 -08:00
parent 9641857e07
commit fd4e8ca324
3 changed files with 64 additions and 60 deletions

View File

@ -224,8 +224,8 @@ class TranslationUtils(object):
from toscaparser.tosca_template import ToscaTemplate from toscaparser.tosca_template import ToscaTemplate
from translator.hot.tosca_translator import TOSCATranslator from translator.hot.tosca_translator import TOSCATranslator
tosca_tpl = os.path.join( tosca_tpl = os.path.normpath(os.path.join(
os.path.dirname(os.path.abspath(__file__)), tosca_file) os.path.dirname(os.path.abspath(__file__)), tosca_file))
a_file = os.path.isfile(tosca_tpl) a_file = os.path.isfile(tosca_tpl)
if not a_file: if not a_file:
tosca_tpl = tosca_file tosca_tpl = tosca_file

View File

@ -78,7 +78,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '0'} input_params = {'num_cpus': '0'}
expectedmessage = _('num_cpus: 0 is not equal to "1".') expectedmessage = _('The value "0" of property "num_cpus" is not '
'equal to "1".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_greater_or_equal(self): def test_invalid_input_constraints_for_greater_or_equal(self):
@ -92,7 +93,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '0'} input_params = {'num_cpus': '0'}
expectedmessage = _('num_cpus: 0 must be greater or equal to "1".') expectedmessage = _('The value "0" of property "num_cpus" must be '
'greater than or equal to "1".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_greater_than(self): def test_invalid_input_constraints_for_greater_than(self):
@ -106,7 +108,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '0'} input_params = {'num_cpus': '0'}
expectedmessage = _('num_cpus: 0 must be greater than "1".') expectedmessage = _('The value "0" of property "num_cpus" must be '
'greater than "1".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_less_than(self): def test_invalid_input_constraints_for_less_than(self):
@ -120,7 +123,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '8'} input_params = {'num_cpus': '8'}
expectedmessage = _('num_cpus: 8 must be less than "8".') expectedmessage = _('The value "8" of property "num_cpus" must be '
'less than "8".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_less_or_equal(self): def test_invalid_input_constraints_for_less_or_equal(self):
@ -134,7 +138,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '9'} input_params = {'num_cpus': '9'}
expectedmessage = _('num_cpus: 9 must be less or equal to "8".') expectedmessage = _('The value "9" of property "num_cpus" must be '
'less than or equal to "8".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_valid_values(self): def test_invalid_input_constraints_for_valid_values(self):
@ -148,8 +153,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '3'} input_params = {'num_cpus': '3'}
expectedmessage = _('num_cpus: 3 is not a valid value. Expected a ' expectedmessage = _('The value "3" of property "num_cpus" is not '
'value from "[1, 2, 4, 8]".') 'valid. Expected a value from "[1, 2, 4, 8]".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_in_range(self): def test_invalid_input_constraints_for_in_range(self):
@ -163,7 +168,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'num_cpus': '10'} input_params = {'num_cpus': '10'}
expectedmessage = _('num_cpus: 10 is out of range (min:1, max:8).') expectedmessage = _('The value "10" of property "num_cpus" is out of '
'range "(min:1, max:8)".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_min_length(self): def test_invalid_input_constraints_for_min_length(self):
@ -177,7 +183,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'user_name': 'abcd'} input_params = {'user_name': 'abcd'}
expectedmessage = _('length of user_name: abcd must be at least "8".') expectedmessage = _('Length of value "abcd" of property "user_name" '
'must be at least "8".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_max_length(self): def test_invalid_input_constraints_for_max_length(self):
@ -191,8 +198,8 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'user_name': 'abcdefg'} input_params = {'user_name': 'abcdefg'}
expectedmessage = _('length of user_name: ' expectedmessage = _('Length of value "abcdefg" of property '
'abcdefg must be no greater than "6".') '"user_name" must be no greater than "6".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
def test_invalid_input_constraints_for_pattern(self): def test_invalid_input_constraints_for_pattern(self):
@ -206,7 +213,7 @@ class ToscaTemplateInputValidationTest(TestCase):
''' '''
input_params = {'user_name': '1-abc'} input_params = {'user_name': '1-abc'}
expectedmessage = _('user_name: "1-abc" does ' expectedmessage = _('The value "1-abc" of property "user_name" does '
'not match pattern "^\\w+$".') 'not match pattern "^\\w+$".')
self._translate_input_test(tpl_snippet, input_params, expectedmessage) self._translate_input_test(tpl_snippet, input_params, expectedmessage)
@ -291,7 +298,7 @@ class ToscaTemplateInputValidationTest(TestCase):
self._translate_input_test(tpl_snippet, input_params, expectedmsg) self._translate_input_test(tpl_snippet, input_params, expectedmsg)
input_params = {'storage_size': '-2 MB'} input_params = {'storage_size': '-2 MB'}
expectedmsg = _('"-2 MB" is not a valid scalar-unit') expectedmsg = _('"-2 MB" is not a valid scalar-unit.')
self._translate_input_test(tpl_snippet, input_params, expectedmsg) self._translate_input_test(tpl_snippet, input_params, expectedmsg)
def test_invalid_input_type_version(self): def test_invalid_input_type_version(self):

View File

@ -11,9 +11,12 @@
# under the License. # under the License.
import json import json
import os
from toscaparser.common.exception import ExceptionCollector
from toscaparser.common.exception import URLException from toscaparser.common.exception import URLException
from toscaparser.common.exception import ValidationError from toscaparser.common.exception import ValidationError
from toscaparser.utils.gettextutils import _
from translator.common.utils import TranslationUtils from translator.common.utils import TranslationUtils
from translator.tests.base import TestCase from translator.tests.base import TestCase
@ -357,16 +360,16 @@ class ToscaHotTranslationTest(TestCase):
'db_port': 3366, 'db_port': 3366,
'cpus': 8} 'cpus': 8}
err = self.assertRaises( self.assertRaises(
ImportError, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
self.assertEqual( expected_msg = _('Absolute file name "/tmp/wordpress.yaml" cannot be '
'Absolute file name /tmp/wordpress.yaml cannot be used for a ' 'used in a URL-based input template "https://raw.'
'URL-based input https://raw.githubusercontent.com/openstack/' 'githubusercontent.com/openstack/heat-translator/'
'heat-translator/master/translator/tests/data/tosca_single_' 'master/translator/tests/data/tosca_single_instance_'
'instance_wordpress_with_local_abspath_import.yaml template.', 'wordpress_with_local_abspath_import.yaml".')
err.__str__()) ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def test_hot_translate_template_by_url_with_url_import(self): def test_hot_translate_template_by_url_with_url_import(self):
tosca_url = 'https://raw.githubusercontent.com/openstack/' \ tosca_url = 'https://raw.githubusercontent.com/openstack/' \
@ -429,78 +432,72 @@ class ToscaHotTranslationTest(TestCase):
hot_file = '' hot_file = ''
params = {} params = {}
err = self.assertRaises( self.assertRaises(
ValidationError, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
path = os.path.normpath(os.path.join(
err_msg = err.__str__() os.path.dirname(os.path.realpath(__file__)), tosca_file))
self.assertIs(True, expected_msg = _('"%s" is not a valid zip file.') % path
err_msg.startswith('The file ') and ExceptionCollector.assertExceptionMessage(ValidationError,
err_msg.endswith('../tests/data/csar_not_zip.zip is not ' expected_msg)
'a valid zip file.'))
def test_translate_csar_metadata_not_yaml(self): def test_translate_csar_metadata_not_yaml(self):
tosca_file = '../tests/data/csar_metadata_not_yaml.zip' tosca_file = '../tests/data/csar_metadata_not_yaml.zip'
hot_file = '' hot_file = ''
params = {} params = {}
err = self.assertRaises( self.assertRaises(
ValidationError, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
path = os.path.normpath(os.path.join(
err_msg = err.__str__() os.path.dirname(os.path.realpath(__file__)), tosca_file))
self.assertIs(True, expected_msg = _('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR '
err_msg.startswith('The file ' '"%s" does not contain valid YAML content.') % path
'"TOSCA-Metadata/TOSCA.meta" in ') ExceptionCollector.assertExceptionMessage(ValidationError,
and expected_msg)
err_msg.endswith('../tests/data/csar_metadata_not_yaml'
'.zip does not contain valid YAML '
'content.'))
def test_translate_csar_wrong_metadata_file(self): def test_translate_csar_wrong_metadata_file(self):
tosca_file = '../tests/data/csar_wrong_metadata_file.zip' tosca_file = '../tests/data/csar_wrong_metadata_file.zip'
hot_file = '' hot_file = ''
params = {} params = {}
err = self.assertRaises( self.assertRaises(
ValidationError, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
path = os.path.normpath(os.path.join(
err_msg = err.__str__() os.path.dirname(os.path.realpath(__file__)), tosca_file))
self.assertIs(True, expected_msg = _('"%s" is not a valid CSAR as it does not contain the '
err_msg.startswith('The file ') and 'required file "TOSCA.meta" in the folder '
err_msg.endswith('../tests/data/csar_wrong_metadata_file' '"TOSCA-Metadata".') % path
'.zip is not a valid CSAR as it does ' ExceptionCollector.assertExceptionMessage(ValidationError,
'not contain the required file ' expected_msg)
'"TOSCA.meta" in the folder '
'"TOSCA-Metadata".'))
def test_translate_csar_wordpress_invalid_import_path(self): def test_translate_csar_wordpress_invalid_import_path(self):
tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip' tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip'
hot_file = '' hot_file = ''
params = {} params = {}
err = self.assertRaises( self.assertRaises(
ImportError, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
self.assertEqual('Import Definitions/wordpress.yaml is not valid', expected_msg = _('Import "Definitions/wordpress.yaml" is not valid.')
err.__str__()) ExceptionCollector.assertExceptionMessage(ImportError, expected_msg)
def test_translate_csar_wordpress_invalid_script_url(self): def test_translate_csar_wordpress_invalid_script_url(self):
tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip' tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip'
hot_file = '' hot_file = ''
params = {} params = {}
err = self.assertRaises( self.assertRaises(
URLException, ValidationError,
TranslationUtils.compare_tosca_translation_with_hot, TranslationUtils.compare_tosca_translation_with_hot,
tosca_file, hot_file, params) tosca_file, hot_file, params)
self.assertEqual('URLException "The resource at ' expected_msg = _('The resource at '
'https://raw.githubusercontent.com/openstack/' '"https://raw.githubusercontent.com/openstack/'
'heat-translator/master/translator/tests/data/' 'heat-translator/master/translator/tests/data/'
'custom_types/wordpress1.yaml cannot be accessed".', 'custom_types/wordpress1.yaml" cannot be accessed.')
err.__str__()) ExceptionCollector.assertExceptionMessage(URLException, expected_msg)