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 默认值
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', )
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', )
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', )
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', )
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', )
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', )
def test_invalid_array(self): self.validator = one_of(['peas', 'carrots']) self.assertEqual( "'sweetcorn' is not in the list ['peas', 'carrots']", self.validator('sweetcorn'))
app_depends_schema = Schema({ 'services': {'type': Array(basestring), 'default': list}, 'apps': {'type': Array(basestring), 'default': list}, 'libs': {'type': Array(basestring), 'default': list} }) conditional_links_schema = Schema({ 'services': {'type': Array(basestring), 'default': list}, 'apps': {'type': Array(basestring), 'default': list}, }) host_forwarding_schema = Schema({ 'host_name': {'type': basestring}, 'host_port': {'type': int}, 'container_port': {'type': int}, 'type': {'type': basestring, 'default': 'http', 'validates': one_of('http', 'stream')} }) commands_schema = Schema({ 'always': {'type': Array(basestring), 'required': True, 'default': list}, 'once': {'type': Array(basestring), 'default': list} }) script_schema = Schema({ 'name': {'type': basestring, 'required': True}, 'description': {'type': basestring}, 'command': {'type': Array(basestring), 'required': True} }) dusty_app_compose_schema = Schema({ 'volumes': {'type': Array(basestring), 'default': list}
def test_single_validation_function(self): Schema({'some_field': {'type':int, "validates":one_of(['a', 'b'])}})
def create_baccs(self, params): bank_schema = Schema( { 'name': { 'type': basestring, 'required': True }, 'branch': { 'type': basestring, 'required': False }, 'swift_code': { 'type': basestring, 'required': True }, 'routing_number': { 'type': basestring, 'required': False }, 'bsb_code': { 'type': basestring, 'required': False }, }, strict=False) holder_schema = Schema( { 'name': { 'type': basestring, 'required': True }, 'doc_type': { 'type': basestring, 'required': False, 'validates': one_of('ID', 'PASSPORT', 'DRIVER_LICENSE', 'CI', 'BR') }, 'doc_number': { 'type': basestring, 'required': False }, 'contact': { 'type': basestring, 'required': False }, 'type': { 'type': basestring, 'required': True, 'validates': one_of('COMPANY', 'INDIVIDUAL') }, 'dob': { 'type': basestring, 'required': False }, 'country': { 'type': basestring, 'required': False }, 'address': { 'type': basestring, 'required': False }, }, strict=False) param_schema = Schema( { 'bank': { 'type': bank_schema, 'required': True }, 'country': { 'type': basestring, 'required': True }, 'currency': { 'type': basestring, 'required': True }, 'bank_account_number': { 'type': basestring, 'required': True }, 'holder': { 'type': holder_schema, 'required': True }, 'purpose': { 'type': basestring, 'required': True, 'validates': one_of('PAYER', 'BENEFICIARY') }, 'iban': { 'type': basestring, 'required': False }, }, strict=False) for bacc in params: param_schema.validate(bacc) # 检测不通过直接抛异常 param_schema.apply_defaults(bacc) # attach 默认值 return KeyVariables( params=json.dumps(params), url='account/bank_accounts', method='POST', )
def validate(value): if 'modification_date'in value and not value['modification_date'] <= value['final_date']: return 'modification_date must be less than or equal to final_date' return validate blog_post_schema = Schema({ "author": {"type": get_author_schema, "required": True}, "content": {"type": Schema({ "title": {"type": basestring, "required": True}, "text": {"type": basestring, "required": True}, "page_views": {"type": int, "default": 1} }), "required": True}, "meta": {"type": Schema({ "last_edited": {"type": datetime} }), "required": True, "nullable": True}, "category": {"type": basestring, "validates": one_of("cooking", "politics")}, "comments": {"type": Array(comment_schema), "required": True}, "likes": {"type": int, "default": 0}, "creation_date": {"type": datetime, "default": stubnow}, "tags": {"type": Array(basestring), "default": ["blog"], "validates": length(1)}, "misc": {"type": Mixed(basestring, int)}, "linked_id": {"type": Mixed(int, basestring)}, "external_code": {"type": basestring, "nullable": False}, "website": {"type": get_website_schema}, "editors": {"type": Array(lambda document: name_schema if isinstance(document, dict) else basestring)}, "latest_comment": {"type": comment_schema, "default": {}}, "most_popular_comments":{"type": Array(comment_schema), "default": [{}, {}, {}]}, "modification_date": {"type": datetime}, "final_date": {"type": datetime} }, validates=[mod_date_gt_creation_date(), mod_date_lte_final_date()])
def test_valid(self): self.validator = one_of('peas', 'carrots') self.assertIsNone(self.validator('peas')) self.assertIsNone(self.validator('carrots'))
def test_invalid_array(self): self.validator = one_of(['peas', 'carrots']) self.assertEqual("'sweetcorn' is not in the list ['peas', 'carrots']", self.validator('sweetcorn'))
}) host_forwarding_schema = Schema({ 'host_name': { 'type': basestring }, 'host_port': { 'type': int }, 'container_port': { 'type': int }, 'type': { 'type': basestring, 'default': 'http', 'validates': one_of('http', 'stream') } }) commands_schema = Schema({ 'always': { 'type': Array(basestring), 'required': True, 'default': list }, 'once': { 'type': Array(basestring), 'default': list } })
def test_valid(self): self.validator = one_of('peas', 'carrots') self.assertIsNone(self.validator('peas')) self.assertIsNone(self.validator('carrots'))
def test_single_validation_function(self): Schema({'some_field': {'type': int, "validates": one_of(['a', 'b'])}})
def __company_identification_schema(self, params): param_schema = Schema( { 'org_name': { 'type': basestring, 'required': True }, 'office_op_address': { 'type': basestring, 'required': True }, 'contact_name': { 'type': basestring, 'required': True }, 'contact_email': { 'type': basestring, 'required': True }, 'contact_phone': { 'type': basestring, 'required': True }, 'contact_country': { 'type': basestring, 'required': True }, 'contact_address': { 'type': basestring, 'required': True }, 'contact_position': { 'type': basestring, 'required': True }, 'website': { 'type': basestring, 'required': False }, 'company_type': { 'type': basestring, 'required': True, 'validates': one_of('有限责任公司 (LLC)', '股份有限公司 (INC)', '合伙人', '个人独资', '上市公司', '非政府组织/慈善机构', '国有企业') }, 'industry': { 'type': basestring, 'required': False, 'validates': one_of('旅行,运输,住宿及物流', '办公,工业,汽车以药品器械灯专用品商店', '生活方式及零售类商店', '互联网计算机及电子服务', '医疗、教育、咨询等专业服务', '商业及其他类服务', '国有企业') }, 'major_funds_source': { 'type': basestring, 'required': False, 'validates': one_of('营业收入,住宿及物流', '股东出资', '投资收益', '借款/贷款', '政府投资', '慈善捐款', '其它') }, 'year_transfer_amount': { 'type': basestring, 'required': True }, 'piece_transfer_amount': { 'type': basestring, 'required': True }, 'credit_code': { 'type': basestring, 'required': False }, 'business_code': { 'type': basestring, 'required': True }, 'business_country': { 'type': basestring, 'required': True }, 'register_country': { 'type': basestring, 'required': True }, 'issue_bearer_share': { 'type': basestring, 'required': True, 'validates': one_of('true', 'false') }, }, strict=False) param_schema.validate(params) # 检测不通过直接抛异常 param_schema.apply_defaults(params) # attach 默认值