12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- from django.conf import settings
- from hypothesis import given, strategies as st
- from pytest_mock import MockFixture
- from typing import Union
- from apilib.monetary import RMB, Permillage
- from apilib.utils_datetime import generate_timestamp_ex
- from apps.web.agent.define import AGENT_INCOME_TYPE
- from apps.web.agent.models import Agent, AgentIncomeReport
- from apps.web.agent.withdraw import AgentWithdrawService
- from apps.web.common.models import WithdrawRecord, WithdrawRefundRecord
- from apps.web.common.transaction import WithdrawStatus, WITHDRAW_PAY_TYPE
- from apps.web.constant import Const
- from apps.web.core import ROLE
- from apps.web.core.models import BankCard
- from apps.web.dealer.define import DEALER_INCOME_TYPE
- from apps.web.dealer.models import Dealer
- from apps.web.dealer.withdraw import DealerWithdrawService
- from common import url_fn, DisposableModel, BANK_ACCOUNT_CODE, MERCHANT_ID
- from conftest import RequestTestClient
- from responses import WECHAT_WITHDRAW_SUCCEEDED, WECHAT_WITHDRAW_ERROR, BANK_WITHDRAW_SUCCEEDED, BANK_WITHDRAW_ERROR
- ###
- ### 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:
- # bank_card = BankCard.objects(id = MERCHANT_ID).first()
- # bank_card.accountType = BankCard.AccountType.PUBLIC
- # bank_card.save()
- # 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
|