本文整理汇总了Python中pyon.public.IonObject.list1方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.list1方法的具体用法?Python IonObject.list1怎么用?Python IonObject.list1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.public.IonObject
的用法示例。
在下文中一共展示了IonObject.list1方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decorator_validation
# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import list1 [as 别名]
def test_decorator_validation(self):
#
# Test required values
#
validate_interceptor = ValidateInterceptor()
validate_interceptor.configure({"enabled": True})
decorator_obj = IonObject(
"Deco_Example",
{
"list1": [1],
"list2": ["One element"],
"dict1": {"key1": 1},
"dict2": {"key1": 1},
"us_phone_number": "555-555-5555",
},
)
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["raise-exception"] = True
invoke.headers["validate"] = True
# Should fail because required field not set
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.an_important_value = {"key": "value"}
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work now that we have set a value for the required field
validate_interceptor.incoming(invoke)
#
# Test collection content types validation
#
# List
decorator_obj = IonObject(
"Deco_Example",
{
"list1": ["Should be a numeric type"],
"list2": ["One element"],
"dict1": {"key1": 1},
"dict2": {"key1": 1},
"an_important_value": "good value",
"us_phone_number": "555-555-5555",
},
)
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should fail because list contains non-numeric value
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.list1 = [1, 2]
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work now that list content has been corrected
validate_interceptor.incoming(invoke)
# Validate with an ION object as content
decorator_obj = IonObject(
"Deco_Example",
{
"list1": [{"phone_number": "858.822.5141", "phone_type": "work", "type_": "Phone", "sms": False}],
"list2": ["One element"],
"dict1": {"key1": 1},
"dict2": {"key1": 1},
"an_important_value": "good value",
"us_phone_number": "555-555-5555",
},
)
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work now that list content has been corrected
validate_interceptor.incoming(invoke)
# Validate with an ION object as content
decorator_obj = IonObject(
"Deco_Example",
{
"list1": [
{"phone_number": "858.822.5141", "phone_type": "work", "type_": "ExtendedPhone", "sms": False}
],
#.........这里部分代码省略.........
示例2: test_decorator_validation
# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import list1 [as 别名]
def test_decorator_validation(self):
#
# Test required values
#
validate_interceptor = ValidateInterceptor()
validate_interceptor.configure({"enabled": True})
decorator_obj = IonObject('Deco_Example', {"list1": [1], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "us_phone_number": "555-555-5555"})
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should fail because required field not set
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.an_important_value = {"key": "value"}
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should work now that we have set a value for the required field
validate_interceptor.incoming(invoke)
#
# Test collection content types validation
#
# List
decorator_obj = IonObject('Deco_Example', {"list1": ["Should be a numeric type"], "list2": ["One element"], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should fail because list contains non-numeric value
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.list1 = [1, 2]
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should work now that list content has been corrected
validate_interceptor.incoming(invoke)
# Dict
decorator_obj = IonObject('Deco_Example', {"list1": [1], "list2": ["One element"], "dict1": {"key1": "Should be a numeric type"}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should fail because dict value contains non-numeric value
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.dict1 = {"key1": 1}
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should work now that dict value content has been corrected
validate_interceptor.incoming(invoke)
#
# Test collection length
#
# List
decorator_obj = IonObject('Deco_Example', {"list1": [1,2], "list2": [], "dict1": {"key1": 1}, "dict2": {"key1": 1}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should fail since list has zero length
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.list2 = ["Item 1", "Item 2"]
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should work new that item length of list has been corrected
validate_interceptor.incoming(invoke)
# Dict
decorator_obj = IonObject('Deco_Example', {"list1": [1,2], "list2": [1,2], "dict1": {"key1": 1}, "dict2": {}, "an_important_value": "good value", "us_phone_number": "555-555-5555"})
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
# Should fail since dict has zero length
#.........这里部分代码省略.........