当前位置: 首页>>代码示例>>Python>>正文


Python IonObject.us_phone_number方法代码示例

本文整理汇总了Python中pyon.public.IonObject.us_phone_number方法的典型用法代码示例。如果您正苦于以下问题:Python IonObject.us_phone_number方法的具体用法?Python IonObject.us_phone_number怎么用?Python IonObject.us_phone_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyon.public.IonObject的用法示例。


在下文中一共展示了IonObject.us_phone_number方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decorator_validation

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import us_phone_number [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}
                ],
#.........这里部分代码省略.........
开发者ID:shenrie,项目名称:pyon,代码行数:103,代码来源:interceptor_test.py

示例2: test_decorator_validation

# 需要导入模块: from pyon.public import IonObject [as 别名]
# 或者: from pyon.public.IonObject import us_phone_number [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
#.........这里部分代码省略.........
开发者ID:daf,项目名称:pyon,代码行数:103,代码来源:interceptor_test.py


注:本文中的pyon.public.IonObject.us_phone_number方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。