123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- from hypothesis import given, strategies as st
- from apilib.monetary import RMB
- from apilib.utils_datetime import generate_timestamp_ex
- from apps.web.agent.define import AGENT_INCOME_TYPE
- from apps.web.agent.models import Agent
- ###
- ### Withdraw related
- ###
- @given(income_type = st.sampled_from(
- [AGENT_INCOME_TYPE.AD,
- AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)))
- def test_agent_incr_fund(agent_no_customized, source_key, income_type, amount):
- # type:(Agent, str, str, [int, float])->None
- """
- :return:
- """
- added = RMB(amount)
- desired_balance = agent_no_customized.sub_balance(income_type, source_key) + added
- desired_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- agent_no_customized.incr_fund(income_type, source_key, added)
- assert agent_no_customized.reload().sub_balance(income_type, source_key) == desired_balance
- assert agent_no_customized.reload().sub_frozen_balance(income_type, source_key) == desired_frozen_balance
- ###
- ### Withdraw related
- ###
- @given(income_type = st.sampled_from(
- [AGENT_INCOME_TYPE.AD,
- AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)))
- def test_agent_decr_fund(agent_no_customized, source_key, income_type, amount):
- # type:(Agent, str, str, [int, float])->None
- """
- :return:
- """
- agent_no_customized.set_balance(income_type, source_key, RMB('23456'))
- agent_no_customized.reload()
- sub = RMB(amount)
- desired_balance = agent_no_customized.sub_balance(income_type, source_key) - sub
- desired_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- agent_no_customized.decr_fund(income_type, source_key, sub)
- assert agent_no_customized.reload().sub_balance(income_type, source_key) == desired_balance
- assert agent_no_customized.reload().sub_frozen_balance(income_type, source_key) == desired_frozen_balance
- ###
- ### Withdraw related
- ###
- @given(income_type = st.sampled_from(
- [AGENT_INCOME_TYPE.AD,
- AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)))
- def test_agent_set_balance(agent_no_customized, source_key, income_type, amount):
- # type:(Agent, str, str, [int, float])->None
- """
- :return:
- """
- money = RMB(amount)
- desired_balance = money
- desired_frozen_balance = RMB(0)
- agent_no_customized.set_balance(income_type, source_key, money)
- assert agent_no_customized.reload().sub_balance(income_type, source_key) == desired_balance
- assert agent_no_customized.reload().sub_frozen_balance(income_type, source_key) == desired_frozen_balance
- @given(income_type = st.sampled_from(
- [AGENT_INCOME_TYPE.AD,
- AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)),
- initial_amount = st.one_of(st.floats(min_value = 1000, max_value = 10000),
- st.integers(min_value = 1000, max_value = 10000)))
- def test_agent_recover_freeze_balance(agent_no_customized, source_key, income_type, amount, initial_amount):
- # type:(Agent, str, str, [int, float], [int, float])->None
- initial = RMB(initial_amount)
- agent_no_customized.set_balance(income_type, source_key, initial)
- agent_no_customized.reload()
- withdrawed = RMB(amount)
- transaction_id = str(generate_timestamp_ex())
- before_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- before_balance = agent_no_customized.sub_balance(income_type, source_key)
- agent_no_customized.freeze_balance(income_type, withdrawed, source_key, transaction_id, True)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) - withdrawed == before_frozen_balance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == before_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert exists
- agent_no_customized.freeze_balance(income_type, withdrawed, source_key, transaction_id, True)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) - withdrawed == before_frozen_balance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == before_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert exists
- agent_no_customized.recover_frozen_balance(income_type, withdrawed, source_key, transaction_id)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- assert agent_no_customized.sub_balance(income_type, source_key) == before_balance
- assert agent_no_customized.sub_balance(income_type, source_key) == initial
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert not exists
- agent_no_customized.recover_frozen_balance(income_type, withdrawed, source_key, transaction_id)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- assert agent_no_customized.sub_balance(income_type, source_key) == before_balance
- assert agent_no_customized.sub_balance(income_type, source_key) == initial
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert not exists
- @given(income_type = st.sampled_from(
- [AGENT_INCOME_TYPE.AD,
- AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)),
- initial_amount = st.one_of(st.floats(min_value = 1000, max_value = 10000),
- st.integers(min_value = 1000, max_value = 10000)))
- def test_agent_clear_freeze_balance(agent_no_customized, source_key, income_type, amount, initial_amount):
- # type:(Agent, str, str, [int, float], [int, float])->None
- initial = RMB(initial_amount)
- agent_no_customized.set_balance(income_type, source_key, initial)
- agent_no_customized.reload()
- withdrawed = RMB(amount)
- transaction_id = str(generate_timestamp_ex())
- pre_frozenBalance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- pre_balance = agent_no_customized.sub_balance(income_type, source_key)
- agent_no_customized.freeze_balance(income_type, withdrawed, source_key, transaction_id, True)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) - withdrawed == pre_frozenBalance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == pre_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert exists
- agent_no_customized.freeze_balance(income_type, withdrawed, source_key, transaction_id, True)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) - withdrawed == pre_frozenBalance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == pre_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert exists
- agent_no_customized.clear_frozen_balance(transaction_id)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) == pre_frozenBalance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == pre_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert not exists
- agent_no_customized.clear_frozen_balance(transaction_id)
- agent_no_customized.reload()
- assert agent_no_customized.sub_frozen_balance(income_type, source_key) == pre_frozenBalance
- assert agent_no_customized.sub_balance(income_type, source_key) + withdrawed == pre_balance
- exists = False
- for item in agent_no_customized.inhandWithdrawList:
- if transaction_id == item['transaction_id']:
- exists = True
- break
- assert not exists
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)))
- # def test_agent_withdraw_with_wechat(mocker, agent_no_customized, income_type, gateway_key, amount,
- # agent_no_customized_client):
- # # type: (MockFixture, Agent, str, str, Union[int, float], RequestTestClient)->None
- #
- # money = RMB(amount)
- #
- # desired_balance = agent_no_customized.sub_balance(income_type, gateway_key)
- # assert agent_no_customized.incr_fund(income_type, gateway_key, money), 'balance inc failed'
- #
- # agent_no_customized.reload()
- #
- # desired_service_fee = money * (Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO / Const.WITHDRAW_FEE_UNIT)
- # desired_actual_pay = money - desired_service_fee
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(money),
- # 'sourceType': income_type,
- # 'sourceId': gateway_key
- # }
- #
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_changes', return_value = WECHAT_WITHDRAW_SUCCEEDED)
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # agent_no_customized.reload()
- #
- # assert desired_balance == agent_no_customized.sub_balance(income_type, gateway_key)
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 1
- # assert json_response['description'] == u'提现成功'
- #
- # withdraw_record_id = json_response['payload']['paymentId']
- #
- # record = WithdrawRecord.objects(id = str(withdraw_record_id)).first() # type: WithdrawRecord
- # assert record
- # assert record.serviceFee == desired_service_fee
- # assert record.actualPay == desired_actual_pay
- # assert record.amount == money
- # assert record.ownerId == str(agent_no_customized.id)
- # assert record.payType == WITHDRAW_PAY_TYPE.WECHAT
- # assert record.balance == (desired_balance + money)
- # assert record.withdrawGatewayKey == gateway_key
- # assert record.status == WithdrawStatus.SUCCEEDED
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # amount = st.one_of(st.floats(min_value = 0.01, max_value = settings.WITHDRAW_MINIMUM - 0.01),
- # st.integers(min_value = 1, max_value = settings.WITHDRAW_MINIMUM - 1)))
- # def test_agent_withdraw_with_wechat_less_min(mocker, agent_no_customized, income_type, source_key, amount,
- # agent_no_customized_client):
- # # type: (MockFixture, Agent, str, str, Union[int, float], RequestTestClient)->None
- # money = RMB(amount)
- #
- # pre_balance = agent_no_customized.sub_balance(income_type, source_key)
- # assert agent_no_customized.incr_fund(income_type, source_key, money), 'balance inc failed'
- # added_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(money),
- # 'sourceType': income_type,
- # 'sourceId': source_key
- # }
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 0
- # assert json_response['description'] == u"提现金额不能少于%s元" % (settings.WITHDRAW_MINIMUM,)
- #
- # assert added_balance == agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # amount = st.one_of(
- # st.floats(min_value = settings.WITHDRAW_MAXIMUM + 0.01, max_value = settings.WITHDRAW_MAXIMUM + 10),
- # st.integers(min_value = settings.WITHDRAW_MAXIMUM + 1, max_value = settings.WITHDRAW_MAXIMUM + 10)))
- # def test_agent_withdraw_with_wechat_more_max(mocker, agent_no_customized, income_type, source_key, amount,
- # agent_no_customized_client):
- # # type: (MockFixture, Agent, str, str, Union[int, float], RequestTestClient)->None
- # money = RMB(amount)
- #
- # pre_balance = agent_no_customized.sub_balance(income_type, source_key)
- # assert agent_no_customized.incr_fund(income_type, source_key, money), 'balance inc failed'
- # added_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # from apps.web.dealer.views import dealerWithdraw
- # url = url_fn(dealerWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(money),
- # 'sourceType': income_type,
- # 'sourceId': source_key
- # }
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 0
- # assert json_response['description'] == u"单次提现金额不得大于%s元" % (settings.WITHDRAW_MAXIMUM,)
- #
- # assert added_balance == agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]))
- # def test_agent_withdraw_with_wechat_less_balance(mocker, agent_no_customized, income_type, source_key, agent_no_customized_client):
- # # type: (MockFixture, Agent, str, str, RequestTestClient)->None
- # withdrawed = RMB(20)
- #
- # agent_no_customized.set_balance(income_type, source_key, RMB(10))
- # pre_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # assert pre_balance == RMB(10)
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(withdrawed),
- # 'sourceType': income_type,
- # 'sourceId': source_key
- # }
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 0
- # assert json_response['description'] == u"余额不足"
- #
- # assert pre_balance == agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # test_id = st.integers(min_value = 0, max_value = len(WECHAT_WITHDRAW_ERROR) - 1))
- # def test_agent_withdraw_via_wechat_error(mocker, agent_no_customized, income_type, source_key,
- # agent_no_customized_client, test_id):
- # # type: (MockFixture, Agent, str, str, RequestTestClient, int)->None
- # """
- # 测试提现到微信失败的场景
- # """
- # desired_result = WECHAT_WITHDRAW_ERROR[test_id]['result']
- # if 'remarks' in WECHAT_WITHDRAW_ERROR[test_id]:
- # desired_remarks = WECHAT_WITHDRAW_ERROR[test_id]['remarks']
- # else:
- # desired_remarks = u'{err_code_des}({err_code})'.format(
- # err_code = WECHAT_WITHDRAW_ERROR[test_id]['err_code'],
- # err_code_des = WECHAT_WITHDRAW_ERROR[test_id][
- # 'err_code_des'])
- #
- # if 'show_message' in WECHAT_WITHDRAW_ERROR[test_id]:
- # desired_show_message = WECHAT_WITHDRAW_ERROR[test_id]['show_message']
- # else:
- # desired_show_message = WECHAT_WITHDRAW_ERROR[test_id]['err_code_des']
- #
- # withdrawed = RMB(20)
- #
- # after_withdraw_balance = agent_no_customized.sub_balance(income_type, source_key)
- #
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed), 'balance inc failed'
- #
- # before_withdraw_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # desired_service_fee = withdrawed * (Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO / Const.WITHDRAW_FEE_UNIT)
- # desired_actual_pay = withdrawed - desired_service_fee
- #
- # before_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key)
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(withdrawed),
- # 'sourceType': income_type,
- # 'sourceId': source_key
- # }
- #
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_changes', return_value = WECHAT_WITHDRAW_ERROR[test_id])
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == desired_result
- # assert json_response['description'] == desired_show_message
- #
- # agent_no_customized.reload()
- #
- # if WECHAT_WITHDRAW_ERROR[test_id]['refund']:
- # assert before_withdraw_balance == agent_no_customized.sub_balance(income_type, source_key)
- # else:
- # assert after_withdraw_balance == agent_no_customized.sub_balance(income_type, source_key)
- #
- # withdraw_record_id = json_response['payload']['paymentId']
- #
- # record = WithdrawRecord.objects(id = str(withdraw_record_id)).first() # type: WithdrawRecord
- # assert record
- # assert record.serviceFee == desired_service_fee
- # assert record.actualPay == desired_actual_pay
- # assert record.amount == withdrawed
- # assert record.ownerId == str(agent_no_customized.id)
- # assert record.payType == WITHDRAW_PAY_TYPE.WECHAT
- # assert record.balance == before_withdraw_balance
- # assert record.withdrawGatewayKey == source_key
- #
- # if WECHAT_WITHDRAW_ERROR[test_id]['refund']:
- # assert record.status == WithdrawStatus.CLOSED
- # else:
- # assert record.status == WithdrawStatus.FAILED
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # amount = st.one_of(st.floats(min_value = 10, max_value = 1000),
- # st.integers(min_value = 10, max_value = 1000)))
- # def test_agent_withdraw_with_bank(mocker, agent_no_customized, income_type, source_key, amount,
- # agent_no_customized_client):
- # # type: (MockFixture, Agent, str, str, Union[int, float], RequestTestClient)->None
- #
- # withdrawed = RMB(amount)
- #
- # after_withdraw_balance = agent_no_customized.sub_balance(income_type, source_key)
- #
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed), 'balance inc failed'
- #
- # before_withdraw_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # desired_service_fee = withdrawed * (Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO / Const.WITHDRAW_FEE_UNIT)
- # desired_actual_pay = withdrawed - desired_service_fee
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.BANK,
- # 'amount': str(withdrawed),
- # 'sourceType': income_type,
- # 'sourceId': source_key,
- # 'bankAccount': BANK_ACCOUNT_CODE
- # }
- #
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_bank', return_value = BANK_WITHDRAW_SUCCEEDED)
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # assert after_withdraw_balance == agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 1
- # assert json_response['description'] == u'提现申请微信已经受理'
- #
- # withdraw_record_id = json_response['payload']['paymentId']
- #
- # record = WithdrawRecord.objects(id = str(withdraw_record_id)).first() # type: WithdrawRecord
- # assert record
- # assert record.serviceFee == desired_service_fee
- # assert record.actualPay == desired_actual_pay
- # assert record.amount == withdrawed
- # assert record.ownerId == str(agent_no_customized.id)
- # assert record.payType == WITHDRAW_PAY_TYPE.BANK
- # assert record.balance == before_withdraw_balance
- # assert record.withdrawGatewayKey == source_key
- # assert record.status == WithdrawStatus.PROCESSING
- # assert record.remarks == u'提现申请微信已经受理'
- #
- #
- # @given(income_type = st.sampled_from(
- # [AGENT_INCOME_TYPE.AD,
- # AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # AGENT_INCOME_TYPE.DEALER_DEVICE_FEE,
- # AGENT_INCOME_TYPE.DEALER_CARD_FEE]),
- # manual_type = st.integers(min_value = 1, max_value = 2))
- #
- # def test_agent_withdraw_with_bank_manual(mocker, agent_no_customized, income_type, source_key, agent_no_customized_client, manual_type):
- # # type: (MockFixture, Agent, str, str, RequestTestClient, int)->None
- #
- # if manual_type == 1:
- # pass
- # else:
- # wechat_payment_app = get_wechat_app_from_gateway_key(source_key) # type: WechatPayApp
- # wechat_payment_app.manual_withdraw = True
- #
- # withdrawed = RMB(20)
- #
- # after_withdraw_balance = agent_no_customized.sub_balance(income_type, source_key)
- #
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed), 'balance inc failed'
- #
- # before_withdraw_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # desired_service_fee = withdrawed * (Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO / Const.WITHDRAW_FEE_UNIT)
- # desired_actual_pay = withdrawed - desired_service_fee
- #
- # from apps.web.agent.views import agentWithdraw
- # url = url_fn(agentWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.BANK,
- # 'amount': str(withdrawed),
- # 'sourceType': income_type,
- # 'sourceId': source_key,
- # 'bankAccount': BANK_ACCOUNT_CODE
- # }
- #
- # response = agent_no_customized_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 1
- # assert json_response['description'] == u"提现申请已经受理"
- #
- # assert after_withdraw_balance == agent_no_customized.reload().sub_balance(income_type, source_key)
- #
- # withdraw_record_id = json_response['payload']['paymentId']
- #
- # record = WithdrawRecord.objects(id = str(withdraw_record_id)).first() # type: WithdrawRecord
- # assert record
- # assert record.serviceFee == desired_service_fee
- # assert record.actualPay == desired_actual_pay
- # assert record.amount == withdrawed
- # assert record.ownerId == str(agent_no_customized.id)
- # assert record.payType == WITHDRAW_PAY_TYPE.BANK
- # assert record.balance == before_withdraw_balance
- # assert record.withdrawGatewayKey == source_key
- # assert record.status == WithdrawStatus.PROCESSING
- # assert record.remarks == u'提现申请已经受理'
- #
- #
- # @given(income_type = st.sampled_from([DEALER_INCOME_TYPE.DEVICE_INCOME, DEALER_INCOME_TYPE.AD_INCOME]),
- # amount = st.one_of(st.floats(min_value = 10, max_value = 1000), st.integers(min_value = 10, max_value = 1000)),
- # fee_ratio = st.integers(min_value = Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO,
- # max_value = Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO + Permillage("10")))
- # def test_record_agent_withdraw_fee(mocker, agent_no_customized, dealer, dealer_client, income_type, amount, fee_ratio):
- # # type: (MockFixture, Agent, Dealer, RequestTestClient, str, [int, float], int)->None
- # money = RMB(amount)
- #
- # dealer.withdrawFeeRatio = fee_ratio
- # dealer.save()
- #
- # dealer.reload()
- #
- # pre_balance = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, money), 'balance inc failed'
- #
- # dealer.reload()
- #
- # desired_service_fee = money * (dealer.withdrawFeeRatio / Const.WITHDRAW_FEE_UNIT)
- # desired_actual_pay = money - desired_service_fee
- #
- # if dealer.withdrawFeeRatio > Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO:
- # earned = money * (
- # (dealer.withdrawFeeRatio - Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO) / Const.WITHDRAW_FEE_UNIT)
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # source_key) + earned
- # else:
- # earned = RMB(0)
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key)
- #
- # from apps.web.dealer.views import dealerWithdraw
- # url = url_fn(dealerWithdraw)
- # payload = {
- # 'code': '1234',
- # 'payType': WITHDRAW_PAY_TYPE.WECHAT,
- # 'amount': str(money),
- # 'sourceType': income_type,
- # 'sourceId': source_key
- # }
- #
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_changes', return_value = WECHAT_WITHDRAW_SUCCEEDED)
- #
- # response = dealer_client.post_json(url, data = payload)
- #
- # assert response
- #
- # dealer.reload()
- #
- # assert pre_balance == dealer.sub_balance(income_type, source_key)
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- # assert json_response['result'] == 1
- # assert json_response['description'] == u'提现成功'
- #
- # withdraw_record_id = json_response['payload']['paymentId']
- #
- # record = WithdrawRecord.objects(id = str(withdraw_record_id)).first() # type: WithdrawRecord
- # assert record
- # assert record.serviceFee == desired_service_fee
- # assert record.actualPay == desired_actual_pay
- # assert record.amount == money
- # assert record.ownerId == str(dealer.id)
- # assert record.payType == WITHDRAW_PAY_TYPE.WECHAT
- # assert record.balance == (pre_balance + money)
- # assert record.withdrawGatewayKey == source_key
- # assert record.status == WithdrawStatus.SUCCEEDED
- #
- # assert agent_no_customized.reload().sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # source_key) == desired_agent_balance
- #
- # report = AgentIncomeReport.objects(agentId = str(agent_no_customized.id), amount = earned).first() # type: AgentIncomeReport
- #
- # if dealer.withdrawFeeRatio > Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO:
- # assert report
- # assert report.amount == earned
- #
- # report.delete()
- # else:
- # assert not report
- #
- #
- # def test_getFeatureList(agent_client, agent):
- # from apps.web.agent.views import getFeatureList
- #
- # from apps.web.common.models import Feature
- #
- # agent.update(set__features = [])
- #
- # url = url_fn(getFeatureList)
- #
- # assert agent_client.post_json(url).json()['payload'] == {}
- #
- # with DisposableModel(model = Feature, name = 'test', key = 'test', role = "agent") as model:
- # agent.update(set__features = [model.key])
- # assert agent_client.post_json(url, data = {'list': ['test']}).json()['payload'] == {'test': True}
- # agent.update(set__features = [])
- #
- #
- # def test_agent_revoke_dealer_withdraw(mocker, dealer, source_key, merchant, default_agent_client, agent_no_customized):
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_bank', return_value = BANK_WITHDRAW_ERROR[0])
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, withdrawed)
- # before_balance = dealer.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = dealer.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(dealer.inhandWithdrawList)
- #
- # withdraw_service = DealerWithdrawService(payee = dealer,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(source_key = source_key, recurrent = False)
- #
- # assert result['result'] == 0
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.FAILED
- #
- # from apps.web.agent.views import revokeWithdrawApplication
- # url = url_fn(revokeWithdrawApplication)
- # payload = {
- # 'orderNo': withdraw_record.order,
- # 'reason': u'测试的原因'
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # refund_record = WithdrawRefundRecord.objects(withdraw_record_id = withdraw_record_id).first()
- # assert refund_record
- #
- # dealer.reload()
- # assert dealer.sub_balance(income_type, source_key) == before_balance
- # assert dealer.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(dealer.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.CLOSED
- #
- #
- # def test_agent_revoke_dealer_withdraw_manual(mocker, dealer, source_key, merchant, default_agent_client, default_agent,
- # agent_no_customized):
- # default_agent.payAppWechat.manual_withdraw = True
- # default_agent.payAppWechat.save()
- # default_agent.payAppWechat.reload()
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, withdrawed)
- # before_balance = dealer.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = dealer.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(dealer.inhandWithdrawList)
- #
- # withdraw_service = DealerWithdrawService(payee = dealer,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 1
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.PROCESSING
- #
- # from apps.web.agent.views import revokeWithdrawApplication
- # url = url_fn(revokeWithdrawApplication)
- # payload = {
- # 'orderNo': withdraw_record.order,
- # 'reason': u'测试的原因'
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # refund_record = WithdrawRefundRecord.objects(withdraw_record_id = withdraw_record_id).first()
- # assert refund_record
- #
- # dealer.reload()
- # assert dealer.sub_balance(income_type, source_key) == before_balance
- # assert dealer.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(dealer.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.CLOSED
- #
- #
- # def test_agent_approve_dealer_withdraw(mocker, dealer, source_key, merchant, default_agent, default_agent_client, agent_no_customized):
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_bank', return_value = BANK_WITHDRAW_ERROR[0])
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, withdrawed)
- # before_balance = dealer.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = dealer.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(dealer.inhandWithdrawList)
- #
- # if dealer.withdrawFeeRatio > Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # source_key) + withdrawed * (
- # (dealer.withdrawFeeRatio - Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO) / Const.WITHDRAW_FEE_UNIT)
- # else:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key)
- #
- # withdraw_service = DealerWithdrawService(payee = dealer,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 0
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.FAILED
- #
- # from apps.web.agent.views import adminAgreeWallet
- # url = url_fn(adminAgreeWallet)
- # payload = {
- # 'orderNo': withdraw_record.order
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # dealer.reload()
- # assert dealer.sub_balance(income_type, source_key) == balance_if_success
- # assert dealer.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(dealer.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.SUCCEEDED
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key) == desired_agent_balance
- #
- #
- # def test_agent_approve_dealer_withdraw_manual(mocker, dealer, source_key, merchant, default_agent_client, default_agent,
- # agent_no_customized):
- # default_agent.payAppWechat.manual_withdraw = True
- # default_agent.payAppWechat.save()
- # default_agent.payAppWechat.reload()
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, withdrawed)
- # before_balance = dealer.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = dealer.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(dealer.inhandWithdrawList)
- #
- # if dealer.withdrawFeeRatio > Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # source_key) + withdrawed * (
- # (dealer.withdrawFeeRatio - Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO) / Const.WITHDRAW_FEE_UNIT)
- # else:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key)
- #
- # withdraw_service = DealerWithdrawService(payee = dealer,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 1
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.PROCESSING
- #
- # from apps.web.agent.views import adminAgreeWallet
- # url = url_fn(adminAgreeWallet)
- # payload = {
- # 'orderNo': withdraw_record.order
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # dealer.reload()
- # assert dealer.sub_balance(income_type, source_key) == balance_if_success
- # assert dealer.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(dealer.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.SUCCEEDED
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key) == desired_agent_balance
- #
- #
- # def test_agent_revoke_agent_withdraw(mocker, dealer, source_key, merchant, default_agent_client, agent_no_customized):
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_bank', return_value = BANK_WITHDRAW_ERROR[0])
- #
- # income_type = AGENT_INCOME_TYPE.DEALER_DEVICE_FEE
- #
- # withdrawed = RMB(20)
- #
- # balance_after_withdraw = agent_no_customized.sub_balance(income_type, source_key)
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed)
- # before_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_service = AgentWithdrawService(payee = agent_no_customized,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 0
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.FAILED
- # assert withdraw_record.role == ROLE.agent
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(income_type, source_key) == balance_after_withdraw
- #
- # from apps.web.agent.views import revokeWithdrawApplication
- # url = url_fn(revokeWithdrawApplication)
- # payload = {
- # 'orderNo': withdraw_record.order,
- # 'reason': u'测试的原因'
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # refund_record = WithdrawRefundRecord.objects(withdraw_record_id = withdraw_record_id).first()
- # assert refund_record
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(income_type, source_key) == before_balance
- # assert agent_no_customized.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.CLOSED
- #
- #
- # def test_agent_revoke_agent_withdraw_manual(mocker, dealer, source_key, merchant, default_agent_client, default_agent,
- # agent_no_customized):
- # default_agent.payAppWechat.manual_withdraw = True
- # default_agent.payAppWechat.save()
- # default_agent.payAppWechat.reload()
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_after_withdraw = agent_no_customized.sub_balance(income_type, source_key)
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed)
- # before_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_service = AgentWithdrawService(payee = agent_no_customized,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 1
- #
- # agent_no_customized.reload().sub_balance(income_type, source_key) == balance_after_withdraw
- #
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- #
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.PROCESSING
- #
- # from apps.web.agent.views import revokeWithdrawApplication
- # url = url_fn(revokeWithdrawApplication)
- # payload = {
- # 'orderNo': withdraw_record.order,
- # 'reason': u'测试的原因'
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # refund_record = WithdrawRefundRecord.objects(withdraw_record_id = withdraw_record_id).first()
- # assert refund_record
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(income_type, source_key) == before_balance
- # assert agent_no_customized.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.CLOSED
- #
- #
- # def test_agent_approve_agent_withdraw(mocker, dealer, source_key, merchant, default_agent, default_agent_client,
- # agent_no_customized):
- # from apps.web.core.payment.wechat import WechatPaymentGateway
- # mocker.patch.object(WechatPaymentGateway, 'withdraw_via_bank', return_value = BANK_WITHDRAW_ERROR[0])
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = agent_no_customized.sub_balance(income_type, source_key)
- # assert agent_no_customized.incr_fund(income_type, source_key, withdrawed)
- # before_balance = agent_no_customized.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = agent_no_customized.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_service = AgentWithdrawService(payee = agent_no_customized,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 0
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.FAILED
- #
- # from apps.web.agent.views import adminAgreeWallet
- # url = url_fn(adminAgreeWallet)
- # payload = {
- # 'orderNo': withdraw_record.order
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(income_type, source_key) == balance_if_success
- # assert agent_no_customized.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(agent_no_customized.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.SUCCEEDED
- #
- #
- # def test_agent_approve_agent_withdraw_manual(mocker, dealer, source_key, merchant, default_agent_client, default_agent,
- # agent_no_customized):
- # default_agent.payAppWechat.manual_withdraw = True
- # default_agent.payAppWechat.save()
- # default_agent.payAppWechat.reload()
- #
- # income_type = DEALER_INCOME_TYPE.DEVICE_INCOME
- # withdrawed = RMB(20)
- #
- # balance_if_success = dealer.sub_balance(income_type, source_key)
- # assert dealer.incr_fund(income_type, source_key, withdrawed)
- # before_balance = dealer.reload().sub_balance(income_type, source_key)
- # before_frozen_balance = dealer.sub_frozen_balance(income_type, source_key)
- # before_outgoing = len(dealer.inhandWithdrawList)
- #
- # if dealer.withdrawFeeRatio > Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE,
- # source_key) + withdrawed * (
- # (dealer.withdrawFeeRatio - Const.PLATFORM_DEFAULT_WITHDRAW_FEE_RATIO) / Const.WITHDRAW_FEE_UNIT)
- # else:
- # desired_agent_balance = agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key)
- #
- # withdraw_service = DealerWithdrawService(payee = dealer,
- # income_type = income_type,
- # code = None, amount = withdrawed,
- # pay_type = WITHDRAW_PAY_TYPE.BANK,
- # bank_card_no = merchant.accountCode)
- # result = withdraw_service.execute(gateway_key = source_key, recurrent = False)
- #
- # assert result['result'] == 1
- # withdraw_record_id = result['payload']['paymentId']
- # withdraw_record = WithdrawRecord.objects(id = withdraw_record_id).first() # type: WithdrawRecord
- # assert withdraw_record
- # assert withdraw_record.status == WithdrawStatus.PROCESSING
- #
- # from apps.web.agent.views import adminAgreeWallet
- # url = url_fn(adminAgreeWallet)
- # payload = {
- # 'orderNo': withdraw_record.order
- # }
- #
- # response = default_agent_client.post_json(url, data = payload)
- #
- # assert response
- #
- # import simplejson as json
- # json_response = json.loads(response.content)
- #
- # assert json_response['result'] == 1
- #
- # dealer.reload()
- # assert dealer.sub_balance(income_type, source_key) == balance_if_success
- # assert dealer.sub_frozen_balance(income_type, source_key) == before_frozen_balance
- # assert before_outgoing == len(dealer.inhandWithdrawList)
- #
- # withdraw_record.reload()
- # assert withdraw_record.status == WithdrawStatus.SUCCEEDED
- #
- # agent_no_customized.reload()
- # assert agent_no_customized.sub_balance(AGENT_INCOME_TYPE.DEALER_WITHDRAW_FEE, source_key) == desired_agent_balance
|