예제 #1
0
def main():
    user = Account.get_by_alias(EMAIL)
    if not user:
        user = register_without_confirm(EMAIL, 'testtest',
                                        ACCOUNT_REG_TYPE.EMAIL)
        bcolors.run(repr(user), key='zhiwang')

    # 绑定身份证和手机
    user.add_alias(MOBILE_PHONE, ACCOUNT_REG_TYPE.MOBILE)
    identity = Identity.save(user.id_, PERSON_NAME, PERSON_RICN)
    bcolors.run(repr(identity), key='zhiwang')

    # 绑定指旺帐号
    ZhiwangAccount.bind(user.id_, ZHIWANG_TOKEN)
    bcolors.run(repr(ZhiwangAccount.get_by_local(user.id_)), key='zhiwang')

    # 绑定银行卡
    bankcards = BankCardManager(user.id_)
    with patch('core.models.profile.bankcard.DEBUG', True):
        bankcard = bankcards.create_or_update(
            mobile_phone=user.mobile,
            card_number=BANKCARD_NO,
            bank_id=BANKCARD_BANK,
            city_id=BANKCARD_DIVISION[:4] + u'00',
            province_id=BANKCARD_DIVISION[:2] + u'0000',
            local_bank_name=u'')
        bcolors.run(repr(bankcard), key='zhiwang')
    bcolors.run('success: %s' % EMAIL, key='zhiwang')
예제 #2
0
def bankcard(sqlstore, redis, user):
    bankcards = BankCardManager(user.id_)
    with patch('core.models.profile.bankcard.DEBUG', True):
        return bankcards.create_or_update(
            mobile_phone='13800138000',
            card_number='6222000000000009',
            bank_id='4',  # 建设银行
            city_id='110100',  # 朝阳
            province_id='110000',  # 北京
            local_bank_name='西夏支行',
            is_default=True)
예제 #3
0
def initialize_bankcard_manager():
    if hasattr(request, 'oauth'):
        g.bankcard_manager = BankCardManager(request.oauth.user.id_)
        g.firewood_flow = FirewoodWorkflow(request.oauth.user.id_)
        g.coupon_manager = CouponManager(request.oauth.user.id_)
    else:
        g.bankcard_manager = None
예제 #4
0
def initialize():
    if not g.user:
        abort(401)
    g.bankcards = BankCardManager(g.user.id_)
    g.partner = request.args.get('partner', type=Partner)
    if not g.partner:
        abort(400)
예제 #5
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)
예제 #6
0
파일: utils.py 프로젝트: c1xfr2e/soledad
def iter_banks(user_id):

    bankcards = BankCardManager(user_id).get_all(Partner.sxb)

    def never_used(bank):
        return all(not HoarderOrder.is_bankcard_swiped(bankcard)
                   for bankcard in bankcards if bankcard.bank is bank)

    for bank in bank_collection.banks:
        if Partner.sxb not in bank.available_in:
            continue
        if never_used(bank):
            amount_limit = bank.sxblib_amount_limit[0]
        else:
            amount_limit = bank.sxblib_amount_limit[1]
        yield (bank, amount_limit)
예제 #7
0
 def bankcards(self):
     return BankCardManager(self.account_id)
예제 #8
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)
예제 #9
0
def initialize_bankcard_manager():
    if hasattr(request, 'oauth'):
        g.bankcard_manager = BankCardManager(request.oauth.user.id_)
    else:
        g.bankcard_manager = None
예제 #10
0
 def setUp(self):
     super(BankCardTest, self).setUp()
     self.local_account = self.add_account(*self.local_user_info)
     self.bankcards = BankCardManager(self.local_account.id)
예제 #11
0
class BankCardTest(BaseTestCase):

    local_user_info = ('*****@*****.**', 'foobar', 'Foo')

    def setUp(self):
        super(BankCardTest, self).setUp()
        self.local_account = self.add_account(*self.local_user_info)
        self.bankcards = BankCardManager(self.local_account.id)

    def test_create(self):
        with patch('core.models.profile.bankcard.DEBUG', True):
            b1 = BankCard.add(self.local_account.id, '13800138000',
                              '6222980000000002', '1', '440113', '440000',
                              '大望路支行', True)
            b2 = BankCard.add(self.local_account.id, '13800138001',
                              '6222980000010001', '2', '440113', '440000',
                              '西二旗支行', False)
            assert b1
            assert b2

        bank_card = BankCard.get(b1.id_)
        assert bank_card.mobile_phone == '13800138000'
        assert bank_card.card_number == '6222980000000002'
        assert bank_card.city_id == '440113'
        assert bank_card.province_id == '440000'
        assert bank_card.local_bank_name == '大望路支行'
        assert bank_card.is_default

        bank_card = BankCard.get(b2.id_)
        assert bank_card.mobile_phone == '13800138001'
        assert bank_card.card_number == '6222980000010001'
        assert bank_card.city_id == '440113'
        assert bank_card.province_id == '440000'
        assert bank_card.local_bank_name == '西二旗支行'
        assert bank_card.is_default is False

    def test_failed_to_create(self):
        with patch('core.models.profile.bankcard.DEBUG', True):
            BankCard.add(self.local_account.id, '13800138000',
                         '6222980000000002', '1', '440113', '440000', '大望路支行',
                         False)

            with raises(CardConflictError):
                BankCard.add(self.local_account.id, '13800138000',
                             '6222980000000002', '2', '440113', '440000',
                             '大望路支行', False)

            with raises(BankConflictError):
                BankCard.add(self.local_account.id, '13800138000',
                             '6222980000010001', '1', '440113', '440000',
                             '大望路支行', False)

    def test_discard(self):
        def create_bankcard_in_the_same_bank():
            return BankCard.add(self.local_account.id, '13800138000',
                                '6222980000010001', '1', '440113', '440000',
                                '大望路支行', False)

        with patch('core.models.profile.bankcard.DEBUG', True):
            bankcard = BankCard.add(self.local_account.id, '13800138000',
                                    '6222980000000002', '1', '440113',
                                    '440000', '大望路支行', False)

            with raises(BankConflictError):
                create_bankcard_in_the_same_bank()

            bankcard.discard()
            assert self.bankcards.get_all() == []
            assert self.bankcards.get_latest() is None
            assert self.bankcards.get_last_used() is None

            new_bankcard = create_bankcard_in_the_same_bank()
            assert new_bankcard

        card_ids = {c.id_ for c in self.bankcards.get_all()}
        assert bankcard.id_ not in card_ids
        assert new_bankcard.id_ in card_ids
        assert BankCard.get(bankcard.id_).status is BankCard.Status.discarded
        assert self.bankcards.get_latest().id_ == new_bankcard.id_
        assert self.bankcards.get_last_used().id_ == new_bankcard.id_

    def test_bank_card_manager(self):
        with patch('core.models.profile.bankcard.DEBUG', True):
            b1 = BankCard.add(self.local_account.id, '13800138000',
                              '6222980000000002', '1', '440113', '440000',
                              '大望路支行', False)
            b2 = BankCard.add(self.local_account.id, '13800138001',
                              '6222980000010001', '2', '440113', '440000',
                              '大望路支行', False)

        cards = self.bankcards.get_all()
        assert len(cards) == 2

        assert cards[0].mobile_phone == b1.mobile_phone
        assert cards[0].card_number == b1.card_number
        assert cards[0].local_bank_name == b1.local_bank_name

        assert cards[1].mobile_phone == b2.mobile_phone
        assert cards[1].card_number == b2.card_number
        assert cards[1].local_bank_name == b2.local_bank_name

        self.bankcards.add(mobile_phone='13800138002',
                           card_number='6222980000030009',
                           bank_id='3',
                           city_id='440113',
                           province_id='440000',
                           local_bank_name='西二旗支行',
                           is_default=False)

        cards = self.bankcards.get_all()
        assert len(cards) == 3

        assert cards[2].mobile_phone == '13800138002'
        assert cards[2].card_number == '6222980000030009'
        assert cards[2].local_bank_name == '西二旗支行'

    def test_delete_and_restore(self):
        with patch('core.models.profile.bankcard.DEBUG', True):
            b1 = BankCard.add(self.local_account.id, '13800138000',
                              '6222980000000002', '1', '440113', '440000',
                              '大望路支行', False)
            assert b1

        BankCard.delete_by_card_number('6222980000000002',
                                       self.local_account.id)
        b2 = BankCard.get(b1.id_)
        assert b2 is None

        BankCard.restore(b1.id_, self.local_account.id)
        b3 = BankCard.get(b1.id_)
        assert b3

        assert b3.mobile_phone == '13800138000'
        assert b3.card_number == '6222980000000002'
        assert b3.city_id == '440113'
        assert b3.province_id == '440000'
        assert b3.local_bank_name == '大望路支行'
예제 #12
0
파일: wallet.py 프로젝트: c1xfr2e/soledad
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)