本文整理汇总了Python中pyon.public.IonObject.get_class_decorator_value方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.get_class_decorator_value方法的具体用法?Python IonObject.get_class_decorator_value怎么用?Python IonObject.get_class_decorator_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.public.IonObject
的用法示例。
在下文中一共展示了IonObject.get_class_decorator_value方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_decorator_validation
# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import get_class_decorator_value [as 别名]
#.........这里部分代码省略.........
"dict2": {"key1": 1},
"unsigned_short_int": -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
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.unsigned_short_int = 256
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work
validate_interceptor.incoming(invoke)
# float
decorator_obj = IonObject(
"Deco_Example",
{
"list1": [1, 2],
"list2": ["One element"],
"dict1": {"key1": 1},
"dict2": {"key1": 1},
"a_float": 10.11,
"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
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.a_float = 1.234
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work
validate_interceptor.incoming(invoke)
#
# Test string pattern matching
#
decorator_obj = IonObject(
"Deco_Example",
{
"list1": [1, 2],
"list2": ["One element"],
"dict1": {"key1": 1},
"dict2": {"key1": 1},
"an_important_value": "good value",
"us_phone_number": "5555555555",
},
)
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should fail
with self.assertRaises(BadRequest):
validate_interceptor.incoming(invoke)
decorator_obj.us_phone_number = "555-555-5555"
invoke = Invocation()
invoke.message = decorator_obj
invoke.headers["validate"] = True
invoke.headers["raise-exception"] = True
# Should work
validate_interceptor.incoming(invoke)
# Check to see if the class level decorators were set properly
deco_value = decorator_obj.get_class_decorator_value("SpecialObject")
self.assertEqual(deco_value, "")
deco_value = decorator_obj.get_class_decorator_value("OriginResourceType")
self.assertEqual(deco_value, "MyObject")
deco_value = decorator_obj.get_class_decorator_value("Unknown")
self.assertEqual(deco_value, None)