Update error message to a uniform format

Update error messages so they follow the same format.
Also, add i18n where it is missing, fix typo and grammatical
errors in messages, and fix vague messages so they are more
clear.

Change-Id: I06d29b4d8448f8c08fa199a316942f373b968d22
Closes-Bug: #1517271
This commit is contained in:
Vahid Hashemian 2015-11-18 16:25:16 -08:00
parent 6924f38fb5
commit ea4b3cdfc6
29 changed files with 470 additions and 422 deletions

View File

@ -55,16 +55,16 @@ class TOSCAException(Exception):
class MissingRequiredFieldError(TOSCAException):
msg_fmt = _('%(what)s is missing required field: "%(required)s".')
msg_fmt = _('%(what)s is missing required field "%(required)s".')
class UnknownFieldError(TOSCAException):
msg_fmt = _('%(what)s contain(s) unknown field: "%(field)s", '
'refer to the definition to verify valid values.')
msg_fmt = _('%(what)s contains unknown field "%(field)s". Refer to the '
'definition to verify valid values.')
class TypeMismatchError(TOSCAException):
msg_fmt = _('%(what)s must be of type: "%(type)s".')
msg_fmt = _('%(what)s must be of type "%(type)s".')
class InvalidNodeTypeError(TOSCAException):
@ -76,15 +76,15 @@ class InvalidTypeError(TOSCAException):
class InvalidSchemaError(TOSCAException):
msg_fmt = _("%(message)s")
msg_fmt = _('%(message)s')
class ValidationError(TOSCAException):
msg_fmt = _("%(message)s")
msg_fmt = _('%(message)s')
class UnknownInputError(TOSCAException):
msg_fmt = _('Unknown input: %(input_name)s')
msg_fmt = _('Unknown input "%(input_name)s".')
class InvalidPropertyValueError(TOSCAException):
@ -93,7 +93,7 @@ class InvalidPropertyValueError(TOSCAException):
class InvalidTemplateVersion(TOSCAException):
msg_fmt = _('The template version "%(what)s" is invalid. '
'The valid versions are: "%(valid_versions)s"')
'Valid versions are "%(valid_versions)s".')
class InvalidTOSCAVersionPropertyException(TOSCAException):
@ -101,7 +101,7 @@ class InvalidTOSCAVersionPropertyException(TOSCAException):
class URLException(TOSCAException):
msg_fmt = _('%(what)s.')
msg_fmt = _('%(what)s')
class ExceptionCollector(object):

View File

