示例#1
0
    def test_paid(self):
        YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token')
        YixinAccount.bind(self.another_local_account.id, 'p2p_account_1',
                          'p2p_token_1')

        order_a = HoardOrder.add(self.yixin_service.uuid.hex,
                                 self.local_account.id,
                                 decimal.Decimal('12000.0'), self.fin_order_id)
        order_b = HoardOrder.add(self.yixin_service.uuid.hex,
                                 self.another_local_account.id,
                                 decimal.Decimal('24000.12'),
                                 self.another_fin_order_id)

        assert not order_a.is_success
        assert not order_b.is_success

        order_a.mark_as_paid('102')
        assert order_a.is_success
        assert order_a.order_id == '102'
        assert not order_b.is_success

        order_a = HoardOrder.get(order_a.id_)
        order_b = HoardOrder.get(order_b.id_)
        assert order_a.is_success
        assert order_a.order_id == '102'
        assert not order_b.is_success

        order_b.mark_as_paid('101')
        assert order_b.is_success
        assert order_b.order_id == '101'
示例#2
0
    def test_amount_out_of_range(self):
        amount_range = (decimal.Decimal('5000'), decimal.Decimal('50000'))

        YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token')

        with raises(OutOfRangeError) as error:
            HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id,
                           decimal.Decimal('-1'),
                           uuid.uuid4().hex)
        assert error.value.args[0] == decimal.Decimal('-1')
        assert error.value.args[1] == amount_range

        with raises(OutOfRangeError) as error:
            HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id,
                           decimal.Decimal('4999.99'),
                           uuid.uuid4().hex)
        assert error.value.args[0] == decimal.Decimal('4999.99')
        assert error.value.args[1] == amount_range

        with raises(OutOfRangeError) as error:
            HoardOrder.add(self.yixin_service.uuid.hex, self.local_account.id,
                           decimal.Decimal('50000.01'),
                           uuid.uuid4().hex)
        assert error.value.args[0] == decimal.Decimal('50000.01')
        assert error.value.args[1] == amount_range
示例#3
0
 def test_create(self):
     YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token')
     order = HoardOrder.add(self.yixin_service.uuid.hex,
                            self.local_account.id,
                            decimal.Decimal('10000.12'),
                            uuid.uuid4().hex)
     assert order
     assert not order.is_success
     assert order.is_owner(self.local_account)
     assert order.order_amount == decimal.Decimal('10000.12')
示例#4
0
    def test_bind_once(self):
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is None

        YixinAccount.bind(self.local_account.id, *self.remote_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is not None

        assert remote_account.account_id == self.local_account.id
        assert remote_account.p2p_account == self.remote_user_info[0]
        assert remote_account.p2p_token == self.remote_user_info[1]
示例#5
0
    def test_confirmed(self):
        YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token')
        order = HoardOrder.add(self.yixin_service.uuid.hex,
                               self.local_account.id,
                               decimal.Decimal('12000.0'), self.fin_order_id)
        assert not order.is_success

        order.mark_as_paid('101')
        assert order.is_success
        assert order.status is not OrderStatus.confirmed

        order.mark_as_confirmed()
        assert order.is_success
        assert order.status is OrderStatus.confirmed
示例#6
0
def token_dump(user_alias, workdir=None):
    """Dumps API token from database."""
    account = Account.get_by_alias(user_alias)
    if not account:
        return bcolors.fail('user %r not found' % user_alias)

    workdir = os.path.expanduser(workdir or '~/.guihua')
    if not os.path.exists(workdir):
        os.makedirs(workdir)

    yixin_account = YixinAccount.get_by_local(account.id_)
    if not yixin_account:
        return bcolors.fail('%r need to bind yixin account' % user_alias)

    jsonfile_location = os.path.join(workdir, 'solar-yixin-token.json')

    if os.path.exists(jsonfile_location):
        with open(jsonfile_location) as jsonfile:
            data = json.load(jsonfile)
        if not isinstance(data, dict):
            return bcolors.fail('unexpected data')
    else:
        data = {}

    data[user_alias] = {
        'user_alias': user_alias,
        'yixin_account': yixin_account.p2p_account,
        'yixin_token': yixin_account.p2p_token,
    }

    with open(jsonfile_location, 'w') as jsonfile:
        json.dump(data, jsonfile, indent=4)

    bcolors.success('success: %s %s' % (user_alias, yixin_account.p2p_account))
示例#7
0
def hoard_yrd_withdrawing(order_id):
    """设置宜人贷提现银行卡."""
    from core.models.hoard import YixinAccount, HoardOrder

    order = HoardOrder.get(order_id)
    if order.fetch_status() != u'已转出':
        token = YixinAccount.get_by_local(order.user_id).p2p_token
        order.register_for_withdrawing(yixin.client, token)
示例#8
0
    def test_get_multi_by_date(self):
        YixinAccount.bind(self.local_account.id, 'p2p_account', 'p2p_token')
        YixinAccount.bind(self.another_local_account.id, 'p2p_account_1',
                          'p2p_token_1')

        order_a = HoardOrder.add(self.yixin_service.uuid.hex,
                                 self.local_account.id,
                                 decimal.Decimal('12000.0'),
                                 uuid.uuid4().hex)
        order_b = HoardOrder.add(self.yixin_service.uuid.hex,
                                 self.another_local_account.id,
                                 decimal.Decimal('24000.12'),
                                 uuid.uuid4().hex)

        start = datetime.now().strftime('%Y-%m')
        os = HoardOrder.gets_by_month(start)

        assert len(os) == 2
        assert order_a.id_ in [o.id_ for o in os]
        assert order_b.id_ in [o.id_ for o in os]
示例#9
0
def token_load(workdir=None):
    """Loads API token from local file."""
    workdir = os.path.expanduser(workdir or '~/.guihua')
    if not os.path.exists(workdir):
        return bcolors.fail('token not found')

    jsonfile_location = os.path.join(workdir, 'solar-yixin-token.json')
    if not os.path.exists(jsonfile_location):
        return bcolors.fail('token not found')

    with open(jsonfile_location) as jsonfile:
        data = json.load(jsonfile)

    for user_alias, item in data.iteritems():
        account = Account.get_by_alias(item['user_alias'])
        if not account:
            bcolors.fail('user %s not found' % user_alias)
            continue

        p2p_account = item['yixin_account']
        p2p_token = item['yixin_token']
        YixinAccount.bind(account.id_, p2p_account, p2p_token)

        bcolors.success('restored %s %s' % (account, p2p_account))
示例#10
0
    def test_bind_twice(self):
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account is None

        YixinAccount.bind(self.local_account.id, *self.alternative_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account.p2p_account == self.alternative_user_info[0]
        assert remote_account.p2p_token == self.alternative_user_info[1]

        # the last bound information should be overrided
        YixinAccount.bind(self.local_account.id, *self.remote_user_info)
        remote_account = YixinAccount.get_by_local(self.local_account.id)
        assert remote_account.p2p_account == self.remote_user_info[0]
        assert remote_account.p2p_token == self.remote_user_info[1]
示例#11
0
def hoard_yrd_confirming(order_id):
    """确认宜人贷订单状态"""
    from core.models.hoard import YixinAccount, HoardOrder
    from core.models.hoard.order import RemoteStatus

    order = HoardOrder.get(order_id)
    token = YixinAccount.get_by_local(order.user_id).p2p_token
    response = yixin.query.order_status(token, order.order_id, max_retry=3)
    status = RemoteStatus(response.data.status)

    if status == RemoteStatus.success:
        order.mark_as_confirmed()
    elif status == RemoteStatus.unknown:
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
    elif status == RemoteStatus.failure:
        order.mark_as_failure()
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
    else:
        raise WorkerTaskError(hoard_yrd_confirming.tube)  # let it fail
示例#12
0
def initialize_yixin():
    if hasattr(request, 'oauth'):
        g.yixin_account = YixinAccount.get_by_local(request.oauth.user.id_)
    else:
        g.yixin_account = None