本文整理汇总了Python中toscaparser.dataentity.DataEntity.validate方法的典型用法代码示例。如果您正苦于以下问题:Python DataEntity.validate方法的具体用法?Python DataEntity.validate怎么用?Python DataEntity.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类toscaparser.dataentity.DataEntity
的用法示例。
在下文中一共展示了DataEntity.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_built_in_datatype
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_built_in_datatype(self):
value_snippet = '''
private_network:
network_name: private
network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
addresses: [ 10.111.128.10 ]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.network.NetworkInfo',
value.get('private_network'))
self.assertIsNotNone(data.validate())
value_snippet = '''
portspec_valid:
protocol: tcp
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.network.PortSpec',
value.get('portspec_valid'))
self.assertIsNotNone(data.validate())
value_snippet = '''
portspec_invalid:
protocol: xyz
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.network.PortSpec',
value.get('portspec_invalid'))
err = self.assertRaises(exception.ValidationError, data.validate)
self.assertEqual(_('The value "xyz" of property "protocol" is not '
'valid. Expected a value from "[udp, tcp, igmp]".'
),
err.__str__())
示例2: validate_additional_req
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def validate_additional_req(properties, prop_name, custom_def=None, ):
try:
source = properties.get(PortSpec.SOURCE)
source_range = properties.get(PortSpec.SOURCE_RANGE)
target = properties.get(PortSpec.TARGET)
target_range = properties.get(PortSpec.TARGET_RANGE)
# verify one of the specified values is set
if source is None and source_range is None and \
target is None and target_range is None:
ExceptionCollector.appendException(
InvalidTypeAdditionalRequirementsError(
type=PortSpec.TYPE_URI))
# Validate source value is in specified range
if source and source_range:
validateutils.validate_value_in_range(source, source_range,
PortSpec.SOURCE)
else:
from toscaparser.dataentity import DataEntity
portdef = DataEntity('PortDef', source, None, PortSpec.SOURCE)
portdef.validate()
# Validate target value is in specified range
if target and target_range:
validateutils.validate_value_in_range(target, target_range,
PortSpec.TARGET)
else:
from toscaparser.dataentity import DataEntity
portdef = DataEntity('PortDef', source, None, PortSpec.TARGET)
portdef.validate()
except Exception:
msg = _('"%(value)s" do not meet requirements '
'for type "%(type)s".') \
% {'value': properties, 'type': PortSpec.SHORTNAME}
ExceptionCollector.appendException(
ValueError(msg))
示例3: test_range_unbounded
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_range_unbounded(self):
value_snippet = '''
temperature: [-100, 999999]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.TestLab', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())
示例4: test_built_in_datatype_without_properties
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_built_in_datatype_without_properties(self):
value_snippet = '''
2
'''
value = yamlparser.simple_parse(value_snippet)
datatype = DataType('PortDef')
self.assertEqual('integer', datatype.value_type)
data = DataEntity('PortDef', value)
self.assertIsNotNone(data.validate())
示例5: test_default_field_in_dataentity
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_default_field_in_dataentity(self):
value_snippet = '''
name: Mike
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
DataTypeTest.custom_type_def)
data = data.validate()
self.assertEqual('unknown', data.get('gender'))
示例6: test_custom_datatype
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_custom_datatype(self):
value_snippet = '''
name: Mike
gender: male
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.PeopleBase', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())
示例7: test_built_in_nested_datatype
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_built_in_nested_datatype(self):
value_snippet = '''
user_port:
protocol: tcp
target: [50000]
source: [9000]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('PortSpec', value.get('user_port'))
self.assertIsNotNone(data.validate())
示例8: test_valid_range_type
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_valid_range_type(self):
value_snippet = '''
user_port:
protocol: tcp
target_range: [20000, 60000]
source_range: [1000, 3000]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('PortSpec', value.get('user_port'))
self.assertIsNotNone(data.validate())
示例9: test_functions_datatype
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_functions_datatype(self):
value_snippet = '''
admin_credential:
user: username
token: { get_input: password }
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.Credential',
value.get('admin_credential'))
self.assertIsNotNone(data.validate())
示例10: test_valid_ranges_against_constraints
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_valid_ranges_against_constraints(self):
# The TestLab range type has max=UNBOUNDED
value_snippet = '''
temperature1: [-255, 999999]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.TestLab', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())
# The TestLab range type has min=UNBOUNDED
value_snippet = '''
temperature2: [-999999, 255]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.TestLab', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())
示例11: test_built_in_datatype
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_built_in_datatype(self):
value_snippet = '''
private_network:
network_name: private
network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
addresses: [ 10.111.128.10 ]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.network.NetworkInfo',
value.get('private_network'))
self.assertIsNotNone(data.validate())
示例12: test_built_in_datatype_with_short_name
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_built_in_datatype_with_short_name(self):
value_snippet = '''
ethernet_port:
port_name: port1
port_id: 2c0c7a37-691a-23a6-7709-2d10ad041467
network_id: 3e54214f-5c09-1bc9-9999-44100326da1b
mac_address: f1:18:3b:41:92:1e
addresses: [ 172.24.9.102 ]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('PortInfo', value.get('ethernet_port'))
self.assertIsNotNone(data.validate())
示例13: test_range_unbounded
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_range_unbounded(self):
value_snippet = '''
humidity: [-100, 100]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.TestLab',
value, DataTypeTest.custom_type_def)
err = self.assertRaises(exception.InvalidSchemaError,
lambda: data.validate())
self.assertEqual(_('The property "in_range" expects comparable values.'
),
err.__str__())
示例14: test_port_spec_addl_reqs
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_port_spec_addl_reqs(self):
value_snippet = '''
test_port:
protocol: tcp
target: 65535
target_range: [ 1, 65535 ]
source: 1
source_range: [ 1, 65535 ]
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.datatypes.network.PortSpec',
value.get('test_port'))
self.assertIsNotNone(data.validate())
示例15: test_custom_datatype_with_parent
# 需要导入模块: from toscaparser.dataentity import DataEntity [as 别名]
# 或者: from toscaparser.dataentity.DataEntity import validate [as 别名]
def test_custom_datatype_with_parent(self):
value_snippet = '''
name: Mike
gender: male
contacts:
- {contact_name: Tom,
contact_email: [email protected],
contact_phone: '123456789'}
- {contact_name: Jerry,
contact_email: [email protected],
contact_phone: '321654987'}
'''
value = yamlparser.simple_parse(value_snippet)
data = DataEntity('tosca.my.datatypes.People', value,
DataTypeTest.custom_type_def)
self.assertIsNotNone(data.validate())