@ -67,7 +67,7 @@ class DataEntity(object):
for value_key in list(self.value.keys()):
if value_key not in allowed_props:
ExceptionCollector.appendException(
UnknownFieldError(what=(_('Data value of type %s')
UnknownFieldError(what=(_('Data value of type "%s"')
% self.datatype.type),
field=value_key))
@ -83,9 +83,9 @@ class DataEntity(object):
missingprop.append(req_key)
if missingprop:
ExceptionCollector.appendException(
MissingRequiredFieldError(what=(_('Data value of type %s')
% self.datatype.type),
required=missingprop))
MissingRequiredFieldError(
what=(_('Data value of type "%s"')
% self.datatype.type), required=missingprop))
# check every field
for name, value in list(self.value.items()):

View File

@ -53,13 +53,13 @@ class Schema(collections.Mapping):
def __init__(self, name, schema_dict):
self.name = name
if not isinstance(schema_dict, collections.Mapping):
msg = _("Schema %(pname)s must be a dict.") % dict(pname=name)
msg = _('Schema "%(pname)s" must be a dict.') % dict(pname=name)
ExceptionCollector.appendException(InvalidSchemaError(message=msg))
try:
schema_dict['type']
except KeyError:
msg = _("Schema %(pname)s must have type.") % dict(pname=name)
msg = _('Schema "%(pname)s" must have a type.') % dict(pname=name)
ExceptionCollector.appendException(InvalidSchemaError(message=msg))
self.schema = schema_dict
@ -137,7 +137,7 @@ class Constraint(object):
for type in constraint.keys():
ConstraintClass = get_constraint_class(type)
if not ConstraintClass:
msg = _('Invalid constraint type "%s".') % type
msg = _('Invalid property "%s".') % type
ExceptionCollector.appendException(
InvalidSchemaError(message=msg))
@ -152,8 +152,8 @@ class Constraint(object):
self.constraint_value = self._get_scalarunit_constraint_value()
# check if constraint is valid for property type
if property_type not in self.valid_prop_types:
msg = _('Constraint type "%(ctype)s" is not valid '
'for data type "%(dtype)s".') % dict(
msg = _('Property "%(ctype)s" is not valid for data type '
'"%(dtype)s".') % dict(
ctype=self.constraint_key,
dtype=property_type)
ExceptionCollector.appendException(InvalidSchemaError(message=msg))
@ -170,7 +170,7 @@ class Constraint(object):
get_num_from_scalar_unit())
def _err_msg(self, value):
return _('Property %s could not be validated.') % self.property_name
return _('Property "%s" could not be validated.') % self.property_name
def validate(self, value):
self.value_msg = value
@ -200,7 +200,8 @@ class Equal(Constraint):
return False
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s is not equal to "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" is not '
'equal to "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
cvalue=self.constraint_value_msg))
@ -227,8 +228,8 @@ class GreaterThan(Constraint):
constraint)
if not isinstance(constraint[self.GREATER_THAN], self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('greater_than must '
'be comparable.')))
InvalidSchemaError(message=_('The property "greater_than" '
'expects comparable values.')))
def _is_valid(self, value):
if value > self.constraint_value:
@ -237,7 +238,8 @@ class GreaterThan(Constraint):
return False
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s must be greater than "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" must be '
'greater than "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
cvalue=self.constraint_value_msg))
@ -264,8 +266,9 @@ class GreaterOrEqual(Constraint):
constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('greater_or_equal must '
'be comparable.')))
InvalidSchemaError(message=_('The property '
'"greater_or_equal" expects '
'comparable values.')))
def _is_valid(self, value):
if toscaparser.functions.is_function(value) or \
@ -274,8 +277,8 @@ class GreaterOrEqual(Constraint):
return False
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s must be greater or equal '
'to "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" must be '
'greater than or equal to "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
cvalue=self.constraint_value_msg))
@ -302,8 +305,8 @@ class LessThan(Constraint):
constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('less_than must '
'be comparable.')))
InvalidSchemaError(message=_('The property "less_than" '
'expects comparable values.')))
def _is_valid(self, value):
if value < self.constraint_value:
@ -312,7 +315,8 @@ class LessThan(Constraint):
return False
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s must be less than "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" must be '
'less than "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
cvalue=self.constraint_value_msg))
@ -339,8 +343,8 @@ class LessOrEqual(Constraint):
constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('less_or_equal must '
'be comparable.')))
InvalidSchemaError(message=_('The property "less_or_equal" '
'expects comparable values.')))
def _is_valid(self, value):
if value <= self.constraint_value:
@ -349,8 +353,8 @@ class LessOrEqual(Constraint):
return False
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s must be less or '
'equal to "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" must be '
'less than or equal to "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
cvalue=self.constraint_value_msg))
@ -377,13 +381,14 @@ class InRange(Constraint):
if(not isinstance(self.constraint_value, collections.Sequence) or
(len(constraint[self.IN_RANGE]) != 2)):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('in_range must be a list.')))
InvalidSchemaError(message=_('The property "in_range" '
'expects a list.')))
for value in self.constraint_value:
if not isinstance(value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(_('in_range value must '
'be comparable.')))
InvalidSchemaError(_('The property "in_range" expects '
'comparable values.')))
self.min = self.constraint_value[0]
self.max = self.constraint_value[1]
@ -397,8 +402,8 @@ class InRange(Constraint):
return True
def _err_msg(self, value):
return (_('%(pname)s: %(pvalue)s is out of range '
'(min:%(vmin)s, max:%(vmax)s).') %
return (_('The value "%(pvalue)s" of property "%(pname)s" is out of '
'range "(min:%(vmin)s, max:%(vmax)s)".') %
dict(pname=self.property_name,
pvalue=self.value_msg,
vmin=self.constraint_value_msg[0],
@ -420,7 +425,8 @@ class ValidValues(Constraint):
constraint)
if not isinstance(self.constraint_value, collections.Sequence):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('valid_values must be a list.')))
InvalidSchemaError(message=_('The property "valid_values" '
'expects a list.')))
def _is_valid(self, value):
if isinstance(value, list):
@ -429,8 +435,8 @@ class ValidValues(Constraint):
def _err_msg(self, value):
allowed = '[%s]' % ', '.join(str(a) for a in self.constraint_value)
return (_('%(pname)s: %(pvalue)s is not a valid value. Expected a '
'value from "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" is not '
'valid. Expected a value from "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=allowed))
@ -452,7 +458,8 @@ class Length(Constraint):
super(Length, self).__init__(property_name, property_type, constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('length must be integer.')))
InvalidSchemaError(message=_('The property "length" expects '
'an integer.')))
def _is_valid(self, value):
if isinstance(value, str) and len(value) == self.constraint_value:
@ -461,8 +468,8 @@ class Length(Constraint):
return False
def _err_msg(self, value):
return (_('length of %(pname)s: %(pvalue)s must be equal '
'to "%(cvalue)s".') %
return (_('Length of value "%(pvalue)s" of property "%(pname)s" '
'must be equal to "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=self.constraint_value))
@ -485,7 +492,8 @@ class MinLength(Constraint):
constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('min_length must be integer.')))
InvalidSchemaError(message=_('The property "min_length" '
'expects an integer.')))
def _is_valid(self, value):
if isinstance(value, str) and len(value) >= self.constraint_value:
@ -494,8 +502,8 @@ class MinLength(Constraint):
return False
def _err_msg(self, value):
return (_('length of %(pname)s: %(pvalue)s must be '
'at least "%(cvalue)s".') %
return (_('Length of value "%(pvalue)s" of property "%(pname)s" '
'must be at least "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=self.constraint_value))
@ -518,7 +526,8 @@ class MaxLength(Constraint):
constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('max_length must be integer.')))
InvalidSchemaError(message=_('The property "max_length" '
'expects an integer.')))
def _is_valid(self, value):
if isinstance(value, str) and len(value) <= self.constraint_value:
@ -527,8 +536,8 @@ class MaxLength(Constraint):
return False
def _err_msg(self, value):
return (_('length of %(pname)s: %(pvalue)s must be no greater '
'than "%(cvalue)s".') %
return (_('Length of value "%(pvalue)s" of property "%(pname)s" '
'must be no greater than "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=self.constraint_value))
@ -551,7 +560,8 @@ class Pattern(Constraint):
super(Pattern, self).__init__(property_name, property_type, constraint)
if not isinstance(self.constraint_value, self.valid_types):
ExceptionCollector.appendException(
InvalidSchemaError(message=_('pattern must be string.')))
InvalidSchemaError(message=_('The property "pattern" '
'expects a string.')))
self.match = re.compile(self.constraint_value).match
def _is_valid(self, value):
@ -559,8 +569,8 @@ class Pattern(Constraint):
return match is not None and match.end() == len(value)
def _err_msg(self, value):
return (_('%(pname)s: "%(pvalue)s" does not match '
'pattern "%(cvalue)s".') %
return (_('The value "%(pvalue)s" of property "%(pname)s" does not '
'match pattern "%(cvalue)s".') %
dict(pname=self.property_name,
pvalue=value,
cvalue=self.constraint_value))

View File

@ -50,7 +50,7 @@ class InterfacesDef(StatefulEntityType):
elif i == INPUTS:
self.inputs = j
else:
what = ('Interfaces of template %s' %
what = ('"interfaces" of template "%s"' %
self.node_template.name)
ExceptionCollector.appendException(
UnknownFieldError(what=what, field=i))

View File

@ -25,8 +25,8 @@ class PropertyDef(object):
try:
self.schema['type']
except KeyError:
msg = (_("Property definition of %(pname)s must have type.") %
dict(pname=self.name))
msg = (_('Property definition of "%(pname)s" must have a "type" '
'attribute.') % dict(pname=self.name))
ExceptionCollector.appendException(
InvalidSchemaError(message=msg))

View File

@ -43,13 +43,15 @@ class ScalarUnit(object):
else:
for key in self.SCALAR_UNIT_DICT.keys():
if key.upper() == input_unit.upper():
log.warning(_('Given unit %(unit)s does not follow scalar '
'unit standards; using %(key)s instead.') % {
'unit': input_unit, 'key': key})
log.warning(_('The unit "%(unit)s" does not follow '
'scalar unit standards; using "%(key)s" '
'instead.') % {'unit': input_unit,
'key': key})
return key
msg = (_('Provided unit "%(unit)s" is not valid. The valid units'
' are %(valid_units)s') % {'unit': input_unit,
'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())})
msg = (_('The unit "%(unit)s" is not valid. Valid units are '
'"%(valid_units)s".') %
{'unit': input_unit,
'valid_units': sorted(self.SCALAR_UNIT_DICT.keys())})
ExceptionCollector.appendException(ValueError(msg))
def validate_scalar_unit(self):
@ -63,7 +65,7 @@ class ScalarUnit(object):
except Exception:
ExceptionCollector.appendException(
ValueError(_('"%s" is not a valid scalar-unit')
ValueError(_('"%s" is not a valid scalar-unit.')
% self.value))
def get_num_from_scalar_unit(self, unit=None):
@ -124,4 +126,4 @@ def get_scalarunit_value(type, value, unit=None):
get_num_from_scalar_unit(unit))
else:
ExceptionCollector.appendException(
TypeError(_('"%s" is not a valid scalar-unit type') % type))
TypeError(_('"%s" is not a valid scalar-unit type.') % type))

View File

@ -146,7 +146,7 @@ class EntityTemplate(object):
self.entity_tpl)
if capabilities:
self._common_validate_field(capabilities, allowed_caps,
'Capabilities')
'capabilities')
self._validate_capabilities_properties(capabilities)
def _validate_capabilities_properties(self, capabilities):
@ -168,10 +168,10 @@ class EntityTemplate(object):
default_instances = prop_dict.get("default_instances")
if not (min_instances <= default_instances
<= max_instances):
err_msg = ("Properties of template %s : "
"default_instances value is not"
" between min_instances and "
"max_instances" % self.name)
err_msg = ('"properties" of template "%s": '
'"default_instances" value is not between '
'"min_instances" and "max_instances".' %
self.name)
ExceptionCollector.appendException(
ValidationError(message=err_msg))
@ -184,7 +184,7 @@ class EntityTemplate(object):
required_props.append(p.name)
if properties:
self._common_validate_field(properties, allowed_props,
'Properties')
'properties')
# make sure it's not missing any property required by a tosca type
missingprop = []
for r in required_props:
@ -193,20 +193,20 @@ class EntityTemplate(object):
if missingprop:
ExceptionCollector.appendException(
MissingRequiredFieldError(
what='Properties of template %s' % self.name,
what='"properties" of template "%s"' % self.name,
required=missingprop))
else:
if required_props:
ExceptionCollector.appendException(
MissingRequiredFieldError(
what='Properties of template %s' % self.name,
what='"properties" of template "%s"' % self.name,
required=missingprop))
def _validate_field(self, template):
if not isinstance(template, dict):
ExceptionCollector.appendException(
MissingRequiredFieldError(
what='Template %s' % self.name, required=self.TYPE))
what='Template "%s"' % self.name, required=self.TYPE))
try:
relationship = template.get('relationship')
if relationship and not isinstance(relationship, str):
@ -218,14 +218,14 @@ class EntityTemplate(object):
except KeyError:
ExceptionCollector.appendException(
MissingRequiredFieldError(
what='Template %s' % self.name, required=self.TYPE))
what='Template "%s"' % self.name, required=self.TYPE))
def _common_validate_field(self, schema, allowedlist, section):
for name in schema:
if name not in allowedlist:
ExceptionCollector.appendException(
UnknownFieldError(
what=('%(section)s of template %(nodename)s'
what=('"%(section)s" of template "%(nodename)s"'
% {'section': section, 'nodename': self.name}),
field=name))

View File

@ -76,8 +76,8 @@ class GetInput(Function):
if len(self.args) != 1:
ExceptionCollector.appendException(
ValueError(_(
'Expected one argument for get_input function but '
'received: {0}.').format(self.args)))
'Expected one argument for function "get_input" but '
'received "%s".') % self.args))
inputs = [input.name for input in self.tosca_tpl.inputs]
if self.args[0] not in inputs:
ExceptionCollector.appendException(
@ -124,9 +124,9 @@ class GetAttribute(Function):
def validate(self):
if len(self.args) != 2:
ExceptionCollector.appendException(
ValueError(_('Illegal arguments for {0} function. Expected '
'arguments: node-template-name, attribute-name'
).format(GET_ATTRIBUTE)))
ValueError(_('Illegal arguments for function "{0}". Expected '
'arguments: "node-template-name", '
'"attribute-name"').format(GET_ATTRIBUTE)))
self._find_node_template_containing_attribute()
def result(self):
@ -148,25 +148,26 @@ class GetAttribute(Function):
if isinstance(self.context, list):
ExceptionCollector.appendException(
ValueError(_(
"get_attribute HOST keyword is not allowed within the "
"outputs section of the TOSCA template")))
'"get_attribute: [ HOST, ... ]" is not allowed in '
'"outputs" section of the TOSCA template.')))
return
node_tpl = self._find_host_containing_attribute()
if not node_tpl:
ExceptionCollector.appendException(
ValueError(_(
"get_attribute HOST keyword is used in '{0}' node "
"template but {1} was not found "
"in relationship chain").format(self.context.name,
HOSTED_ON)))
'"get_attribute: [ HOST, ... ]" was used in node '
'template "{0}" but "{1}" was not found in '
'the relationship chain.').format(self.context.name,
HOSTED_ON)))
else:
node_tpl = self._find_node_template(self.args[0])
if node_tpl and \
not self._attribute_exists_in_type(node_tpl.type_definition):
ExceptionCollector.appendException(
KeyError(_(
"Attribute '{0}' not found in node template: {1}.").format(
self.attribute_name, node_tpl.name)))
KeyError(_('Attribute "%(att)s" was not found in node '
'template "%(ntpl)s".') %
{'att': self.attribute_name,
'ntpl': node_tpl.name}))
return node_tpl
def _attribute_exists_in_type(self, type_definition):
@ -202,7 +203,8 @@ class GetAttribute(Function):
return node_template
ExceptionCollector.appendException(
KeyError(_(
'No such node template: {0}.').format(node_template_name)))
'Node template "{0}" was not found.'
).format(node_template_name)))
@property
def node_template_name(self):
@ -243,8 +245,8 @@ class GetProperty(Function):
if len(self.args) < 2 or len(self.args) > 3:
ExceptionCollector.appendException(
ValueError(_(
'Expected arguments: [node-template-name, req-or-cap '
'(optional), property name.')))
'Expected arguments: "node-template-name", "req-or-cap" '
'(optional), "property name".')))
return
if len(self.args) == 2:
found_prop = self._find_property(self.args[1])
@ -293,16 +295,16 @@ class GetProperty(Function):
property = props[property_name].value
if not property:
ExceptionCollector.appendException(
KeyError(_(
'Property "{0}" not found in capability "{1}" of node'
' template "{2}" referenced from node template'
' "{3}".').format(property_name,
capability_name,
node_template.name,
self.context.name)))
KeyError(_('Property "%(prop)s" was not found in '
'capability "%(cap)s" of node template '
'"%(ntpl1)s" referenced from node template '
'"%(ntpl2)s".') % {'prop': property_name,
'cap': capability_name,
'ntpl1': node_template.name,
'ntpl2': self.context.name}))
return property
msg = _("Requirement/Capability '{0}' referenced from '{1}' node "
"template not found in '{2}' node template.").format(
msg = _('Requirement/Capability "{0}" referenced from node template '
'"{1}" was not found in node template "{2}".').format(
capability_name,
self.context.name,
node_template.name)
@ -316,9 +318,10 @@ class GetProperty(Function):
found = [props[property_name]] if property_name in props else []
if len(found) == 0:
ExceptionCollector.appendException(
KeyError(_(
"Property: '{0}' not found in node template: {1}.").format(
property_name, node_tpl.name)))
KeyError(_('Property "%(prop)s" was not found in node '
'template "%(ntpl)s".') %
{'prop': property_name,
'ntpl': node_tpl.name}))
return None
return found[0]
@ -332,7 +335,8 @@ class GetProperty(Function):
return node_template
ExceptionCollector.appendException(
KeyError(_(
'No such node template: {0}.').format(node_template_name)))
'Node template "{0}" was not found.'
).format(node_template_name)))
def result(self):
if len(self.args) == 3:

View File

