fix(wallet): adapt submit and verify process to new wallet, account concept
adapt submit and verify process to new wallet, account concept test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications
This commit is contained in:
parent
c5ec20e1f0
commit
450c6f0191
2 changed files with 21 additions and 19 deletions
|
|
@ -14,10 +14,11 @@ from apps.wallet.models import Wallet
|
||||||
AccessToken = get_access_token_model()
|
AccessToken = get_access_token_model()
|
||||||
Application = get_application_model()
|
Application = get_application_model()
|
||||||
|
|
||||||
|
application_uuid_hex = 'b14e8b86-8f4a-44d9-b29d-badceb470053'
|
||||||
|
|
||||||
class ApplicationApiFlowsTests(APITestCase):
|
class ApplicationApiFlowsTests(APITestCase):
|
||||||
client_id = '4INGOCMoulE0fNY1SQlTbPtsWqqxGj2DdqjADq6u'
|
client_id = '4INGOCMoulE0fNY1SQlTbPtsWqqxGj2DdqjADq6u'
|
||||||
application_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470053')
|
application_uuid = uuid.UUID(application_uuid_hex)
|
||||||
application_access_token = '14naVsdKCbKNOhnElPyXcrwSnqqFbm'
|
application_access_token = '14naVsdKCbKNOhnElPyXcrwSnqqFbm'
|
||||||
payer_access_token = '24naVsdKCbKNOhnElPyXcrwSnqqFbm'
|
payer_access_token = '24naVsdKCbKNOhnElPyXcrwSnqqFbm'
|
||||||
payer_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470051')
|
payer_uuid = uuid.UUID('b14e8b86-8f4a-44d9-b29d-badceb470051')
|
||||||
|
|
@ -205,35 +206,36 @@ class ApplicationApiFlowsTests(APITestCase):
|
||||||
data=data, HTTP_AUTHORIZATION=auth)
|
data=data, HTTP_AUTHORIZATION=auth)
|
||||||
self.assertEqual(response.status_code, 422)
|
self.assertEqual(response.status_code, 422)
|
||||||
|
|
||||||
@override_settings(ALLOWED_NEGATIVE_BALANCE_APPLICATIONS=['b14e8b86-8f4a-44d9-b29d-badceb470053'])
|
@override_settings(ALLOWED_NEGATIVE_BALANCE_APPLICATIONS=[application_uuid_hex])
|
||||||
def test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications(self):
|
def test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications(self):
|
||||||
auth = self._create_authorization_header(self.application_access_token.token)
|
auth = self._create_authorization_header(self.application_access_token.token)
|
||||||
|
|
||||||
# Checking wallets initials values(application balance = 300 and payee balance = zero)
|
# Checking wallets initials values(application balance = 300 and payee balance = zero)
|
||||||
response = self.client.get(reverse('wallet:application_account_balance_api'), HTTP_AUTHORIZATION=auth)
|
wallets = [self.wallet_rial_uuid.hex, self.wallet_reward_uuid.hex]
|
||||||
self.assertContains(response, 'balance')
|
response = self.client.get(reverse('wallet:application_account_balance_api'), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
|
||||||
self.assertEqual(response.json()['balance'], 300)
|
self.assertGreater(response.json()['count'], 1)
|
||||||
|
from_wallet = response.json()['results'][0]
|
||||||
|
self.assertEqual(from_wallet['balance'], 300)
|
||||||
params = {
|
params = {
|
||||||
'uuid': self.payee_uuid,
|
'user': self.payee_uuid,
|
||||||
'wallet_uuid': self.wallet_rial_uuid,
|
|
||||||
}
|
}
|
||||||
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=params), HTTP_AUTHORIZATION=auth)
|
response = self.client.get(reverse('wallet:application_user_account_api', kwargs=params), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
|
||||||
self.assertContains(response, 'balance')
|
self.assertGreater(response.json()['count'], 1)
|
||||||
self.assertEqual(response.json()['balance'], 0)
|
to_wallet = response.json()['results'][0]
|
||||||
|
self.assertEqual(to_wallet['balance'], 0)
|
||||||
|
|
||||||
# Deposit process
|
# Deposit process
|
||||||
data = {
|
data = {
|
||||||
'amount': 500,
|
'amount': 500,
|
||||||
'payee': self.payee_uuid,
|
'payee': self.payee_uuid,
|
||||||
'payee_type': TypeChoices.USER,
|
'payee_type': TypeChoices.USER,
|
||||||
'payee_account': self.wallet_rial_uuid,
|
'payee_wallet': self.wallet_rial_uuid,
|
||||||
}
|
}
|
||||||
|
kwargs_payer_wallet = {
|
||||||
kwargs_wallet_uuid_payee_uuid = {
|
'payer_wallet': self.wallet_rial_uuid,
|
||||||
'wallet_uuid': self.wallet_rial_uuid,
|
|
||||||
}
|
}
|
||||||
|
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet),
|
||||||
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_wallet_uuid_payee_uuid), data=data, HTTP_AUTHORIZATION=auth)
|
data=data, HTTP_AUTHORIZATION=auth)
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
def test_deposit_flow_zero_amount(self):
|
def test_deposit_flow_zero_amount(self):
|
||||||
|
|
|
||||||
|
|
@ -181,9 +181,9 @@ class DepositSubmitAPIView(generics.CreateAPIView):
|
||||||
required_scopes = ['wallet.application.deposit:submit']
|
required_scopes = ['wallet.application.deposit:submit']
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
wallet_uuid = self.kwargs.get('wallet_uuid')
|
payer_wallet_uuid = self.kwargs.get('payer_wallet')
|
||||||
if wallet_uuid:
|
if payer_wallet_uuid:
|
||||||
wallet = get_object_or_404(Wallet.objects.all(), uuid=wallet_uuid)
|
wallet = get_object_or_404(Wallet.objects.all(), uuid=payer_wallet_uuid)
|
||||||
else:
|
else:
|
||||||
wallet = None
|
wallet = None
|
||||||
application = get_application(self.request)
|
application = get_application(self.request)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue