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 __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 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',
        )
    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',
        )
    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',
        )
Example #6
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',
        )
Example #7
0
    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')
    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_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',
        )
    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',
        )
    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',
        )
Example #12
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'))
    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 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',
        )
    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',
        )
Example #16
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',
        )
    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 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',
        )
    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',
        )
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'})
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'})
    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 __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 默认值
    def evidence(self, params):

        param_schema = Schema(
            {
                'file_name': {
                    'type': basestring,
                    'required': True
                },
                'memo': {
                    'type': basestring,
                    'required': True
                },
                'transfer_no': {
                    'type': basestring,
                    'required': False
                },
                'exchange_no': {
                    'type': basestring,
                    'required': False
                },
                'deposit_no': {
                    'type': basestring,
                    'required': False
                },
                'invoice_no': {
                    'type': basestring,
                    'required': False
                },
                'iat_no': {
                    'type': basestring,
                    'required': False
                },
                'out_transfer_id': {
                    'type': basestring,
                    'required': False
                },
                'out_exchange_id': {
                    'type': basestring,
                    'required': False
                },
                'out_deposit_id': {
                    'type': basestring,
                    'required': False
                },
                'out_invoice_id': {
                    'type': basestring,
                    'required': False
                },
                'out_iat_id': {
                    'type': basestring,
                    'required': False
                },
            },
            strict=False)

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

        # 校验数据
        return KeyVariables(
            params=params,
            url='evidence',
            method='POST',
        )
Example #25
0
    def create_article(self, param):
        """ 创建 """

        param_schema = Schema({
            'id': {
                'type': basestring,
                'required': False
            },
            'no': {
                'type': basestring,
                'required': False
            },
            'author': {
                'type': basestring,
                'required': False,
                'default': 'zhuxin'
            },
            'title': {
                'type': basestring,
                'required': True
            },
            'intro': {
                'type': basestring,
                'required': False
            },
            'content': {
                'type': basestring,
                'required': True
            },
            'category': {
                'type': basestring,
                'required': False,
                'default': 'test'
            },
            'views': {
                'type': basestring,
                'required': False
            },
            'modified': {
                'type': basestring,
                'required': False
            },
        })
        param_schema.validate(param)  # 检测不通过直接抛异常
        param_schema.apply_defaults(param)  # attach 默认值

        article_param = {
            'id': param.get('id'),
            'no': param.get('no'),
            'author': param.get('author'),
            'title': param.get('title'),
            'intro': param.get('intro'),
            'content': param.get('content'),
            'category': param.get('category'),
            'views': param.get('views'),
            'modified': param.get('modified')
        }
        session = get_session()

        try:
            article = Article(**article_param)

            ar = ArticleRepository(session)
            ar.save(article)
            session.commit()
            session.close()

            return article

        except:
            traceback.print_exc()