@ -35,7 +35,7 @@ class ImportsLoader(object):
self.importslist = importslist
self.custom_defs = {}
if not path:
msg = _("Input tosca template is not provided")
msg = _('Input tosca template is not provided.')
log.warning(msg)
ExceptionCollector.appendException(ValidationError(message=msg))
self.path = path
@ -54,7 +54,8 @@ class ImportsLoader(object):
imports_names = set()
if not self.importslist:
msg = _("imports keyname defined without including templates")
msg = _('"imports" keyname is defined without including '
'templates.')
log.error(msg)
ExceptionCollector.appendException(ValidationError(message=msg))
return
@ -63,7 +64,8 @@ class ImportsLoader(object):
if isinstance(import_def, dict):
for import_name, import_uri in import_def.items():
if import_name in imports_names:
msg = _('Duplicate Import name found %s') % import_name
msg = (_('Duplicate import name "%s" was found.') %
import_name)
log.error(msg)
ExceptionCollector.appendException(
ValidationError(message=msg))
@ -90,21 +92,20 @@ class ImportsLoader(object):
def _validate_import_keys(self, import_name, import_uri_def):
if self.FILE not in import_uri_def.keys():
log.warning(_("Missing 'file' keyname in "
"imported %(name)s definition.")
log.warning(_('Missing keyname "file" in import "%(name)s".')
% {'name': import_name})
ExceptionCollector.appendException(
MissingRequiredFieldError(
what='Import of template %s' % import_name,
what='Import of template "%s"' % import_name,
required=self.FILE))
for key in import_uri_def.keys():
if key not in self.IMPORTS_SECTION:
log.warning(_("Unknown keyname %(key)s error in "
"imported %(def)s definition.")
log.warning(_('Unknown keyname "%(key)s" error in '
'imported definition "%(def)s".')
% {'key': key, 'def': import_name})
ExceptionCollector.appendException(
UnknownFieldError(
what='Import of template %s' % import_name,
what='Import of template "%s"' % import_name,
field=key))
def _load_import_template(self, import_name, import_uri_def):
@ -141,8 +142,8 @@ class ImportsLoader(object):
short_import_notation = True
if not file_name:
msg = (_("Input tosca template is not provided with import"
" '%(import_name)s' definition.")
msg = (_('A template file name is not provided with import '
'definition "%(import_name)s".')
% {'import_name': import_name})
log.error(msg)
ExceptionCollector.appendException(ValidationError(message=msg))
@ -165,9 +166,8 @@ class ImportsLoader(object):
import_template = full_path
else: # main_a_url
if os.path.isabs(file_name):
msg = (_("Absolute file name %(name)s"
" cannot be used for a URL-based input "
"%(template)s template.")
msg = (_('Absolute file name "%(name)s" cannot be used '
'in a URL-based input template "%(template)s".')
% {'name': file_name, 'template': self.path})
log.error(msg)
ExceptionCollector.appendException(ImportError(msg))
@ -176,17 +176,18 @@ class ImportsLoader(object):
join_url(self.path, file_name)
a_file = False
if not import_template:
log.error(_("Import %(name)s is not valid")
% {'name': import_uri_def})
log.error(_('Import "%(name)s" is not valid.') %
{'name': import_uri_def})
ExceptionCollector.appendException(
ImportError(_("Import %s is not valid") % import_uri_def))
ImportError(_('Import "%s" is not valid.') %
import_uri_def))
return
return YAML_LOADER(import_template, a_file)
if short_import_notation:
log.error(_("Import %(name)s is not valid") % import_uri_def)
log.error(_('Import "%(name)s" is not valid.') % import_uri_def)
ExceptionCollector.appendException(
ImportError(_("Import %s is not valid") % import_uri_def))
ImportError(_('Import "%s" is not valid.') % import_uri_def))
# Remove leading, ending spaces and strip the last character if "/"
namespace_uri = ((namespace_uri).strip()).rstrip("//")
@ -200,8 +201,8 @@ class ImportsLoader(object):
full_url = namespace_uri + "/" + file_name
return YAML_LOADER(full_url, False)
else:
msg = (_("namespace_uri %(n_uri)s"
" is not valid in import '%(tpl)s' definition")
msg = (_('namespace_uri "%(n_uri)s" is not valid in import '
'definition "%(tpl)s".')
% {'n_uri': namespace_uri, 'tpl': import_name})
log.error(msg)
ExceptionCollector.appendException(ImportError(msg))

View File

@ -74,8 +74,8 @@ class NodeTemplate(EntityTemplate):
if node:
# TODO(spzala) implement look up once Glance meta data is available
# to find a matching TOSCA node using the TOSCA types
msg = _('Lookup by TOSCA types are not supported. '
'Requirement for %s can not be full-filled.') % self.name
msg = _('Lookup by TOSCA types is not supported. '
'Requirement for "%s" can not be full-filled.') % self.name
if (node in list(self.type_definition.TOSCA_DEF.keys())
or node in self.custom_def):
ExceptionCollector.appendException(NotImplementedError(msg))
@ -178,7 +178,7 @@ class NodeTemplate(EntityTemplate):
if not isinstance(requires, list):
ExceptionCollector.appendException(
TypeMismatchError(
what='Requirements of template %s' % self.name,
what='"requirements" of template "%s"' % self.name,
type='list'))
for req in requires:
for r1, value in req.items():
@ -186,7 +186,7 @@ class NodeTemplate(EntityTemplate):
self._validate_requirements_keys(value)
self._validate_requirements_properties(value)
allowed_reqs.append(r1)
self._common_validate_field(req, allowed_reqs, 'Requirements')
self._common_validate_field(req, allowed_reqs, 'requirements')
def _validate_requirements_properties(self, requirements):
# TODO(anyone): Only occurrences property of the requirements is
@ -212,7 +212,7 @@ class NodeTemplate(EntityTemplate):
if key not in self.REQUIREMENTS_SECTION:
ExceptionCollector.appendException(
UnknownFieldError(
what='Requirements of template %s' % self.name,
what='"requirements" of template "%s"' % self.name,
field=key))
def _validate_interfaces(self):
@ -225,21 +225,21 @@ class NodeTemplate(EntityTemplate):
self._common_validate_field(
value, InterfacesDef.
interfaces_node_lifecycle_operations,
'Interfaces')
'interfaces')
elif name in (CONFIGURE, CONFIGURE_SHORTNAME):
self._common_validate_field(
value, InterfacesDef.
interfaces_relationship_confiure_operations,
'Interfaces')
'interfaces')
else:
ExceptionCollector.appendException(
UnknownFieldError(
what='Interfaces of template %s' % self.name,
field=name))
what='"interfaces" of template "%s"' %
self.name, field=name))
def _validate_fields(self, nodetemplate):
for name in nodetemplate.keys():
if name not in self.SECTIONS and name not in self.SPECIAL_SECTIONS:
ExceptionCollector.appendException(
UnknownFieldError(what='Node template %s' % self.name,
UnknownFieldError(what='Node template "%s"' % self.name,
field=name))

View File

@ -60,13 +60,13 @@ class Input(object):
for name in self.schema.schema:
if name not in self.INPUTFIELD:
ExceptionCollector.appendException(
UnknownFieldError(what='Input %s' % self.name,
UnknownFieldError(what='Input "%s"' % self.name,
field=name))
def validate_type(self, input_type):
if input_type not in Schema.PROPERTY_TYPES:
ExceptionCollector.appendException(
ValueError(_('Invalid type %s') % type))
ValueError(_('Invalid type "%s".') % type))
def _validate_value(self, value):
tosca = EntityType.TOSCA_DEF
@ -101,16 +101,16 @@ class Output(object):
def _validate_field(self):
if not isinstance(self.attrs, dict):
ExceptionCollector.appendException(
MissingRequiredFieldError(what='Output %s' % self.name,
MissingRequiredFieldError(what='Output "%s"' % self.name,
required=self.VALUE))
try:
self.value
except KeyError:
ExceptionCollector.appendException(
MissingRequiredFieldError(what='Output %s' % self.name,
MissingRequiredFieldError(what='Output "%s"' % self.name,
required=self.VALUE))
for name in self.attrs:
if name not in self.OUTPUTFIELD:
ExceptionCollector.appendException(
UnknownFieldError(what='Output %s' % self.name,
UnknownFieldError(what='Output "%s"' % self.name,
field=name))

View File

@ -46,7 +46,7 @@ class CSAR(object):
self.is_validated = True
# validate that the file or URL exists
missing_err_msg = (_('%s does not exist.') % self.path)
missing_err_msg = (_('"%s" does not exist.') % self.path)
if self.a_file:
if not os.path.isfile(self.path):
ExceptionCollector.appendException(
@ -63,7 +63,7 @@ class CSAR(object):
# validate that it is a valid zip file
if not zipfile.is_zipfile(self.csar):
err_msg = (_('%s is not a valid zip file.') % self.path)
err_msg = (_('"%s" is not a valid zip file.') % self.path)
ExceptionCollector.appendException(
ValidationError(message=err_msg))
@ -71,7 +71,7 @@ class CSAR(object):
self.zfile = zipfile.ZipFile(self.csar, 'r')
filelist = self.zfile.namelist()
if 'TOSCA-Metadata/TOSCA.meta' not in filelist:
err_msg = (_('%s is not a valid CSAR as it does not contain the '
err_msg = (_('"%s" is not a valid CSAR as it does not contain the '
'required file "TOSCA.meta" in the folder '
'"TOSCA-Metadata".') % self.path)
ExceptionCollector.appendException(
@ -80,7 +80,7 @@ class CSAR(object):
# validate that 'Entry-Definitions' property exists in TOSCA.meta
data = self.zfile.read('TOSCA-Metadata/TOSCA.meta')
invalid_yaml_err_msg = (_('The file "TOSCA-Metadata/TOSCA.meta" in '
'the CSAR %s does not contain valid YAML '
'the CSAR "%s" does not contain valid YAML '
'content.') % self.path)
try:
meta = yaml.load(data)
@ -93,7 +93,7 @@ class CSAR(object):
ValidationError(message=invalid_yaml_err_msg))
if 'Entry-Definitions' not in self.metadata:
err_msg = (_('The CSAR %s is missing the required metadata '
err_msg = (_('The CSAR "%s" is missing the required metadata '
'"Entry-Definitions" in "TOSCA-Metadata/TOSCA.meta".')
% self.path)
ExceptionCollector.appendException(
@ -104,7 +104,7 @@ class CSAR(object):
entry = self.metadata['Entry-Definitions']
if entry not in filelist:
err_msg = (_('The "Entry-Definitions" file defined in the CSAR '
'%s does not exist.') % self.path)
'"%s" does not exist.') % self.path)
ExceptionCollector.appendException(
ValidationError(message=err_msg))
@ -140,9 +140,9 @@ class CSAR(object):
main_template = self.get_main_template()
data = self.zfile.read(main_template)
invalid_tosca_yaml_err_msg = (
_('The file %(template)s in the CSAR %(csar)s does not contain '
'valid TOSCA YAML content.') % {'template': main_template,
'csar': self.path})
_('The file "%(template)s" in the CSAR "%(csar)s" does not '
'contain valid TOSCA YAML content.') %
{'template': main_template, 'csar': self.path})
try:
tosca_yaml = yaml.load(data)
if type(tosca_yaml) is not dict:
@ -210,7 +210,7 @@ class CSAR(object):
else:
ExceptionCollector.appendException(
ValueError(_('Unexpected artifact '
'definition for %s.')
'definition for "%s".')
% artifact_key))
if 'interfaces' in node_template:
interfaces = node_template['interfaces']
@ -242,7 +242,8 @@ class CSAR(object):
Note that in a CSAR resource_file cannot be an absolute path.
"""
if UrlUtils.validate_url(resource_file):
msg = (_('The resource at %s cannot be accessed') % resource_file)
msg = (_('The resource at "%s" cannot be accessed.') %
resource_file)
try:
if UrlUtils.url_accessible(resource_file):
return
@ -260,5 +261,5 @@ class CSAR(object):
if raise_exc:
ExceptionCollector.appendException(
ValueError(_('The resource %s does not exist.')
ValueError(_('The resource "%s" does not exist.')
% resource_file))

View File

@ -42,12 +42,12 @@ class ParserShell(object):
def _validate(self, args):
if len(args) < 1:
msg = _("The program requires template or CSAR file as an "
"argument. Please refer to the usage documentation.")
msg = _('The program requires a template or a CSAR file as an '
'argument. Please refer to the usage documentation.')
raise ValueError(msg)
if "--template-file=" not in args[0]:
msg = _("The program expects --template-file as first argument. "
"Please refer to the usage documentation.")
msg = _('The program expects "--template-file" as the first '
'argument. Please refer to the usage documentation.')
raise ValueError(msg)
def main(self, args):
@ -58,7 +58,7 @@ class ParserShell(object):
elif toscaparser.utils.urlutils.UrlUtils.validate_url(path):
self.parse(path, False)
else:
raise ValueError(_("%(path)s is not a valid file.")
raise ValueError(_('"%(path)s" is not a valid file.')
% {'path': path})
def parse(self, path, a_file=True):

View File

@ -17,6 +17,7 @@ from toscaparser.common import exception
from toscaparser.elements.constraints import Constraint
from toscaparser.elements.constraints import Schema
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils import yamlparser
@ -46,7 +47,7 @@ class ConstraintTest(TestCase):
schema = yamlparser.simple_parse(tpl_snippet)
error = self.assertRaises(exception.InvalidSchemaError, Schema,
'cpus', schema['cpus'])
self.assertEqual('Schema cpus must be a dict.', str(error))
self.assertEqual(_('Schema "cpus" must be a dict.'), str(error))
def test_schema_miss_type(self):
tpl_snippet = '''
@ -56,7 +57,7 @@ class ConstraintTest(TestCase):
schema = yamlparser.simple_parse(tpl_snippet)
error = self.assertRaises(exception.InvalidSchemaError, Schema,
'cpus', schema['cpus'])
self.assertEqual('Schema cpus must have type.', str(error))
self.assertEqual(_('Schema "cpus" must have a type.'), str(error))
def test_schema_none_description(self):
tpl_snippet = '''
@ -72,7 +73,7 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('Invalid constraint type "invalid_type".',
self.assertEqual(_('Invalid property "invalid_type".'),
str(error))
def test_invalid_prop_type(self):
@ -80,15 +81,16 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('Constraint type "length" is not valid for '
'data type "integer".', str(error))
self.assertEqual(_('Property "length" is not valid for data type '
'"integer".'), str(error))
def test_invalid_validvalues(self):
schema = {'valid_values': 2}
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('valid_values must be a list.', str(error))
self.assertEqual(_('The property "valid_values" expects a list.'),
str(error))
def test_validvalues_validate(self):
schema = {'valid_values': [2, 4, 6, 8]}
@ -100,8 +102,9 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.INTEGER, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 5)
self.assertEqual('prop: 5 is not a valid value. Expected a value from '
'"[2, 4, 6, 8]".', str(error))
self.assertEqual(_('The value "5" of property "prop" is not valid. '
'Expected a value from "[2, 4, 6, 8]".'),
str(error))
def test_invalid_in_range(self):
snippet = 'in_range: {2, 6}'
@ -109,7 +112,8 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('in_range must be a list.', str(error))
self.assertEqual(_('The property "in_range" expects a list.'),
str(error))
def test_in_range_min_max(self):
schema = {'in_range': [2, 6]}
@ -129,8 +133,8 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.INTEGER, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 8)
self.assertEqual('prop: 8 is out of range (min:2, max:6).',
str(error))
self.assertEqual(_('The value "8" of property "prop" is out of range '
'"(min:2, max:6)".'), str(error))
def test_equal_validate(self):
schema = {'equal': 4}
@ -142,7 +146,8 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.INTEGER, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 8)
self.assertEqual('prop: 8 is not equal to "4".', str(error))
self.assertEqual('The value "8" of property "prop" is not equal to '
'"4".', str(error))
def test_greater_than_validate(self):
schema = {'greater_than': 4}
@ -154,11 +159,13 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.INTEGER, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 3)
self.assertEqual('prop: 3 must be greater than "4".', str(error))
self.assertEqual(_('The value "3" of property "prop" must be greater '
'than "4".'), str(error))
error = self.assertRaises(exception.ValidationError,
constraint.validate, 4)
self.assertEqual('prop: 4 must be greater than "4".', str(error))
self.assertEqual(_('The value "4" of property "prop" must be greater '
'than "4".'), str(error))
def test_greater_than_invalid(self):
snippet = 'greater_than: {4}'
@ -166,7 +173,8 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('greater_than must be comparable.', str(error))
self.assertEqual(_('The property "greater_than" expects comparable '
'values.'), str(error))
def test_greater_or_equal_validate(self):
schema = {'greater_or_equal': 3.9}
@ -179,12 +187,14 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.FLOAT, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 3.0)
self.assertEqual('prop: 3.0 must be greater or equal to "3.9".',
self.assertEqual(_('The value "3.0" of property "prop" must be '
'greater than or equal to "3.9".'),
str(error))
error = self.assertRaises(exception.ValidationError,
constraint.validate, 3.8)
self.assertEqual('prop: 3.8 must be greater or equal to "3.9".',
self.assertEqual(_('The value "3.8" of property "prop" must be '
'greater than or equal to "3.9".'),
str(error))
def test_greater_or_equal_invalid(self):
@ -193,7 +203,8 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('greater_or_equal must be comparable.', str(error))
self.assertEqual(_('The property "greater_or_equal" expects '
'comparable values.'), str(error))
def test_less_than_validate(self):
schema = {'less_than': datetime.date(2014, 0o7, 25)}
@ -207,15 +218,15 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.ValidationError,
constraint.validate,
datetime.date(2014, 0o7, 25))
self.assertEqual('prop: 2014-07-25 must be '
'less than "2014-07-25".',
self.assertEqual(_('The value "2014-07-25" of property "prop" must be '
'less than "2014-07-25".'),
str(error))
error = self.assertRaises(exception.ValidationError,
constraint.validate,
datetime.date(2014, 0o7, 27))
self.assertEqual('prop: 2014-07-27 must be '
'less than "2014-07-25".',
self.assertEqual(_('The value "2014-07-27" of property "prop" must be '
'less than "2014-07-25".'),
str(error))
def test_less_than_invalid(self):
@ -224,7 +235,8 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('less_than must be comparable.', str(error))
self.assertEqual(_('The property "less_than" expects comparable '
'values.'), str(error))
def test_less_or_equal_validate(self):
schema = {'less_or_equal': 4}
@ -237,7 +249,8 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.INTEGER, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 5)
self.assertEqual('prop: 5 must be less or equal to "4".', str(error))
self.assertEqual(_('The value "5" of property "prop" must be less '
'than or equal to "4".'), str(error))
def test_less_or_equal_invalid(self):
snippet = 'less_or_equal: {3.9}'
@ -245,20 +258,23 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.INTEGER,
schema)
self.assertEqual('less_or_equal must be comparable.', str(error))
self.assertEqual(_('The property "less_or_equal" expects comparable '
'values.'), str(error))
def test_invalid_length(self):
schema = {'length': 'four'}
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.STRING,
schema)
self.assertEqual('length must be integer.', str(error))
self.assertEqual(_('The property "length" expects an integer.'),
str(error))
schema = {'length': 4.5}
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.STRING,
schema)
self.assertEqual('length must be integer.', str(error))
self.assertEqual(_('The property "length" expects an integer.'),
str(error))
def test_length_validate(self):
schema = {'length': 4}
@ -270,21 +286,22 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.STRING, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 'abc')
self.assertEqual('length of prop: abc must be equal to "4".',
str(error))
self.assertEqual(_('Length of value "abc" of property "prop" must '
'be equal to "4".'), str(error))
error = self.assertRaises(exception.ValidationError,
constraint.validate,
'abcde')
self.assertEqual('length of prop: abcde must be equal to "4".',
str(error))
self.assertEqual(_('Length of value "abcde" of property "prop" must '
'be equal to "4".'), str(error))
def test_invalid_min_length(self):
schema = {'min_length': 'four'}
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.STRING,
schema)
self.assertEqual('min_length must be integer.', str(error))
self.assertEqual(_('The property "min_length" expects an integer.'),
str(error))
def test_min_length_validate(self):
schema = {'min_length': 4}
@ -297,15 +314,16 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.STRING, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 'abc')
self.assertEqual('length of prop: abc must be at least "4".',
str(error))
self.assertEqual(_('Length of value "abc" of property "prop" must '
'be at least "4".'), str(error))
def test_invalid_max_length(self):
schema = {'max_length': 'four'}
error = self.assertRaises(exception.InvalidSchemaError, Constraint,
'prop', Schema.STRING,
schema)
self.assertEqual('max_length must be integer.', str(error))
self.assertEqual(_('The property "max_length" expects an integer.'),
str(error))
def test_max_length_validate(self):
schema = {'max_length': 4}
@ -319,7 +337,8 @@ class ConstraintTest(TestCase):
error = self.assertRaises(exception.ValidationError,
constraint.validate,
'abcde')
self.assertEqual('length of prop: abcde must be no greater than "4".',
self.assertEqual(_('Length of value "abcde" of property "prop" '
'must be no greater than "4".'),
str(error))
def test_pattern_validate(self):
@ -332,5 +351,5 @@ class ConstraintTest(TestCase):
constraint = Constraint('prop', Schema.STRING, schema)
error = self.assertRaises(exception.ValidationError,
constraint.validate, 'abc')
self.assertEqual('prop: "abc" does not match pattern "[0-9]*".',
str(error))
self.assertEqual(_('The value "abc" of property "prop" does not '
'match pattern "[0-9]*".'), str(error))

View File

@ -129,7 +129,8 @@ class DataTypeTest(TestCase):
self.assertIsNone(input.validate(3360))
err = self.assertRaises(exception.ValidationError, input.validate,
336000)
self.assertEqual(_('None: 336000 is out of range (min:1, max:65535).'),
self.assertEqual(_('The value "336000" of property "None" is out of '
'range "(min:1, max:65535)".'),
err.__str__())
def test_custom_datatype(self):
@ -168,7 +169,7 @@ class DataTypeTest(TestCase):
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
DataTypeTest.custom_type_def)
error = self.assertRaises(exception.TypeMismatchError, data.validate)
self.assertEqual(_('[\'Tom\', \'Jerry\'] must be of type: '
self.assertEqual(_('[\'Tom\', \'Jerry\'] must be of type '
'"tosca.my.datatypes.PeopleBase".'),
error.__str__())
@ -182,9 +183,10 @@ class DataTypeTest(TestCase):
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
DataTypeTest.custom_type_def)
error = self.assertRaises(exception.UnknownFieldError, data.validate)
self.assertEqual(_('Data value of type tosca.my.datatypes.PeopleBase '
'contain(s) unknown field: "nema", refer to the '
'definition to verify valid values.'),
self.assertEqual(_('Data value of type '
'"tosca.my.datatypes.PeopleBase" contains unknown '
'field "nema". Refer to the definition to verify '
'valid values.'),
error.__str__())
def test_default_field_in_dataentity(self):
@ -207,8 +209,9 @@ class DataTypeTest(TestCase):
DataTypeTest.custom_type_def)
error = self.assertRaises(exception.MissingRequiredFieldError,
data.validate)
self.assertEqual(_('Data value of type tosca.my.datatypes.PeopleBase '
'is missing required field: "[\'name\']".'),
self.assertEqual(_('Data value of type '
'"tosca.my.datatypes.PeopleBase" is missing '
'required field "[\'name\']".'),
error.__str__())
# the value of name field is not a string
@ -233,8 +236,8 @@ class DataTypeTest(TestCase):
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
DataTypeTest.custom_type_def)
error = self.assertRaises(exception.ValidationError, data.validate)
self.assertEqual(_('length of name: M must be at least "2".'),
error.__str__())
self.assertEqual(_('Length of value "M" of property "name" must be '
'at least "2".'), error.__str__())
# value of addresses doesn't fit the entry_schema
def test_validation_in_collection_entry(self):
@ -266,9 +269,10 @@ class DataTypeTest(TestCase):
data = DataEntity('tosca.my.datatypes.People', value,
DataTypeTest.custom_type_def)
error = self.assertRaises(exception.UnknownFieldError, data.validate)
self.assertEqual(_('Data value of type tosca.my.datatypes.ContactInfo '
'contain(s) unknown field: "contact_pone", refer '
'to the definition to verify valid values.'),
self.assertEqual(_('Data value of type '
'"tosca.my.datatypes.ContactInfo" contains unknown '
'field "contact_pone". Refer to the definition to '
'verify valid values.'),
error.__str__())
def test_datatype_in_current_template(self):

View File

@ -12,6 +12,7 @@
from toscaparser.common import exception
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
class ExceptionTest(TestCase):
@ -23,7 +24,7 @@ class ExceptionTest(TestCase):
def test_message(self):
ex = exception.MissingRequiredFieldError(what='Template',
required='type')
self.assertEqual('Template is missing required field: "type".',
self.assertEqual(_('Template is missing required field "type".'),
ex.__str__())
def test_set_flag(self):
@ -33,7 +34,7 @@ class ExceptionTest(TestCase):
def test_format_error(self):
ex = exception.UnknownFieldError(what='Template')
self.assertEqual('An unknown exception occurred.', ex.__str__(),)
self.assertEqual(_('An unknown exception occurred.'), ex.__str__(),)
self.assertRaises(KeyError, self._formate_exception)
def _formate_exception(self):

View File

@ -71,7 +71,7 @@ class IntrinsicFunctionsTest(TestCase):
'functions/test_unknown_capability_property.yaml')
exception.ExceptionCollector.assertExceptionMessage(
KeyError,
_('\'Property "unknown" not found in capability '
_('\'Property "unknown" was not found in capability '
'"database_endpoint" of node template "database" referenced '
'from node template "database".\''))
@ -91,22 +91,22 @@ class IntrinsicFunctionsTest(TestCase):
'functions/test_unknown_input_in_property.yaml')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownInputError,
_('Unknown input: objectstore_name'))
_('Unknown input "objectstore_name".'))
self.assertRaises(
exception.ValidationError, self._load_template,
'functions/test_unknown_input_in_interface.yaml')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownInputError,
_('Unknown input: image_id'))
_('Unknown input "image_id".'))
self.assertRaises(
exception.ValidationError, self._load_template,
'functions/test_invalid_function_signature.yaml')
exception.ExceptionCollector.assertExceptionMessage(
ValueError,
_("Expected one argument for get_input function but received: "
"['cpus', 'cpus']."))
_('Expected one argument for function "get_input" but received '
'"[\'cpus\', \'cpus\']".'))
def test_get_input_default_value_result(self):
mysql_dbms = self._get_node('mysql_dbms')
@ -135,7 +135,8 @@ class GetAttributeTest(TestCase):
website_url_output.value.attribute_name)
def test_get_attribute_invalid_args(self):
expected_msg = 'Expected arguments: node-template-name, attribute-name'
expected_msg = _('Expected arguments: "node-template-name", '
'"attribute-name"')
err = self.assertRaises(ValueError,
functions.get_function, None, None,
{'get_attribute': []})
@ -155,7 +156,7 @@ class GetAttributeTest(TestCase):
'functions/test_get_attribute_unknown_node_template_name.yaml')
exception.ExceptionCollector.assertExceptionMessage(
KeyError,
_('\'No such node template: unknown_node_template.\''))
_('\'Node template "unknown_node_template" was not found.\''))
def test_get_attribute_unknown_attribute(self):
self.assertRaises(
@ -163,8 +164,8 @@ class GetAttributeTest(TestCase):
'functions/test_get_attribute_unknown_attribute_name.yaml')
exception.ExceptionCollector.assertExceptionMessage(
KeyError,
_("\"Attribute 'unknown_attribute' not found in node template: "
"server.\""))
_('\'Attribute "unknown_attribute" was not found in node template '
'"server".\''))
def test_get_attribute_host_keyword(self):
tpl = self._load_template(
@ -189,9 +190,9 @@ class GetAttributeTest(TestCase):
'functions/test_get_attribute_host_not_found.yaml')
exception.ExceptionCollector.assertExceptionMessage(
ValueError,
_("get_attribute HOST keyword is used in 'server' node template "
"but tosca.relationships.HostedOn was not found in relationship "
"chain"))
_('"get_attribute: [ HOST, ... ]" was used in node template '
'"server" but "tosca.relationships.HostedOn" was not found in '
'the relationship chain.'))
def test_get_attribute_illegal_host_in_outputs(self):
self.assertRaises(
@ -199,5 +200,5 @@ class GetAttributeTest(TestCase):
'functions/test_get_attribute_illegal_host_in_outputs.yaml')
exception.ExceptionCollector.assertExceptionMessage(
ValueError,
_("get_attribute HOST keyword is not allowed within the outputs "
"section of the TOSCA template"))
_('"get_attribute: [ HOST, ... ]" is not allowed in "outputs" '
'section of the TOSCA template.'))

View File

@ -30,7 +30,7 @@ class CSARPrereqTest(TestCase):
path = os.path.join(self.base_path, "data/CSAR/csar_not_there.zip")
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('%s does not exist.') % path, str(error))
self.assertEqual(_('"%s" does not exist.') % path, str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -38,14 +38,14 @@ class CSARPrereqTest(TestCase):
path = os.path.join(self.base_path, "data/CSAR/csar_not_zip.zip")
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('%s is not a valid zip file.') % path, str(error))
self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error))
def test_url_is_zip(self):
path = "https://github.com/openstack/tosca-parser/raw/master/" \
"toscaparser/tests/data/CSAR/csar_not_zip.zip"
csar = CSAR(path, False)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('%s is not a valid zip file.') % path, str(error))
self.assertEqual(_('"%s" is not a valid zip file.') % path, str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -54,8 +54,8 @@ class CSARPrereqTest(TestCase):
"data/CSAR/csar_no_metadata_file.zip")
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('%s is not a valid CSAR as it does not contain the '
'required file "TOSCA.meta" in the folder '
self.assertEqual(_('"%s" is not a valid CSAR as it does not contain '
'the required file "TOSCA.meta" in the folder '
'"TOSCA-Metadata".') % path, str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -65,8 +65,8 @@ class CSARPrereqTest(TestCase):
"data/CSAR/csar_wrong_metadata_file.zip")
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('%s is not a valid CSAR as it does not contain the '
'required file "TOSCA.meta" in the folder '
self.assertEqual(_('"%s" is not a valid CSAR as it does not contain '
'the required file "TOSCA.meta" in the folder '
'"TOSCA-Metadata".') % path, str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -77,7 +77,7 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR '
'%s does not contain valid YAML content.') % path,
'"%s" does not contain valid YAML content.') % path,
str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -87,7 +87,7 @@ class CSARPrereqTest(TestCase):
"data/CSAR/csar_missing_metadata.zip")
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('The CSAR %s is missing the required metadata '
self.assertEqual(_('The CSAR "%s" is missing the required metadata '
'"Entry-Definitions" in '
'"TOSCA-Metadata/TOSCA.meta".') % path, str(error))
self.assertTrue(csar.temp_dir is None or
@ -99,7 +99,7 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.validate)
self.assertEqual(_('The "Entry-Definitions" file defined in the CSAR '
'%s does not exist.') % path, str(error))
'"%s" does not exist.') % path, str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -108,8 +108,8 @@ class CSARPrereqTest(TestCase):
"data/CSAR/csar_wordpress_invalid_import_path.zip")
csar = CSAR(path)
error = self.assertRaises(ImportError, csar.validate)
self.assertEqual(_('Import Definitions/wordpress.yaml is not valid'),
str(error))
self.assertEqual(_('Import "Definitions/wordpress.yaml" is not '
'valid.'), str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -119,10 +119,10 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(URLException, csar.validate)
self.assertEqual(_('Failed to reach server '
'https://raw.githubusercontent.com/openstack/'
'"https://raw.githubusercontent.com/openstack/'
'tosca-parser/master/toscaparser/tests/data/CSAR/'
'tosca_single_instance_wordpress/Definitions/'
'wordpress1.yaml. Reason is: Not Found.'),
'wordpress1.yaml". Reason is: Not Found.'),
str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -133,10 +133,10 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(ValueError, csar.validate)
self.assertTrue(
str(error) == _('The resource Scripts/WordPress/install.sh does '
str(error) == _('The resource "Scripts/WordPress/install.sh" does '
'not exist.') or
str(error) == _('The resource Scripts/WordPress/configure.sh does '
'not exist.'))
str(error) == _('The resource "Scripts/WordPress/configure.sh" '
'does not exist.'))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -146,10 +146,10 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(URLException, csar.validate)
self.assertEqual(_('The resource at '
'https://raw.githubusercontent.com/openstack/'
'"https://raw.githubusercontent.com/openstack/'
'tosca-parser/master/toscaparser/tests/data/CSAR/'
'tosca_single_instance_wordpress/Scripts/WordPress/'
'install1.sh cannot be accessed.'),
'install1.sh" cannot be accessed.'),
str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))
@ -175,7 +175,7 @@ class CSARPrereqTest(TestCase):
csar = CSAR(path)
error = self.assertRaises(ValidationError, csar.get_author)
self.assertEqual(_('The file "TOSCA-Metadata/TOSCA.meta" in the CSAR '
'%s does not contain valid YAML content.') % path,
'"%s" does not contain valid YAML content.') % path,
str(error))
self.assertTrue(csar.temp_dir is None or
not os.path.exists(csar.temp_dir))

View File

@ -13,6 +13,7 @@
from toscaparser.common import exception
from toscaparser.properties import Property
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils import yamlparser
@ -30,7 +31,7 @@ class PropertyTest(TestCase):
test_property_schema)
error = self.assertRaises(exception.InvalidTypeError,
propertyInstance.validate)
self.assertEqual('Type "Fish" is not a valid type.', str(error))
self.assertEqual(_('Type "Fish" is not a valid type.'), str(error))
def test_list(self):
test_property_schema = {'type': 'list'}
@ -44,7 +45,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', 'a',
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"a" is not a list.', str(error))
self.assertEqual(_('"a" is not a list.'), str(error))
def test_list_entry_schema(self):
test_property_schema = {'type': 'list',
@ -73,7 +74,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', [1, 'b'],
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"b" is not an integer.', str(error))
self.assertEqual(_('"b" is not an integer.'), str(error))
def test_map(self):
test_property_schema = {'type': 'map'}
@ -87,7 +88,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', 12,
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"12" is not a map.', str(error))
self.assertEqual(_('"12" is not a map.'), str(error))
def test_map_entry_schema(self):
test_property_schema = {'type': 'map',
@ -106,7 +107,7 @@ class PropertyTest(TestCase):
{'valid': True, 'contact_name': 123},
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"123" is not a boolean.', str(error))
self.assertEqual(_('"123" is not a boolean.'), str(error))
def test_boolean(self):
test_property_schema = {'type': 'boolean'}
@ -123,7 +124,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', 12,
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"12" is not a boolean.', str(error))
self.assertEqual(_('"12" is not a boolean.'), str(error))
def test_float(self):
test_property_schema = {'type': 'float'}
@ -137,7 +138,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', 12,
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('"12" is not a float.', str(error))
self.assertEqual(_('"12" is not a float.'), str(error))
def test_timestamp(self):
test_property_schema = {'type': 'timestamp'}
@ -180,7 +181,7 @@ class PropertyTest(TestCase):
propertyInstance = Property('test_property', '2015-04-115T02:59:43.1Z',
test_property_schema)
error = self.assertRaises(ValueError, propertyInstance.validate)
self.assertEqual('day is out of range for month', str(error))
self.assertEqual(_('day is out of range for month'), str(error))
def test_required(self):
test_property_schema = {'type': 'string'}

View File

@ -16,6 +16,7 @@ from toscaparser.elements.scalarunit import ScalarUnit_Size
from toscaparser.elements.scalarunit import ScalarUnit_Time
from toscaparser.nodetemplate import NodeTemplate
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils import yamlparser
@ -243,9 +244,9 @@ class GetNumFromScalarUnitSizeNegative(TestCase):
get_num_from_scalar_unit(self.UserInputUnit))
except Exception as error:
self.assertTrue(isinstance(error, ValueError))
self.assertEqual('Provided unit "qB" is not valid. The valid units'
' are [\'B\', \'GB\', \'GiB\', \'KiB\', \'MB\','
' \'MiB\', \'TB\', \'TiB\', \'kB\']',
self.assertEqual(_('The unit "qB" is not valid. Valid units are '
'"[\'B\', \'GB\', \'GiB\', \'KiB\', \'MB\', '
'\'MiB\', \'TB\', \'TiB\', \'kB\']".'),
error.__str__())
@ -260,8 +261,8 @@ class GetNumFromScalarUnitFrequencyNegative(TestCase):
get_num_from_scalar_unit(self.UserInputUnit))
except Exception as error:
self.assertTrue(isinstance(error, ValueError))
self.assertEqual('Provided unit "Jz" is not valid. The valid'
' units are [\'GHz\', \'Hz\', \'MHz\', \'kHz\']',
self.assertEqual(_('The unit "Jz" is not valid. Valid units are '
'"[\'GHz\', \'Hz\', \'MHz\', \'kHz\']".'),
error.__str__())
@ -276,7 +277,7 @@ class GetNumFromScalarUnitTimeNegative(TestCase):
get_num_from_scalar_unit(self.UserInputUnit))
except Exception as error:
self.assertTrue(isinstance(error, ValueError))
self.assertEqual('"Jz" is not a valid scalar-unit',
self.assertEqual(_('"Jz" is not a valid scalar-unit.'),
error.__str__())
@ -336,17 +337,19 @@ class ScalarUnitNegativeTest(TestCase):
if 'cpu_frequency' in props.keys():
error = self.assertRaises(exception.ValidationError,
props['cpu_frequency'].validate)
self.assertEqual('cpu_frequency: 0.05 GHz must be greater or '
'equal to "0.1 GHz".', error.__str__())
self.assertEqual(_('The value "0.05 GHz" of property '
'"cpu_frequency" must be greater than or equal '
'to "0.1 GHz".'), error.__str__())
if 'disk_size' in props.keys():
error = self.assertRaises(exception.ValidationError,
props['disk_size'].validate)
self.assertEqual('disk_size: 500 MB must be greater or '
'equal to "1 GB".', error.__str__())
self.assertEqual(_('The value "500 MB" of property "disk_size" '
'must be greater than or equal to "1 GB".'),
error.__str__())
if 'mem_size' in props.keys():
error = self.assertRaises(exception.ValidationError,
props['mem_size'].validate)
self.assertEqual('mem_size: 1 MB is out of range '
'(min:1 MiB, '
'max:1 GiB).', error.__str__())
self.assertEqual(_('The value "1 MB" of property "mem_size" is '
'out of range "(min:1 MiB, max:1 GiB)".'),
error.__str__())

View File

@ -15,6 +15,7 @@ import os
from toscaparser.common import exception
import toscaparser.shell as shell
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
class ShellTest(TestCase):
@ -29,20 +30,20 @@ class ShellTest(TestCase):
def test_missing_arg(self):
error = self.assertRaises(ValueError, shell.main, '')
err_msg = "The program requires template or CSAR file as an " \
"argument. Please refer to the usage documentation."
err_msg = _('The program requires a template or a CSAR file as an '
'argument. Please refer to the usage documentation.')
self.assertEqual(err_msg, str(error))
def test_invalid_arg(self):
error = self.assertRaises(ValueError, shell.main, 'parse me')
err_msg = "The program expects --template-file as first argument. " \
"Please refer to the usage documentation."
err_msg = _('The program expects "--template-file" as the first '
'argument. Please refer to the usage documentation.')
self.assertEqual(err_msg, str(error))
def test_template_not_exist(self):
error = self.assertRaises(
ValueError, shell.main, ['--template-file=template.txt'])
self.assertEqual('template.txt is not a valid file.', str(error))
self.assertEqual(_('"template.txt" is not a valid file.'), str(error))
def test_template_invalid(self):
arg = '--template-file=' + self.errornous_template
@ -53,4 +54,4 @@ class ShellTest(TestCase):
try:
shell.main([arg])
except Exception:
self.fail("The program raised an exception unexpectedly.")
self.fail(_('The program raised an exception unexpectedly.'))

View File

@ -412,9 +412,9 @@ class ToscaTemplateTest(TestCase):
'import.yaml')
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
None, False)
err_msg = (_("Absolute file name /toscaparser/tests/data/custom_types"
"/wordpress.yaml cannot be used for a URL-based input "
"%(tpl)s template.")
err_msg = (_('Absolute file name "/toscaparser/tests/data/custom_types'
'/wordpress.yaml" cannot be used in a URL-based input '
'template "%(tpl)s".')
% {'tpl': tosca_tpl})
exception.ExceptionCollector.assertExceptionMessage(ImportError,
err_msg)
@ -452,7 +452,7 @@ class ToscaTemplateTest(TestCase):
def test_invalid_template_file(self):
template_file = 'invalid template file'
expected_msg = ('%s is not a valid file.' % template_file)
expected_msg = (_('"%s" is not a valid file.') % template_file)
self.assertRaises(
exception.ValidationError,
ToscaTemplate, template_file, None, False)
@ -466,11 +466,11 @@ class ToscaTemplateTest(TestCase):
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
None)
err1_msg = _('The template version "tosca_simple_yaml_1" is invalid. '
'The valid versions are: "tosca_simple_yaml_1_0"')
'Valid versions are "tosca_simple_yaml_1_0".')
exception.ExceptionCollector.assertExceptionMessage(
exception.InvalidTemplateVersion, err1_msg)
err2_msg = _('Import custom_types/not_there.yaml is not valid')
err2_msg = _('Import "custom_types/not_there.yaml" is not valid.')
exception.ExceptionCollector.assertExceptionMessage(
ImportError, err2_msg)
@ -479,14 +479,14 @@ class ToscaTemplateTest(TestCase):
exception.ExceptionCollector.assertExceptionMessage(
exception.InvalidTypeError, err3_msg)
err4_msg = _('Node template wordpress contain(s) unknown field: '
'"requirement", refer to the definition to verify valid '
err4_msg = _('Node template "wordpress" contains unknown field '
'"requirement". Refer to the definition to verify valid '
'values.')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err4_msg)
err5_msg = _("\"Property: 'passwords' not found in node template: "
"mysql_database.\"")
err5_msg = _('\'Property "passwords" was not found in node template '
'"mysql_database".\'')
exception.ExceptionCollector.assertExceptionMessage(
KeyError, err5_msg)
@ -496,25 +496,24 @@ class ToscaTemplateTest(TestCase):
"data/test_invalid_section_names.yaml")
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
None)
err1_msg = _('Template contain(s) unknown field: '
'"tosca_definitions_versions", refer to the definition '
err1_msg = _('Template contains unknown field '
'"tosca_definitions_versions". Refer to the definition '
'to verify valid values.')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err1_msg)
err2_msg = _('Template contain(s) unknown field: "descriptions", '
'refer to the definition to verify valid values.')
err2_msg = _('Template contains unknown field "descriptions". '
'Refer to the definition to verify valid values.')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err2_msg)
err3_msg = _('Template contain(s) unknown field: "import", refer to '
err3_msg = _('Template contains unknown field "import". Refer to '
'the definition to verify valid values.')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err3_msg)
err4_msg = _('Template contain(s) unknown field: '
'"topology_templates", refer to the definition to verify '
'valid values.')
err4_msg = _('Template contains unknown field "topology_templates". '
'Refer to the definition to verify valid values.')
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError, err4_msg)

View File

@ -41,7 +41,7 @@ class ToscaTemplateValidationTest(TestCase):
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
exception.ExceptionCollector.assertExceptionMessage(
exception.MissingRequiredFieldError,
_('Template is missing required field: '
_('Template is missing required field '
'"tosca_definitions_version".'))
tpl_path = os.path.join(
@ -50,8 +50,8 @@ class ToscaTemplateValidationTest(TestCase):
self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
exception.ExceptionCollector.assertExceptionMessage(
exception.UnknownFieldError,
_('Template contain(s) unknown field: "node_template", refer to '
'the definition to verify valid values.'))
_('Template contains unknown field "node_template". Refer to the '
'definition to verify valid values.'))
def test_inputs(self):
tpl_snippet = '''
@ -67,9 +67,9 @@ class ToscaTemplateValidationTest(TestCase):
name, attrs = list(inputs.items())[0]
input = Input(name, attrs)
err = self.assertRaises(exception.UnknownFieldError, input.validate)
self.assertEqual(_('Input cpus contain(s) unknown field: '
'"constraint", refer to the definition to verify '
'valid values.'), err.__str__())
self.assertEqual(_('Input "cpus" contains unknown field "constraint". '
'Refer to the definition to verify valid values.'),
err.__str__())
def _imports_content_test(self, tpl_snippet, path, custom_type_def):
imports = (toscaparser.utils.yamlparser.
@ -83,7 +83,8 @@ class ToscaTemplateValidationTest(TestCase):
# omitted here for brevity
'''
path = 'toscaparser/tests/data/tosca_elk.yaml'
errormsg = _("imports keyname defined without including templates")
errormsg = _('"imports" keyname is defined without including '
'templates.')
err = self.assertRaises(exception.ValidationError,
self._imports_content_test,
tpl_snippet,
@ -97,8 +98,8 @@ class ToscaTemplateValidationTest(TestCase):
- some_definitions:
'''
path = 'toscaparser/tests/data/tosca_elk.yaml'
errormsg = _("Input tosca template is not provided with import"
" 'some_definitions' definition.")
errormsg = _('A template file name is not provided with import '
'definition "some_definitions".')
err = self.assertRaises(exception.ValidationError,
self._imports_content_test,
tpl_snippet, path, None)
@ -142,7 +143,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
- some_definitions:
file: my_defns/my_typesdefs_n.yaml
'''
errormsg = _('Input tosca template is not provided')
errormsg = _('Input tosca template is not provided.')
err = self.assertRaises(exception.ValidationError,
self._imports_content_test,
tpl_snippet, None, None)
@ -156,7 +157,7 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
- some_definitions:
file: my_defns/my_typesdefs_n.yaml
'''
errormsg = _('Duplicate Import name found some_definitions')
errormsg = _('Duplicate import name "some_definitions" was found.')
path = 'toscaparser/tests/data/tosca_elk.yaml'
err = self.assertRaises(exception.ValidationError,
self._imports_content_test,
@ -172,8 +173,8 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
namespace_uri: http://mycompany.com/ns/tosca/2.0
namespace_prefix: mycompany
'''
errormsg = _('Import of template more_definitions is missing'
' required field: "file".')
errormsg = _('Import of template "more_definitions" is missing '
'required field "file".')
path = 'toscaparser/tests/data/tosca_elk.yaml'
err = self.assertRaises(exception.MissingRequiredFieldError,
self._imports_content_test,
@ -221,8 +222,8 @@ custom_types/wordpress.yaml
namespace_uri: mycompany.com/ns/tosca/2.0
namespace_prefix: mycompany
'''
errormsg = _("namespace_uri mycompany.com/ns/tosca/2.0 is not "
"valid in import 'more_definitions' definition")
errormsg = _('namespace_uri "mycompany.com/ns/tosca/2.0" is not '
'valid in import definition "more_definitions".')
path = 'toscaparser/tests/data/tosca_elk.yaml'
err = self.assertRaises(ImportError,
self._imports_content_test,
@ -234,7 +235,8 @@ custom_types/wordpress.yaml
imports:
- some_definitions: abc.com/tests/data/tosca_elk.yaml
'''
errormsg = _('Import abc.com/tests/data/tosca_elk.yaml is not valid')
errormsg = _('Import "abc.com/tests/data/tosca_elk.yaml" is not '
'valid.')
path = 'toscaparser/tests/data/tosca_elk.yaml'
err = self.assertRaises(ImportError,
self._imports_content_test,
@ -257,8 +259,8 @@ custom_types/wordpress.yaml
except Exception as err:
self.assertTrue(
isinstance(err, exception.MissingRequiredFieldError))
self.assertEqual('Output server_address is missing required '
'field: "value".', err.__str__())
self.assertEqual(_('Output "server_address" is missing required '
'field "value".'), err.__str__())
tpl_snippet = '''
outputs:
@ -274,9 +276,9 @@ custom_types/wordpress.yaml
output.validate()
except Exception as err:
self.assertTrue(isinstance(err, exception.UnknownFieldError))
self.assertEqual('Output server_address contain(s) unknown '
'field: "descriptions", refer to the definition '
'to verify valid values.',
self.assertEqual(_('Output "server_address" contains unknown '
'field "descriptions". Refer to the definition '
'to verify valid values.'),
err.__str__())
def _custom_types(self):
@ -320,8 +322,8 @@ custom_types/wordpress.yaml
distribution: Fedora
version: 18.0
'''
expectedmessage = ('Template server is missing '
'required field: "type".')
expectedmessage = _('Template "server" is missing required field '
'"type".')
err = self.assertRaises(
exception.MissingRequiredFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -337,9 +339,9 @@ custom_types/wordpress.yaml
root_password: aaa
port: 3376
'''
expectedmessage = ('Node template mysql_dbms '
'contain(s) unknown field: "propertiessss", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_dbms" contains unknown '
'field "propertiessss". Refer to the definition '
'to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -357,9 +359,9 @@ custom_types/wordpress.yaml
requirement:
- host: server
'''
expectedmessage = ('Node template mysql_dbms '
'contain(s) unknown field: "requirement", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_dbms" contains unknown '
'field "requirement". Refer to the definition to '
'verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -380,9 +382,9 @@ custom_types/wordpress.yaml
Standard:
configure: mysql_database_configure.sh
'''
expectedmessage = ('Node template mysql_dbms '
'contain(s) unknown field: "interfac", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_dbms" contains unknown '
'field "interfac". Refer to the definition to '
'verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -403,9 +405,9 @@ custom_types/wordpress.yaml
properties:
port: { get_input: db_port }
'''
expectedmessage = ('Node template mysql_database '
'contain(s) unknown field: "capabilitiis", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_database" contains unknown '
'field "capabilitiis". Refer to the definition to '
'verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -422,9 +424,9 @@ custom_types/wordpress.yaml
implementation: files/my_db_content.txt
type: tosca.artifacts.File
'''
expectedmessage = ('Node template mysql_database '
'contain(s) unknown field: "artifactsss", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_database" contains unknown '
'field "artifactsss". Refer to the definition to '
'verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -445,9 +447,9 @@ custom_types/wordpress.yaml
Standard:
configure: mysql_database_configure.sh
'''
expectedmessage = ('Node template mysql_dbms '
'contain(s) unknown field: "propertieees", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_dbms" contains unknown '
'field "propertieees". Refer to the definition to '
'verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -473,9 +475,9 @@ custom_types/wordpress.yaml
configure: mysql_database_configure.sh
'''
expectedmessage = ('Node template mysql_database '
'contain(s) unknown field: "capabilitiiiies", '
'refer to the definition to verify valid values.')
expectedmessage = _('Node template "mysql_database" contains unknown '
'field "capabilitiiiies". Refer to the definition '
'to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -500,8 +502,8 @@ custom_types/wordpress.yaml
Standard:
configure: mysql_database_configure.sh
'''
expectedmessage = ('Type "tosca.nodes.Databases" is not '
'a valid type.')
expectedmessage = _('Type "tosca.nodes.Databases" is not '
'a valid type.')
err = self.assertRaises(
exception.InvalidTypeError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -519,8 +521,8 @@ custom_types/wordpress.yaml
create: webserver_install.sh
start: d.sh
'''
expectedmessage = ('Requirements of template webserver '
'must be of type: "list".')
expectedmessage = _('"requirements" of template "webserver" must be '
'of type "list".')
err = self.assertRaises(
exception.TypeMismatchError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -545,9 +547,9 @@ custom_types/wordpress.yaml
Standard:
configure: mysql_database_configure.sh
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "database_endpoint", '
'refer to the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "database_endpoint". '
'Refer to the definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -564,9 +566,9 @@ custom_types/wordpress.yaml
nodes: mysql_dbms
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "nodes", refer to the '
'definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "nodes". Refer to the '
'definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -592,9 +594,9 @@ custom_types/wordpress.yaml
type: tosca.relationships.ConnectsTo
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "capabilityy", refer to '
'the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "capabilityy". Refer to '
'the definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -620,9 +622,9 @@ custom_types/wordpress.yaml
type: tosca.relationships.ConnectsTo
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "relationshipppp", refer'
' to the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "relationshipppp". Refer '
'to the definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -648,9 +650,9 @@ custom_types/wordpress.yaml
type: tosca.relationships.ConnectsTo
occurences: [0, UNBOUNDED]
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "occurences", refer'
' to the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "occurences". Refer to '
'the definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -672,9 +674,9 @@ custom_types/wordpress.yaml
type: tosca.relationships.ConnectsTo
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "nod", refer'
' to the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "nod". Refer to the '
'definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -694,9 +696,9 @@ custom_types/wordpress.yaml
type: tosca.relationships.ConnectsTo
'''
expectedmessage = ('Requirements of template mysql_database '
'contain(s) unknown field: "capabilit", refer'
' to the definition to verify valid values.')
expectedmessage = _('"requirements" of template "mysql_database" '
'contains unknown field "capabilit". Refer to the '
'definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -712,7 +714,7 @@ custom_types/wordpress.yaml
capability: log_endpoint
occurrences: [0, -1]
'''
expectedmessage = ('Value of property "[0, -1]" is invalid.')
expectedmessage = _('Value of property "[0, -1]" is invalid.')
err = self.assertRaises(
exception.InvalidPropertyValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -727,7 +729,7 @@ custom_types/wordpress.yaml
capability: log_endpoint
occurrences: [a, w]
'''
expectedmessage = ('"a" is not an integer.')
expectedmessage = _('"a" is not an integer.')
err = self.assertRaises(
ValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -742,7 +744,7 @@ custom_types/wordpress.yaml
capability: log_endpoint
occurrences: -1
'''
expectedmessage = ('"-1" is not a list.')
expectedmessage = _('"-1" is not a list.')
err = self.assertRaises(
ValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -757,7 +759,7 @@ custom_types/wordpress.yaml
capability: log_endpoint
occurrences: [5, 1]
'''
expectedmessage = ('Value of property "[5, 1]" is invalid.')
expectedmessage = _('Value of property "[5, 1]" is invalid.')
err = self.assertRaises(
exception.InvalidPropertyValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -772,7 +774,7 @@ custom_types/wordpress.yaml
capability: log_endpoint
occurrences: [0, 0]
'''
expectedmessage = ('Value of property "[0, 0]" is invalid.')
expectedmessage = _('Value of property "[0, 0]" is invalid.')
err = self.assertRaises(
exception.InvalidPropertyValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -809,9 +811,9 @@ custom_types/wordpress.yaml
Standard:
configure: mysql_database_configure.sh
'''
expectedmessage = ('Capabilities of template mysql_database '
'contain(s) unknown field: "http_endpoint", '
'refer to the definition to verify valid values.')
expectedmessage = _('"capabilities" of template "mysql_database" '
'contains unknown field "http_endpoint". Refer to '
'the definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -837,9 +839,9 @@ custom_types/wordpress.yaml
distribution: Fedora
version: 18.0
'''
expectedmessage = ('Properties of template server contain(s) '
'unknown field: "os_image", refer to the '
'definition to verify valid values.')
expectedmessage = _('"properties" of template "server" contains '
'unknown field "os_image". Refer to the '
'definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -866,10 +868,9 @@ custom_types/wordpress.yaml
wp_db_port: { get_property: [ SELF, \
database_endpoint, port ] }
'''
expectedmessage = ('Interfaces of template wordpress '
'contain(s) unknown field: '
'"Standards", '
'refer to the definition to verify valid values.')
expectedmessage = _('"interfaces" of template "wordpress" contains '
'unknown field "Standards". Refer to the '
'definition to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -895,9 +896,9 @@ custom_types/wordpress.yaml
wp_db_port: { get_property: [ SELF, \
database_endpoint, port ] }
'''
expectedmessage = ('Interfaces of template wordpress contain(s) '
'unknown field: "config", refer to the definition'
' to verify valid values.')
expectedmessage = _('"interfaces" of template "wordpress" contains '
'unknown field "config". Refer to the definition '
'to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -923,9 +924,9 @@ custom_types/wordpress.yaml
wp_db_port: { get_ref_property: [ database_endpoint, \
database_endpoint, port ] }
'''
expectedmessage = ('Interfaces of template wordpress contain(s) '
'unknown field: "input", refer to the definition'
' to verify valid values.')
expectedmessage = _('"interfaces" of template "wordpress" contains '
'unknown field "input". Refer to the definition '
'to verify valid values.')
err = self.assertRaises(
exception.UnknownFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -939,9 +940,8 @@ custom_types/wordpress.yaml
properties:
device: test_device
'''
expectedmessage = ('Properties of template '
'storage_attachto is missing required field: '
'"[\'location\']".')
expectedmessage = _('"properties" of template "storage_attachto" is '
'missing required field "[\'location\']".')
rel_template = (toscaparser.utils.yamlparser.
simple_parse(tpl_snippet))['relationship_templates']
name = list(rel_template.keys())[0]
@ -958,8 +958,8 @@ custom_types/wordpress.yaml
valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
exception.ExceptionCollector.assertExceptionMessage(
exception.InvalidTemplateVersion,
(_('The template version "tosca_xyz" is invalid. The valid '
'versions are: "%s"') % valid_versions))
(_('The template version "tosca_xyz" is invalid. Valid versions '
'are "%s".') % valid_versions))
def test_node_template_capabilities_properties(self):
tpl_snippet = '''
@ -983,9 +983,8 @@ custom_types/wordpress.yaml
min_instances: 1
default_instances: 5
'''
expectedmessage = ('Properties of template server is missing '
'required field: '
'"[\'max_instances\']".')
expectedmessage = _('"properties" of template "server" is missing '
'required field "[\'max_instances\']".')
err = self.assertRaises(
exception.MissingRequiredFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -1001,8 +1000,9 @@ custom_types/wordpress.yaml
properties:
initiator: test
'''
expectedmessage = ('initiator: test is not a valid value. Expected a '
'value from "[source, target, peer]".')
expectedmessage = _('The value "test" of property "initiator" is '
'not valid. Expected a value from "[source, '
'target, peer]".')
err = self.assertRaises(
exception.ValidationError,
@ -1031,9 +1031,9 @@ custom_types/wordpress.yaml
max_instances: 3
default_instances: 5
'''
expectedmessage = ('Properties of template server : '
'default_instances value is not between'
' min_instances and max_instances')
expectedmessage = _('"properties" of template "server": '
'"default_instances" value is not between '
'"min_instances" and "max_instances".')
err = self.assertRaises(
exception.ValidationError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -1047,9 +1047,8 @@ custom_types/wordpress.yaml
properties:
maxsize: 1 GB
'''
expectedmessage = ('Properties of template server is missing '
'required field: '
'"[\'name\']".')
expectedmessage = _('"properties" of template "server" is missing '
'required field "[\'name\']".')
err = self.assertRaises(
exception.MissingRequiredFieldError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -1064,7 +1063,7 @@ custom_types/wordpress.yaml
name: test
maxsize: -1
'''
expectedmessage = ('"-1" is not a valid scalar-unit')
expectedmessage = _('"-1" is not a valid scalar-unit.')
err = self.assertRaises(
ValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -1079,7 +1078,7 @@ custom_types/wordpress.yaml
name: test
maxsize: 1 XB
'''
expectedmessage = ('"1 XB" is not a valid scalar-unit')
expectedmessage = _('"1 XB" is not a valid scalar-unit.')
err = self.assertRaises(
ValueError,
lambda: self._single_node_template_content_test(tpl_snippet))
@ -1088,7 +1087,7 @@ custom_types/wordpress.yaml
def test_special_keywords(self):
"""Test special keywords
Test that special keywords, e.g. metadata, which are not part
Test that special keywords, e.g. metadata, which are not part
of specification do not throw any validation error.
"""
tpl_snippet_metadata_map = '''

View File

@ -50,8 +50,8 @@ class UrlUtilsTest(TestCase):
def test_load_url_errors(self):
url = "http://www.badurl."
err_msg = (_('Failed to reach server %(url)s.'
' Reason is: [Errno -2] Name or service not known.')
err_msg = (_('Failed to reach server "%(url)s". Reason is: '
'[Errno -2] Name or service not known.')
% {'url': url})
err = self.assertRaises(URLException,
YAML_LOADER,

View File

@ -13,6 +13,7 @@
from toscaparser.common.exception import (
InvalidTOSCAVersionPropertyException)
from toscaparser.tests.base import TestCase
from toscaparser.utils.gettextutils import _
from toscaparser.utils.validateutils import TOSCAVersionProperty
@ -67,7 +68,7 @@ class TOSCAVersionPropertyTest(TestCase):
def test_tosca_version_property_invalid_major_version(self):
version = 'x'
exp_msg = ('Value of TOSCA version property "x" is invalid.')
exp_msg = _('Value of TOSCA version property "x" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
@ -75,19 +76,19 @@ class TOSCAVersionPropertyTest(TestCase):
def test_tosca_version_property_invalid_minor_version(self):
version = '18.x'
exp_msg = ('Value of TOSCA version property "18.x" is invalid.')
exp_msg = _('Value of TOSCA version property "18.x" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
version = '18.x.y'
exp_msg = ('Value of TOSCA version property "18.x.y" is invalid.')
exp_msg = _('Value of TOSCA version property "18.x.y" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
version = '18-2'
exp_msg = ('Value of TOSCA version property "18-2" is invalid.')
exp_msg = _('Value of TOSCA version property "18-2" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
@ -95,7 +96,7 @@ class TOSCAVersionPropertyTest(TestCase):
def test_tosca_version_property_invalid_fix_version(self):
version = '18.0.a'
exp_msg = ('Value of TOSCA version property "18.0.a" is invalid.')
exp_msg = _('Value of TOSCA version property "18.0.a" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
@ -103,13 +104,13 @@ class TOSCAVersionPropertyTest(TestCase):
def test_tosca_version_property_invalid_qualifier(self):
version = '18.0.1-xyz'
exp_msg = ('Value of TOSCA version property "18.0.1-xyz" is invalid.')
exp_msg = _('Value of TOSCA version property "18.0.1-xyz" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
version = '0.0.0.abc'
exp_msg = ('Value of TOSCA version property "0.0.0.abc" is invalid.')
exp_msg = _('Value of TOSCA version property "0.0.0.abc" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
@ -117,14 +118,15 @@ class TOSCAVersionPropertyTest(TestCase):
def test_tosca_version_property_invalid_build_version(self):
version = '18.0.1.abc-x'
exp_msg = ('Value of TOSCA version property '
'"18.0.1.abc-x" is invalid.')
exp_msg = _('Value of TOSCA version property '
'"18.0.1.abc-x" is invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())
version = '0.0.0.abc-x'
exp_msg = ('Value of TOSCA version property "0.0.0.abc-x" is invalid.')
exp_msg = _('Value of TOSCA version property "0.0.0.abc-x" is '
'invalid.')
err = self.assertRaises(InvalidTOSCAVersionPropertyException,
TOSCAVersionProperty, version)
self.assertEqual(exp_msg, err.__str__())

View File

@ -193,18 +193,18 @@ class ToscaTemplate(object):
return os.path.join(csar.temp_dir, csar.get_main_template())
else:
ExceptionCollector.appendException(
ValueError(_("%(path)s is not a valid file.")
ValueError(_('"%(path)s" is not a valid file.')
% {'path': path}))
def verify_template(self):
if ExceptionCollector.exceptionsCaught():
raise ValidationError(
message=(_('\nThe input "%(path)s" has failed validation with '
'the following error(s): \n\n\t')
message=(_('\nThe input "%(path)s" failed validation with the '
'following error(s): \n\n\t')
% {'path': self.path}) +
'\n\t'.join(ExceptionCollector.getExceptionsReport()))
else:
msg = (_('The input "%(path)s" has successfully passed '
'validation.') % {'path': self.path})
msg = (_('The input "%(path)s" successfully passed validation.') %
{'path': self.path})
log.info(msg)
print(msg)

View File

@ -48,7 +48,7 @@ class UrlUtils(object):
"""
if not UrlUtils.validate_url(url):
ExceptionCollector.appendException(
ValueError(_("Provided URL is invalid.")))
ValueError(_('"%s" is not a valid URL.') % url))
return urljoin(url, relative_path)
@staticmethod

View File

@ -128,7 +128,7 @@ class TOSCAVersionProperty(object):
if self.minor_version is None and self.build_version is None and \
value != '0':
log.warning(_('Minor version assumed "0"'))
log.warning(_('Minor version assumed "0".'))
self.version = '.'.join([value, '0'])
return value

View File

@ -37,14 +37,14 @@ def load_yaml(path, a_file=True):
else urllib2.urlopen(path)
except urllib2.URLError as e:
if hasattr(e, 'reason'):
msg = (_("Failed to reach server %(path)s. Reason is: "
"%(reason)s")
msg = (_('Failed to reach server "%(path)s". Reason is: '
'%(reason)s.')
% {'path': path, 'reason': e.reason})
ExceptionCollector.appendException(URLException(what=msg))
return
elif hasattr(e, 'code'):
msg = (_("The server %(path)s couldn\'t fulfill the request."
"Error code: %(code)s")
msg = (_('The server "%(path)s" couldn\'t fulfill the request. '
'Error code: "%(code)s".')
% {'path': path, 'code': e.code})
ExceptionCollector.appendException(URLException(what=msg))
return