コード例 #1
0
    def update_invoice(self, params):
        address_schema = Schema({
            'line1': {'type': basestring, 'required': True},
            'city': {'type': basestring, 'required': False},
            'state': {'type': basestring, 'required': False},
            'postal_code': {'type': basestring, 'required': False},
            'country': {'type': basestring, 'required': False},
        })

        recipient_schema = Schema({
            'dob': {'type': basestring, 'required': True},
            'entity_type': {'type': basestring, 'required': True, 'validates': one_of('INDIVIDUAL', 'COMPANY')},
            'first_name': {'type': basestring, 'required': True},
            'last_name': {'type': basestring, 'required': True},
            'document_type': {'type': basestring, 'required': True},
            'document_number': {'type': basestring, 'required': True},
            'email': {'type': basestring, 'required': False},
            'mobile': {'type': basestring, 'required': False},
            'address': {'type': address_schema, 'required': False},
            'bank_account_number': {'type': basestring, 'required': False},
            'bank_name': {'type': basestring, 'required': False},
        }, strict=False)

        unit_price_schema = Schema({
            'currency': {'type': basestring, 'required': True},
            'amount': {'type': numbers.Number, 'required': True},
        })

        products_schema = Schema({
            'name': {'type': basestring, 'required': True},
            'quantity': {'type': int, 'required': True},
            'unit_price': {'type': unit_price_schema, 'required': True}
        })

        param_schema = Schema({
            'recipient': {'type': recipient_schema, 'required': True},
            'products': {'type': Array(products_schema), 'required': True},
            'memo': {'type': basestring, 'required': False},
            'out_trade_id': {'type': basestring, 'required': False},
            'currency': {'type': basestring, 'required': True},
            'amount': {'type': numbers.Number, 'required': True},
            'ex_invoice_no': {'type': basestring, 'required': True},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=json.dumps(params),
            url='invoice',
            method='PUT',
        )
コード例 #2
0
 def test_type_can_be_another_schema(self):
     Schema({
         "author": {
             'type': Schema({
                 'first': {
                     'type': str
                 },
                 'last': {
                     'type': str
                 }
             })
         }
     })
コード例 #3
0
    def setUp(self):
        self.schema = Schema({
            'somefield': {'type': str},
            'otherfield': {'type': str},
            'anotherfield': {'type': str},

        }, validates=requires_all_or_none_of('somefield', 'otherfield'))
コード例 #4
0
 def test_array_of_strings_with_default(self):
     Schema({
         "fruit": {
             'type': Array(basestring),
             "default": ['apple', 'orange']
         }
     })
コード例 #5
0
    def setUp(self):
        self.schema = Schema({
            'somefield': {'type': str},
            'otherfield': {'type': str},
            'anotherfield': {'type': str},

        }, validates=requires_at_least_one_of('somefield', ['otherfield', 'anotherfield']))
コード例 #6
0
    def setUp(self):
        self.schema = Schema({
            'somefield': {'type': str},
            'otherfield': {'type': str},
            'anotherfield': {'type': str},

        }, validates=mutually_exclusive('somefield', ['otherfield', 'anotherfield']))
コード例 #7
0
 def test_default_schema_value_correct_2(self):
     Schema({
         'wheel': {
             'type':
             Schema({
                 'size': {
                     'type': int,
                     'default': 32
                 },
                 'brand': {
                     'type': basestring,
                     'default': 'firestone'
                 }
             }),
             'default': {}
         }
     })
コード例 #8
0
    def create_transfer(self, params):

        beneficiary_schema = Schema({
            'bank_account_number': {'type': basestring, 'required': True},
            'amount': {'type': numbers.Number, 'required': True},
            'currency': {'type': basestring, 'required': True},
        }, strict=False)

        param_schema = Schema({
            'send_amount': {'type': numbers.Number, 'required': True},
            'send_currency': {'type': basestring, 'required': True},
            'beneficiaries': {'type': Array(beneficiary_schema), 'required': True},
            'purpose': {'type': basestring, 'required': True},
            'memo': {'type': basestring, 'required': False},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=json.dumps(params),
            url='transfer',
            method='POST',
        )
コード例 #9
0
 def test_default_array_schema_value_correct_1(self):
     Schema({
         'wheel': {
             'type':
             Array(
                 Schema({
                     'size': {
                         'type': int,
                         'default': 32
                     },
                     'brand': {
                         'type': basestring,
                         'default': 'firestone'
                     }
                 })),
             'default': [{
                 'wrong': True
             }]
         }
     })
コード例 #10
0
    def __individual_identification_schema(self, params):
        param_schema = Schema(
            {
                'name': {
                    'type': basestring,
                    'required': True
                },
                'country': {
                    'type': basestring,
                    'required': True
                },
                'mobile': {
                    'type': basestring,
                    'required': True
                },
                'doc_type': {
                    'type': basestring,
                    'required': True,
                    'validates': one_of('ID', 'PASSPORT')
                },
                'doc_number': {
                    'type': basestring,
                    'required': True
                },
                'address': {
                    'type': basestring,
                    'required': True
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值
コード例 #11
0
    def get_bacc(self, params):
        param_schema = Schema(
            {
                'bank_account_number': {
                    'type': basestring,
                    'required': True
                },
                'purpose': {
                    'type': basestring,
                    'required': True,
                    'validates': one_of('PAYER', 'BENEFICIARY')
                },
                'currency': {
                    'type': basestring,
                    'required': True
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        return KeyVariables(
            params=params,
            url='account/bank_account',
            method='GET',
        )
コード例 #12
0
    def get_iats(self, params):

        param_schema = Schema(
            {
                'from_created_at': {
                    'type': basestring,
                    'required': False
                },
                'to_created_at': {
                    'type': basestring,
                    'required': False
                },
                'send_currency': {
                    'type': basestring,
                    'required': False
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='iats',
            method='GET',
        )
コード例 #13
0
    def get_deposits(self, params):
        param_schema = Schema(
            {
                'from_created_at': {
                    'type': basestring,
                    'required': True
                },
                'to_created_at': {
                    'type': basestring,
                    'required': True
                },
                'currency': {
                    'type': basestring,
                    'required': True
                },
                'status': {
                    'type': basestring,
                    'required': True,
                    'validates': one_of('CREDITED', 'PROCESSING', 'CANCELED')
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        return KeyVariables(
            params=params,
            url='deposits',
            method='GET',
        )
コード例 #14
0
    def create_exchange(self, params):

        param_schema = Schema(
            {
                'sell_amount': {
                    'type': numbers.Number,
                    'required': True
                },
                'sell_currency': {
                    'type': basestring,
                    'required': True
                },
                'buy_amount': {
                    'type': numbers.Number,
                    'required': True
                },
                'buy_currency': {
                    'type': basestring,
                    'required': True
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=json.dumps(params),
            url='exchange',
            method='POST',
        )
コード例 #15
0
ファイル: article_cls.py プロジェクト: zxins/zxins
    def __init__(self, **kwargs):
        """
        :param author:  作者
        :param title:   标题
        :param content: 内容
        :param label:   标签
        """

        param_schema = Schema({
            'id': {
                'type': basestring,
                'required': False
            },
            'no': {
                'type': basestring,
                'required': False
            },
            'author': {
                'type': basestring,
                'required': True
            },
            'title': {
                'type': basestring,
                'required': True
            },
            'intro': {
                'type': basestring,
                'required': False
            },
            'content': {
                'type': basestring,
                'required': True
            },
            'category': {
                'type': basestring,
                'required': False
            },
            'views': {
                'type': basestring,
                'required': False
            },
            'modified': {
                'type': basestring,
                'required': False
            },
        })

        param_schema.validate(kwargs)  # 检测不通过直接抛异常
        param_schema.apply_defaults(kwargs)  # attach 默认值

        self.id = kwargs.get('id')
        self.no = kwargs.get('no')
        self.author = kwargs.get('author')
        self.title = kwargs.get('title')
        self.intro = kwargs.get('intro')
        self.content = kwargs.get('content')
        self.category = kwargs.get('category')
        self.views = kwargs.get('views')
        self.modified = kwargs.get('modified')
コード例 #16
0
    def test_nested_schema_cannot_have_validation(self):
        def some_func():
            pass

        self.assert_spec_invalid(
            {
                "content": {
                    'type': Schema({"somefield": {
                        "type": int
                    }}),
                    "validates": some_func
                }
            }, 'content')
コード例 #17
0
 def setUp(self):
     self.base_schema = Schema({
         'street': {
             'type': basestring
         },
         'house_number': {
             'type': int,
             'default': 1
         }
     })
     self.bigger_schema = Schema({
         'address': {
             'type': self.base_schema,
             'default': {}
         },
         'first_name': {
             'type': basestring,
             'required': True
         },
         'last_name': {
             'type': basestring,
             'default': 'johnson'
         }
     })
コード例 #18
0
 def test_default_array_schema_value_of_incorrect_type_2(self):
     self.assert_spec_invalid(
         {
             'wheel': {
                 'type':
                 Array(
                     Schema({
                         'size': {
                             'type': int,
                             'default': 32
                         },
                         'brand': {
                             'type': basestring,
                             'default': 'firestone'
                         }
                     })),
                 'default': {}
             }
         }, 'wheel')
コード例 #19
0
    def get_transfer(self, params):

        param_schema = Schema({
            'no': {'type': basestring, 'required': True},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='transfer',
            method='GET',
        )
コード例 #20
0
    def cancel_invoice(self, params):

        param_schema = Schema({
            'no': {'type': basestring, 'required': True},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='invoice',
            method='DELETE',
        )
コード例 #21
0
    def get_rate(self, params):

        param_schema = Schema({
            'sell_currency': {'type': basestring, 'required': True},
            'buy_currency': {'type': basestring, 'required': True},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='rate',
            method='GET',
        )
コード例 #22
0
class TestRequiresAllOrNoneOf(unittest.TestCase):
    def setUp(self):
        self.schema = Schema({
            'somefield': {'type': str},
            'otherfield': {'type': str},
            'anotherfield': {'type': str},

        }, validates=requires_all_or_none_of('somefield', 'otherfield'))

    def test_valid(self):
        self.schema.validate({})
        self.schema.validate({'somefield': 'somevalue', 'otherfield': 'othervalue'})


    def test_invalid(self):
        with self.assertRaises(ValidationException):
             self.schema.validate({'otherfield': 'partialvalue'})
コード例 #23
0
    def __init__(self, **kwargs):
        # 先对参数做校验,校验不通过不生成News对象
        params_schema = Schema({
            'no': {
                'type': basestring,
                'required': False,
                'default': shortuuid.uuid().upper()
            },
            'title': {
                'type': basestring,
                'required': True
            },
            'author_name': {
                'type': basestring,
                'required': True
            },
            'url': {
                'type': basestring,
                'required': True
            },
            'date': {
                'type': basestring,
                'required': False
            },
            'pictures': {
                'type': dict,
                'required': False
            },
            'category': {
                'type': basestring,
                'required': False,
                'default': 'default'
            },  # 这里要限制类型吗?
        })

        params_schema.validate(kwargs)
        params_schema.apply_defaults(kwargs)

        self.no = kwargs.get('no')
        self.title = kwargs.get('title')
        self.author_name = kwargs.get('author_name')
        self.url = kwargs.get('url')
        self.date = kwargs.get('date')
        self.pictures = kwargs.get('pictures')
        self.category = get_category(kwargs.get('category'))
コード例 #24
0
    def get_transfers(self, params):

        param_schema = Schema({
            'from_created_at': {'type': basestring, 'required': False},
            'to_created_at': {'type': basestring, 'required': False},
            'send_currency': {'type': basestring, 'required': False},
            'receive_currency': {'type': basestring, 'required': False},
            'status': {'type': basestring, 'required': False, 'validates': one_of('RISK', 'PAYMENT', 'CONVERSION', 'DELIVERY')},
        }, strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='transfers',
            method='GET',
        )
コード例 #25
0
    def payment(self, params):

        param_schema = Schema({
            'no': {
                'type': basestring,
                'required': True
            },
        },
                              strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='exchange/payment',
            method='POST',
        )
コード例 #26
0
    def create_acc(self, params):
        param_schema = Schema(
            {
                'account': {
                    'type': basestring,
                    'required': False
                },
                'password': {
                    'type': basestring,
                    'required': False
                },
                'entity_type': {
                    'type': basestring,
                    'required': True,
                    'validates': one_of('COMPANY', 'INDIVIDUAL')
                },
                'secret': {
                    'type': basestring,
                    'required': False
                },
                'partner': {
                    'type': basestring,
                    'required': True
                },
                'callback_url': {
                    'type': basestring,
                    'required': False
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='account',
            method='POST',
        )
コード例 #27
0
    def create_deposit(self, params):
        param_schema = Schema(
            {
                'payer_bank_acc_number': {
                    'type': basestring,
                    'required': False
                },
                'payer_bank_acc_no': {
                    'type': basestring,
                    'required': False
                },
                'escrow_bank_acc_number': {
                    'type': basestring,
                    'required': False
                },
                'currency': {
                    'type': basestring,
                    'required': True
                },
                'amount': {
                    'type': basestring,
                    'required': True
                },
                'out_trade_id': {
                    'type': basestring,
                    'required': False
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='deposit',
            method='POST',
        )
コード例 #28
0
    def get_baccs(self, params):
        param_schema = Schema(
            {
                'purpose': {
                    'type': basestring,
                    'required': False,
                    'validates': one_of('PAYER', 'BENEFICIARY')
                },
                'status': {
                    'type': basestring,
                    'required': False,
                    'validates': one_of('NEW', 'APPROVED', 'PENDING', 'DENIED')
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        return KeyVariables(
            params=params,
            url='account/bank_accounts',
            method='GET',
        )
コード例 #29
0
    def escrow_accounts(self, params):

        param_schema = Schema(
            {
                'currency': {
                    'type': basestring,
                    'required': True
                },
                'country': {
                    'type': basestring,
                    'required': True
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='escrow_accounts',
            method='GET',
        )
コード例 #30
0
    def download(self, params):

        param_schema = Schema(
            {
                'from_created_at': {
                    'type': basestring,
                    'required': True
                },
                'to_created_at': {
                    'type': basestring,
                    'required': True
                },
            },
            strict=False)

        param_schema.validate(params)  # 检测不通过直接抛异常
        param_schema.apply_defaults(params)  # attach 默认值

        # 校验数据
        return KeyVariables(
            params=params,
            url='statement',
            method='GET',
        )
コード例 #31
0
 def test_multiple_validation_functions(self):
     Schema({'some_field': {'type': int, "validates": [gte(1), lte(10)]}})
コード例 #32
0
 def test_single_validation_function(self):
     Schema({'some_field': {'type': int, "validates": one_of(['a', 'b'])}})
コード例 #33
0
 def test_array_validation(self):
     Schema(
         {"fruit": {
             'type': Array(basestring),
             "validates": length(1, 2)
         }})
コード例 #34
0
 def test_array_of_ints(self):
     Schema({"numbers": {"type": Array(int)}})
コード例 #35
0
class TestMutuallyExclusive(unittest.TestCase):
    def setUp(self):
        self.schema = Schema({
            'somefield': {'type': str},
            'otherfield': {'type': str},
            'anotherfield': {'type': str},

        }, validates=mutually_exclusive('somefield', ['otherfield', 'anotherfield']))

    def test_valid(self):
        self.schema.validate({})
        self.schema.validate({'otherfield': 'partialvalue'})
        self.schema.validate({'somefield': 'somevalue'})
        self.schema.validate({'otherfield': 'othervalue', 'anotherfield': 'anothervalue'})
        self.schema.validate({'somefield': 'somevalue', 'otherfield': 'partialvalue'})


    def test_invalid(self):
        with self.assertRaises(ValidationException):
             self.schema.validate({'somefield': 'somevalue', 'otherfield': 'othervalue', 'anotherfield': 'anothervalue'})