Ejemplo n.º 1
0
 def test_valid_data(self):
     wallet = WalletFactory(currency=CurrencyChoices.USD.value)
     url = reverse('core:wallet_refill', kwargs={'pk': wallet.pk})
     data = {
         "currency": "USD",
         "amount": 10
     }
     response = self.client.put(url, data, format='json')
     assert response.status_code == 200
     wallet.refresh_from_db()
     assert wallet.amount == Decimal('10.00')
Ejemplo n.º 2
0
 def test_no_currency(self):
     wallet = WalletFactory(currency=CurrencyChoices.USD.value)
     url = reverse('core:wallet_refill', kwargs={'pk': wallet.pk})
     data = {
         "amount": 10
     }
     response = self.client.put(url, data, format='json')
     assert response.status_code == 400
Ejemplo n.º 3
0
 def test_direct_transfer(self):
     source_wallet = WalletFactory(currency=CurrencyChoices.USD.value, amount=15.00)
     target_wallet = WalletFactory(currency=CurrencyChoices.USD.value, amount=10.00)
     url = reverse('core:wallet_transfer', kwargs={'pk': source_wallet.pk})
     data = {
         "target_wallet_id": target_wallet.id,
         "amount": 10.00
     }
     response = self.client.post(url, data, format='json')
     assert response.status_code == 200
     source_wallet.refresh_from_db()
     target_wallet.refresh_from_db()
     assert source_wallet.amount == Decimal('5.00')
     assert target_wallet.amount == Decimal('20.00')
Ejemplo n.º 4
0
 def test_two_step_conversion(self):
     RateFactory(source_currency='CAD', rate='0.76')
     source_wallet = WalletFactory(currency=CurrencyChoices.CAD.value, amount=15.00)
     target_wallet = WalletFactory(currency=CurrencyChoices.EUR.value)
     url = reverse('core:wallet_transfer', kwargs={'pk': source_wallet.pk})
     data = {
         "target_wallet_id": target_wallet.id,
         "amount": 10.00
     }
     response = self.client.post(url, data, format='json')
     assert response.status_code == 200
     source_wallet.refresh_from_db()
     target_wallet.refresh_from_db()
     assert source_wallet.amount == Decimal('5.00')
     assert target_wallet.amount == Decimal('6.72')  # CAD->USD rate * USD->EUR rate * amount round to floor