Пример #1
0
 def test_get_or_add(self):
     assert not WalletAccount.get_by_local_account(self.user, self.provider)
     assert WalletAccount.get_or_add(self.user, self.provider)
     assert (WalletAccount.get_or_add(
         self.user,
         self.provider) == WalletAccount.get_or_add(self.user,
                                                    self.provider))
Пример #2
0
    def test_add_and_get(self):
        account = WalletAccount.add(self.user, self.provider)

        assert account.account_id == self.user.id_
        assert account.secret_id == 'e9xcSDzt_92jl5ZVyToEDQ=='
        assert len(account.secret_token) == 32
        assert account.creation_time <= datetime.now()
        assert account.service_provider == self.provider
        assert account.local_account == self.user

        assert WalletAccount.get_by_local_account(self.user,
                                                  self.provider) == account
Пример #3
0
    def test_status(self):
        account = WalletAccount.add(self.user, self.provider)
        assert account.status is WalletAccount.Status.raw

        account.transfer_status(WalletAccount.Status.success)
        assert account.status is WalletAccount.Status.success
        account = WalletAccount.get(account.id_)
        assert account.status is WalletAccount.Status.success

        account.transfer_status(WalletAccount.Status.failure)
        assert account.status is WalletAccount.Status.failure
        account = WalletAccount.get(account.id_)
        assert account.status is WalletAccount.Status.failure
Пример #4
0
def get_active_accounts_by_date(date):
    sql = ('select distinct(account_id) from wallet_transaction'
           ' where date(creation_time)=%s')
    params = (date, )
    rs = db.execute(sql, params)
    for r in rs:
        yield WalletAccount.get(r[0])
Пример #5
0
def wallet_profit_syncronizer(wallet_account_id):
    """更新零钱包用户收益."""
    from core.models.wallet.account import WalletAccount
    from core.models.wallet.profit import WalletProfit

    wallet_account = WalletAccount.get(wallet_account_id)
    if wallet_account.status is not WalletAccount.Status.success:
        return
    WalletProfit.synchronize(zslib.client, wallet_account, days=3)
Пример #6
0
 def prepare_profile():
     if not login_required:
         return
     if not g.user:
         return redirect(url_for('accounts.login.login', next=request.path))
     g.bankcards = BankCardManager(g.user.id_)
     g.bind_cards = [
         card for card in g.bankcards.get_all()
         if is_bound_bankcard(card, zhongshan)
     ]
     g.wallet_provider = zhongshan
     g.wallet_account = WalletAccount.get_or_add(g.user, g.wallet_provider)
Пример #7
0
def asset_profile():
    """用户资产概况

    :reqheader Authorization: OAuth 2.0 Bearer Token
    :reqheader If-None-Match: 客户端缓存的 ETag
    :resheader ETag: 客户端可缓存的 ETag
    :status 304: 客户端缓存未过期, 无需返回数据
    :status 200: 返回 :class:`.AssetProfile`
    """
    savings_manager = SavingsManager(request.oauth.user.id_)
    hoard_total = savings_manager.total_invest_amount
    hoard_daily_profit = savings_manager.daily_profit
    hoard_yesterday_profit = savings_manager.yesterday_profit

    wallet_total = 0
    wallet_yesterday_profit = 0
    wallet_account = WalletAccount.get_by_local_account(request.oauth.user, zhongshan)
    if wallet_account:
        dashboard = UserDashboard.today(wallet_account)
        wallet_total = dashboard.balance
        wallet_yesterday_profit = dashboard.latest_profit_amount

    profile = {
        'total_amount': float(hoard_total) + float(wallet_total),
        'total_yesterday_profit': float(hoard_yesterday_profit) + float(wallet_yesterday_profit),
        'hoard_amount': hoard_total,
        'hoard_daily_profit': hoard_daily_profit,
        'hoard_yesterday_profit': hoard_yesterday_profit,
        'wallet_amount': wallet_total,
        'wallet_yesterday_profit': wallet_yesterday_profit
    }

    conditional_for([
        unicode(profile['total_amount']),
        unicode(profile['total_yesterday_profit']),
        unicode(profile['hoard_amount']),
        unicode(profile['hoard_daily_profit']),
        unicode(profile['hoard_yesterday_profit']),
        unicode(profile['wallet_amount']),
        unicode(profile['wallet_yesterday_profit'])
    ])

    schema = AssetProfile()
    return jsonify(success=True, data=schema.dump(profile).data)
Пример #8
0
def generate_fake_transactions():
    user = Account.get_by_alias('*****@*****.**')
    if not user:
        return
    with patch('core.models.profile.bankcard.DEBUG', True):
        b1 = BankCard.add(
            user_id=user.id_,
            mobile_phone='13800138000',
            card_number='6222000000000009',
            bank_id='4',  # 建设银行
            city_id='110100',  # 朝阳
            province_id='110000',  # 北京
            local_bank_name='西夏支行',
            is_default=True)
        b2 = BankCard.add(
            user_id=user.id_,
            mobile_phone='13800138000',
            card_number='6222000000010008',
            bank_id='10002',  # 中信银行
            city_id='110100',  # 朝阳
            province_id='110000',  # 北京
            local_bank_name='天龙寺支行',
            is_default=True)

    bcolors.run(repr(b1), key='wallet')
    bcolors.run(repr(b2), key='wallet')

    wallet_account = WalletAccount.get_or_add(user, zhongshan)
    t1 = WalletTransaction.add(
        wallet_account, b1, decimal.Decimal('40'),
        WalletTransaction.Type.purchase, uuid.uuid4().hex, WalletTransaction.Status.failure)
    t2 = WalletTransaction.add(
        wallet_account, b1, decimal.Decimal('42'),
        WalletTransaction.Type.purchase, uuid.uuid4().hex, WalletTransaction.Status.success)
    t3 = WalletTransaction.add(
        wallet_account, b2, decimal.Decimal('10'),
        WalletTransaction.Type.redeeming, uuid.uuid4().hex, WalletTransaction.Status.success)

    bcolors.run(repr(t1), key='wallet')
    bcolors.run(repr(t2), key='wallet')
    bcolors.run(repr(t3), key='wallet')
Пример #9
0
def mine():
    # 攒钱助手
    savings_manager = SavingsManager(g.user.id_)
    savings_products = ZhiwangProduct.get_all()

    vendor = Vendor.get_by_name(Provider.sxb)
    sxb_products = Product.get_products_by_vendor_id(vendor.id_)
    xm_products = XMFixedDuedayProduct.get_all()

    # 零钱包
    wallet_dashboard = PublicDashboard.today()
    wallet_account = WalletAccount.get_by_local_account(g.user, zhongshan)
    if wallet_account:
        wallet_profile = UserDashboard.today(wallet_account)
        wallet_has_transaction = bool(
            WalletTransaction.get_ids_by_account(wallet_account.id_))
    else:
        wallet_profile = None
        wallet_has_transaction = False

    # 规划书
    report = Report.get_latest_by_plan_id(g.plan.id) if g.plan else None

    if not (report and report.status >= REPORT_STATUS.interdata):
        return render_template('/mine/center_unplanned.html', **locals())

    if int(report.formula_ver) < int(FORMULA_VER):
        regen_log(report, 'start regenerate inter data')
        cal_intermediate_data(report, force=True, log=regen_log)
        report.update_formula_ver(FORMULA_VER)
        regen_log(report,
                  'success regenerate inter data FV:%s' % report.formula_ver)

    inter_data = report.inter_data
    locals().update(inter_data)

    cur_path = 'center'
    return render_template('/mine/center.html', **locals())
Пример #10
0
    def test_create_failure(self, zslib, uuid):
        self._add_identity_for_users()

        class TestingException(Exception):
            pass

        # calls with exception
        zslib.create_account.side_effect = TestingException()
        flow = CreateAccountFlow(self.user.id_, self.bankcard.id_)
        with raises(TestingException):
            flow.create_account('10010')
        assert zslib.create_account.called

        # check failure
        wallet_account = WalletAccount.get_by_local_account(
            self.user, flow.provider)
        assert wallet_account.status is WalletAccount.Status.failure
        assert flow.need_to_create()

        # retry
        zslib.create_account.side_effect = None
        wallet_account = flow.create_account('10010')
        assert wallet_account.status is WalletAccount.Status.success
        assert not flow.need_to_create()
Пример #11
0
 def test_get_nothing(self):
     assert not WalletAccount.get(42)
     assert not WalletAccount.get_by_local_account(self.user, self.provider)
Пример #12
0
def generate_fake_profits():
    user = Account.get_by_alias('*****@*****.**')
    wallet_account = WalletAccount.get_or_add(user, zhongshan)
    yesterday = datetime.date.today() - datetime.timedelta(days=1)
    WalletProfit.record(wallet_account, decimal.Decimal('1.2'), yesterday)
Пример #13
0
def main():
    for id_ in WalletAccount.get_all_ids():
        WalletProfit.synchronize_async(id_)
Пример #14
0
def profit(sqlstore, redis, user):
    wallet_account = WalletAccount.get_or_add(user, zhongshan)
    return WalletProfit.record(wallet_account, Decimal('1.2'),
                               date(2015, 10, 19))
Пример #15
0
def initialize_managers():
    if hasattr(request, 'oauth'):
        g.bankcards = BankCardManager(request.oauth.user.id_)
        g.wallet_provider = zhongshan
        g.wallet_account = WalletAccount.get_or_add(
            request.oauth.user, g.wallet_provider)
Пример #16
0
def initialize_managers():
    if not g.user:
        abort(401)
    g.bankcards = BankCardManager(g.user.id_)
    g.wallet_provider = zhongshan
    g.wallet_account = WalletAccount.get_or_add(g.user, g.wallet_provider)
Пример #17
0
 def test_all_ids(self):
     account = WalletAccount.add(self.user, self.provider)
     assert WalletAccount.get_all_ids() == [account.id_]
Пример #18
0
 def wallet_account(self):
     return WalletAccount.get(self.wallet_account_id)