diff --git a/translator/common/utils.py b/translator/common/utils.py index 502b206e..6d0d9e1b 100644 --- a/translator/common/utils.py +++ b/translator/common/utils.py @@ -224,8 +224,8 @@ class TranslationUtils(object): from toscaparser.tosca_template import ToscaTemplate from translator.hot.tosca_translator import TOSCATranslator - tosca_tpl = os.path.join( - os.path.dirname(os.path.abspath(__file__)), tosca_file) + tosca_tpl = os.path.normpath(os.path.join( + os.path.dirname(os.path.abspath(__file__)), tosca_file)) a_file = os.path.isfile(tosca_tpl) if not a_file: tosca_tpl = tosca_file diff --git a/translator/hot/tests/test_translate_inputs.py b/translator/hot/tests/test_translate_inputs.py index 079876ac..2b302ab8 100644 --- a/translator/hot/tests/test_translate_inputs.py +++ b/translator/hot/tests/test_translate_inputs.py @@ -78,7 +78,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_greater_or_equal(self): @@ -92,7 +93,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_greater_than(self): @@ -106,7 +108,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_less_than(self): @@ -120,7 +123,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_less_or_equal(self): @@ -134,7 +138,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_valid_values(self): @@ -148,8 +153,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' input_params = {'num_cpus': '3'} - expectedmessage = _('num_cpus: 3 is not a valid value. Expected a ' - 'value from "[1, 2, 4, 8]".') + expectedmessage = _('The value "3" of property "num_cpus" is not ' + 'valid. Expected a value from "[1, 2, 4, 8]".') self._translate_input_test(tpl_snippet, input_params, expectedmessage) def test_invalid_input_constraints_for_in_range(self): @@ -163,7 +168,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_min_length(self): @@ -177,7 +183,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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) def test_invalid_input_constraints_for_max_length(self): @@ -191,8 +198,8 @@ class ToscaTemplateInputValidationTest(TestCase): ''' input_params = {'user_name': 'abcdefg'} - expectedmessage = _('length of user_name: ' - 'abcdefg must be no greater than "6".') + expectedmessage = _('Length of value "abcdefg" of property ' + '"user_name" must be no greater than "6".') self._translate_input_test(tpl_snippet, input_params, expectedmessage) def test_invalid_input_constraints_for_pattern(self): @@ -206,7 +213,7 @@ class ToscaTemplateInputValidationTest(TestCase): ''' 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+$".') 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) 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) def test_invalid_input_type_version(self): diff --git a/translator/tests/test_tosca_hot_translation.py b/translator/tests/test_tosca_hot_translation.py index 55e70638..534f8ed9 100644 --- a/translator/tests/test_tosca_hot_translation.py +++ b/translator/tests/test_tosca_hot_translation.py @@ -11,9 +11,12 @@ # under the License. import json +import os +from toscaparser.common.exception import ExceptionCollector from toscaparser.common.exception import URLException from toscaparser.common.exception import ValidationError +from toscaparser.utils.gettextutils import _ from translator.common.utils import TranslationUtils from translator.tests.base import TestCase @@ -357,16 +360,16 @@ class ToscaHotTranslationTest(TestCase): 'db_port': 3366, 'cpus': 8} - err = self.assertRaises( - ImportError, + self.assertRaises( + ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - self.assertEqual( - 'Absolute file name /tmp/wordpress.yaml cannot be used for a ' - 'URL-based input https://raw.githubusercontent.com/openstack/' - 'heat-translator/master/translator/tests/data/tosca_single_' - 'instance_wordpress_with_local_abspath_import.yaml template.', - err.__str__()) + expected_msg = _('Absolute file name "/tmp/wordpress.yaml" cannot be ' + 'used in a URL-based input template "https://raw.' + 'githubusercontent.com/openstack/heat-translator/' + 'master/translator/tests/data/tosca_single_instance_' + 'wordpress_with_local_abspath_import.yaml".') + ExceptionCollector.assertExceptionMessage(ImportError, expected_msg) def test_hot_translate_template_by_url_with_url_import(self): tosca_url = 'https://raw.githubusercontent.com/openstack/' \ @@ -429,78 +432,72 @@ class ToscaHotTranslationTest(TestCase): hot_file = '' params = {} - err = self.assertRaises( + self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - - err_msg = err.__str__() - self.assertIs(True, - err_msg.startswith('The file ') and - err_msg.endswith('../tests/data/csar_not_zip.zip is not ' - 'a valid zip file.')) + path = os.path.normpath(os.path.join( + os.path.dirname(os.path.realpath(__file__)), tosca_file)) + expected_msg = _('"%s" is not a valid zip file.') % path + ExceptionCollector.assertExceptionMessage(ValidationError, + expected_msg) def test_translate_csar_metadata_not_yaml(self): tosca_file = '../tests/data/csar_metadata_not_yaml.zip' hot_file = '' params = {} - err = self.assertRaises( + self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - - err_msg = err.__str__() - self.assertIs(True, - err_msg.startswith('The file ' - '"TOSCA-Metadata/TOSCA.meta" in ') - and - err_msg.endswith('../tests/data/csar_metadata_not_yaml' - '.zip does not contain valid YAML ' - 'content.')) + path = os.path.normpath(os.path.join( + os.path.dirname(os.path.realpath(__file__)), tosca_file)) + expected_msg = _('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR ' + '"%s" does not contain valid YAML content.') % path + ExceptionCollector.assertExceptionMessage(ValidationError, + expected_msg) def test_translate_csar_wrong_metadata_file(self): tosca_file = '../tests/data/csar_wrong_metadata_file.zip' hot_file = '' params = {} - err = self.assertRaises( + self.assertRaises( ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - - err_msg = err.__str__() - self.assertIs(True, - err_msg.startswith('The file ') and - err_msg.endswith('../tests/data/csar_wrong_metadata_file' - '.zip is not a valid CSAR as it does ' - 'not contain the required file ' - '"TOSCA.meta" in the folder ' - '"TOSCA-Metadata".')) + path = os.path.normpath(os.path.join( + os.path.dirname(os.path.realpath(__file__)), tosca_file)) + expected_msg = _('"%s" is not a valid CSAR as it does not contain the ' + 'required file "TOSCA.meta" in the folder ' + '"TOSCA-Metadata".') % path + ExceptionCollector.assertExceptionMessage(ValidationError, + expected_msg) def test_translate_csar_wordpress_invalid_import_path(self): tosca_file = '../tests/data/csar_wordpress_invalid_import_path.zip' hot_file = '' params = {} - err = self.assertRaises( - ImportError, + self.assertRaises( + ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - self.assertEqual('Import Definitions/wordpress.yaml is not valid', - err.__str__()) + expected_msg = _('Import "Definitions/wordpress.yaml" is not valid.') + ExceptionCollector.assertExceptionMessage(ImportError, expected_msg) def test_translate_csar_wordpress_invalid_script_url(self): tosca_file = '../tests/data/csar_wordpress_invalid_script_url.zip' hot_file = '' params = {} - err = self.assertRaises( - URLException, + self.assertRaises( + ValidationError, TranslationUtils.compare_tosca_translation_with_hot, tosca_file, hot_file, params) - self.assertEqual('URLException "The resource at ' - 'https://raw.githubusercontent.com/openstack/' + expected_msg = _('The resource at ' + '"https://raw.githubusercontent.com/openstack/' 'heat-translator/master/translator/tests/data/' - 'custom_types/wordpress1.yaml cannot be accessed".', - err.__str__()) + 'custom_types/wordpress1.yaml" cannot be accessed.') + ExceptionCollector.assertExceptionMessage(URLException, expected_msg)