pass tests
This commit is contained in:
parent
a35bd6b202
commit
9183b1aa78
2 changed files with 18 additions and 4 deletions
|
|
@ -173,9 +173,19 @@ class Transaction(BaseModel):
|
||||||
if self.amount > self.payer_account.balance and not payer_is_allowed_negative_balance:
|
if self.amount > self.payer_account.balance and not payer_is_allowed_negative_balance:
|
||||||
logger.error('not enough balance')
|
logger.error('not enough balance')
|
||||||
raise UnprocessableEntity('not enough balance')
|
raise UnprocessableEntity('not enough balance')
|
||||||
logger.info(f'payer_account balance {self.payee_account} -> {self.payer_account.balance} - {self.amount}')
|
|
||||||
self.payer_account.balance = F('balance') - self.amount
|
if not payer_is_allowed_negative_balance:
|
||||||
self.payer_account.save(update_fields=['balance'])
|
updated = Account.objects.filter(pk=self.payer_account.pk, balance__gt=self.amount).update(balance=F('balance') - self.amount)
|
||||||
|
else:
|
||||||
|
updated = Account.objects.filter(pk=self.payer_account.pk).update(balance=F('balance') - self.amount)
|
||||||
|
|
||||||
|
if updated:
|
||||||
|
self.payer_account.refresh_from_db()
|
||||||
|
logger.info(f'payer_account balance {self.payee_account} -> {self.payer_account.balance} - {self.amount}')
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise UnprocessableEntity('not enough balance')
|
||||||
|
|
||||||
|
|
||||||
def deposit_to_payee_balance(self):
|
def deposit_to_payee_balance(self):
|
||||||
logger.debug('start deposit_to_payee_balance')
|
logger.debug('start deposit_to_payee_balance')
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class ApplicationApiFlowsTests(APITestCase):
|
||||||
'wallet.deposit:submit',
|
'wallet.deposit:submit',
|
||||||
'wallet.wallet:get_balance',
|
'wallet.wallet:get_balance',
|
||||||
'wallet.application:get_user_balance',
|
'wallet.application:get_user_balance',
|
||||||
|
'wallet.user:transaction_list',
|
||||||
|
|
||||||
'wallet.application.withdraw:submit',
|
'wallet.application.withdraw:submit',
|
||||||
'wallet.application.withdraw:verify',
|
'wallet.application.withdraw:verify',
|
||||||
|
|
@ -93,9 +94,10 @@ class ApplicationApiFlowsTests(APITestCase):
|
||||||
return "Bearer {0}".format(token)
|
return "Bearer {0}".format(token)
|
||||||
|
|
||||||
def test_authentication_allow(self):
|
def test_authentication_allow(self):
|
||||||
auth = self._create_authorization_header(self.application_access_token.token)
|
auth = self._create_authorization_header(self.payer_access_token.token)
|
||||||
wallets = [self.wallet_rial_uuid.hex, self.wallet_reward_uuid.hex]
|
wallets = [self.wallet_rial_uuid.hex, self.wallet_reward_uuid.hex]
|
||||||
response = self.client.get(reverse('wallet:user_wallet_account_api'), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
|
response = self.client.get(reverse('wallet:user_wallet_account_api'), query_params={'wallet': ','.join(wallets)}, HTTP_AUTHORIZATION=auth)
|
||||||
|
print(response.json())
|
||||||
self.assertGreater(response.json()['count'], 1)
|
self.assertGreater(response.json()['count'], 1)
|
||||||
from_wallet = response.json()['results'][0]
|
from_wallet = response.json()['results'][0]
|
||||||
self.assertEqual(from_wallet['balance'], 300)
|
self.assertEqual(from_wallet['balance'], 300)
|
||||||
|
|
@ -239,6 +241,7 @@ class ApplicationApiFlowsTests(APITestCase):
|
||||||
}
|
}
|
||||||
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_payer_wallet),
|
||||||
data=data, HTTP_AUTHORIZATION=auth)
|
data=data, HTTP_AUTHORIZATION=auth)
|
||||||
|
print(response.json())
|
||||||
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):
|
||||||
|
|
@ -303,6 +306,7 @@ class ApplicationApiFlowsTests(APITestCase):
|
||||||
'payer_wallet': self.wallet_rial_uuid,
|
'payer_wallet': self.wallet_rial_uuid,
|
||||||
}
|
}
|
||||||
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet), data=data, HTTP_AUTHORIZATION=auth)
|
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet), data=data, HTTP_AUTHORIZATION=auth)
|
||||||
|
print(response.json())
|
||||||
self.assertEqual(response.status_code, 201)
|
self.assertEqual(response.status_code, 201)
|
||||||
|
|
||||||
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet), data=data, HTTP_AUTHORIZATION=auth)
|
response = self.client.post(reverse('wallet:application_deposit_submit_api', kwargs=kwargs_payer_wallet), data=data, HTTP_AUTHORIZATION=auth)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue