コード例 #1
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)
コード例 #2
0
    def test_query_with_invalid_argument(self):
        with raises(ValueError) as einfo:
            WalletProfit.get_multi_by_date(self.account, None)
        assert 'datetime.date or tuple' in einfo.value.args[0]

        with raises(ValueError) as einfo:
            WalletProfit.get_multi_by_date(
                self.account, (date(2012, 1, 1), date(2010, 1, 1)))
        assert 'must less or equal' in einfo.value.args[0]
コード例 #3
0
    def test_update(self):
        profit = WalletProfit.record(self.account, Decimal(12321),
                                     date(2012, 12, 12))
        last_updated_time = profit.updated_time

        profit = WalletProfit.record(self.account, Decimal(12322),
                                     date(2012, 12, 12))
        assert profit.updated_time >= last_updated_time
        assert profit.account_id == str(self.account.id_)
        assert profit.amount == Decimal(12322)
        assert profit.date == date(2012, 12, 12)
コード例 #4
0
def profit():
    """累积收益

    :reqheader Authorization: OAuth 2.0 Bearer Token
    :status 200: 返回  :class:`.ProfitItemSchema`
    :query offset: 可选参数, 开始条数,按请求数限制返回结果.
    :query count: 可选参数, 每页数量,按请求数限制返回结果.
    """
    profit_schema = ProfitItemSchema(strict=True, many=True)
    offset = request.args.get('offset', type=int, default=0)
    count = request.args.get('count', type=int, default=20)
    ids = WalletProfit.get_ids_by_account(g.wallet_account.id_)[::-1]
    items = WalletProfit.get_multi(ids[offset:offset + count])
    return jsonify(success=True, data=profit_schema.dump(items).data)
コード例 #5
0
 def test_record_once(self):
     profit = WalletProfit.record(self.account, Decimal(12321),
                                  date(2012, 12, 12))
     assert profit.account_id == str(self.account.id_)
     assert profit.amount == Decimal(12321)
     assert profit.date == date(2012, 12, 12)
     assert profit.updated_time <= datetime.now()
コード例 #6
0
    def test_query(self):
        p1 = WalletProfit.record(self.account, Decimal(12321),
                                 date(2012, 12, 12))
        p2 = WalletProfit.record(self.account, Decimal(20), date(2012, 12, 15))

        assert WalletProfit.get_multi_by_date(self._make_account(123),
                                              date(2012, 12, 12)) == []
        assert WalletProfit.get_multi_by_date(self._make_account(123),
                                              date(2012, 12, 15)) == []
        assert WalletProfit.get_multi_by_date(self.account, date(2012, 12,
                                                                 16)) == []
        assert WalletProfit.get_multi_by_date(self.account, date(2012, 12,
                                                                 12)) == [p1]
        assert WalletProfit.get_multi_by_date(self.account, date(2012, 12,
                                                                 15)) == [p2]
        assert WalletProfit.get_multi_by_date(
            self.account,
            (date(2012, 12, 12), date(2012, 12, 15))) == [p1, p2]
        assert WalletProfit.get_multi_by_date(
            self.account,
            (date(2012, 12, 11), date(2012, 12, 16))) == [p1, p2]
        assert WalletProfit.get_multi_by_date(
            self.account, (date(2012, 12, 12), date(2012, 12, 14))) == [p1]
コード例 #7
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)
コード例 #8
0
ファイル: cron_user_profit.py プロジェクト: c1xfr2e/soledad
def main():
    for id_ in WalletAccount.get_all_ids():
        WalletProfit.synchronize_async(id_)
コード例 #9
0
 def test_get_nothing(self):
     records = WalletProfit.get_multi_by_date(self.account,
                                              date(2012, 12, 12))
     assert records == []
コード例 #10
0
ファイル: test_wallet.py プロジェクト: c1xfr2e/soledad
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))