skip insufficient balance for allowed negative balance applications test
This commit is contained in:
parent
e4093ee4de
commit
9de126d585
2 changed files with 27 additions and 26 deletions
|
|
@ -312,8 +312,8 @@ class Transaction(BaseModel):
|
|||
|
||||
######################## category
|
||||
def category_withdraw_from_payer_balance(self):
|
||||
payer_is_allowed_negative_balance = self.payer_type == TypeChoices.APPLICATION.value and str(
|
||||
self.payer_id) in settings.ALLOWED_NEGATIVE_BALANCE_APPLICATIONS
|
||||
payer_is_allowed_negative_balance = self.payer_wallet.owner_type == TypeChoices.APPLICATION.value and str(
|
||||
self.payer_wallet.owner_uuid) in settings.ALLOWED_NEGATIVE_BALANCE_APPLICATIONS
|
||||
if self.amount > self.payer_wallet.balance and not payer_is_allowed_negative_balance:
|
||||
raise APIException('not enough balance')
|
||||
self.payer_wallet.balance = F('balance') - self.amount
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from oauth2_provider.models import get_access_token_model, get_application_model
|
||||
from rest_framework.test import APITestCase
|
||||
from rest_framework.test import APITestCase, override_settings
|
||||
|
||||
from apps.users.models import User
|
||||
from apps.wallet.constans import TypeChoices
|
||||
|
|
@ -234,6 +234,30 @@ class ApplicationApiFlowsTests(APITestCase):
|
|||
response = self.client.post(reverse('wallet:application_deposit_submit_api'), data=data, HTTP_AUTHORIZATION=auth)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
@override_settings(ALLOWED_NEGATIVE_BALANCE_APPLICATIONS=['b14e8b86-8f4a-44d9-b29d-badceb470053'])
|
||||
def test_deposit_flow_skip_insufficient_balance_for_allowed_negative_balance_applications(self):
|
||||
auth = self._create_authorization_header(self.application_access_token.token)
|
||||
|
||||
# Checking wallets initials values(application balance = 300 and payee balance = zero)
|
||||
response = self.client.get(reverse('wallet:application_wallet_balance_api'), HTTP_AUTHORIZATION=auth)
|
||||
self.assertContains(response, 'balance')
|
||||
self.assertEqual(response.json()['balance'], 300)
|
||||
params = {
|
||||
'uuid': self.payee_uuid,
|
||||
}
|
||||
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=params), HTTP_AUTHORIZATION=auth)
|
||||
self.assertContains(response, 'balance')
|
||||
self.assertEqual(response.json()['balance'], 0)
|
||||
|
||||
# Deposit process
|
||||
data = {
|
||||
'amount': 500,
|
||||
'payee_id': self.payee_uuid,
|
||||
'payee_type': TypeChoices.USER
|
||||
}
|
||||
response = self.client.post(reverse('wallet:application_deposit_submit_api'), data=data, HTTP_AUTHORIZATION=auth)
|
||||
self.assertEqual(response.status_code, 201)
|
||||
|
||||
def test_deposit_flow_zero_amount(self):
|
||||
auth = self._create_authorization_header(self.application_access_token.token)
|
||||
|
||||
|
|
@ -381,29 +405,6 @@ class ApplicationApiFlowsTests(APITestCase):
|
|||
self.assertContains(response, 'balance')
|
||||
self.assertEqual(response.json()['balance'], 300)
|
||||
|
||||
def test_withdraw_flow_insufficient_balance(self):
|
||||
auth = self._create_authorization_header(self.payer_access_token.token)
|
||||
|
||||
# Checking wallets initials values(application balance = 300 and payee balance = zero)
|
||||
response = self.client.get(reverse('wallet:application_wallet_balance_api'), HTTP_AUTHORIZATION=auth)
|
||||
self.assertContains(response, 'balance')
|
||||
self.assertEqual(response.json()['balance'], 300)
|
||||
params = {
|
||||
'uuid': self.payer_uuid,
|
||||
}
|
||||
response = self.client.get(reverse('wallet:application_user_wallet_balance_api', kwargs=params), HTTP_AUTHORIZATION=auth)
|
||||
self.assertContains(response, 'balance')
|
||||
self.assertEqual(response.json()['balance'], 300)
|
||||
|
||||
# Deposit process
|
||||
data = {
|
||||
'amount': 500,
|
||||
'payer_id': self.payer_uuid,
|
||||
'payer_type': TypeChoices.USER
|
||||
}
|
||||
response = self.client.post(reverse('wallet:application_withdraw_submit_api'), data=data, HTTP_AUTHORIZATION=auth)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
def test_withdraw_flow_zero_amount(self):
|
||||
auth = self._create_authorization_header(self.payer_access_token.token)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue