Ejemplo n.º 1
0
 def test_purchase(self):
     account_obj = AccountFactory.create()
     wallet_obj = WalletFactory.create(owner_id=account_obj.id)
     WalletTrxFactory.create(
         wallet=wallet_obj,
         amount=Money(1000, 'SEK'),
         trx_status=TrxStatus.FINALIZED
     )
     product_obj1 = ProductFactory.create(
         name='Billys Ooriginal',
         price=Money(13, 'SEK')
     )
     product_obj2 = ProductFactory.create(
         name='Kebabrulle',
         price=Money(30, 'SEK')
     )
     url = reverse('api:purchases-list')
     data = {
         'account_id': account_obj.id,
         'products': [
             {'id': product_obj1.id, 'qty': 1},
             {'id': product_obj2.id, 'qty': 3},
         ]
     }
     response = self.api_client.post(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     _, balance = wallet_api.get_balance(wallet_obj.owner_id, 'SEK')
     self.assertEqual(balance, Money(897, 'SEK'))
Ejemplo n.º 2
0
 def test_cash_purchase(self):
     product_obj1 = ProductFactory.create(name='Billys Ooriginal',
                                          price=Money(13, 'SEK'))
     product_obj2 = ProductFactory.create(name='Kebabrulle',
                                          price=Money(30, 'SEK'))
     url = reverse('api:purchases-list')
     data = {
         'account_id':
         None,
         'products': [
             {
                 'id': product_obj1.id,
                 'qty': 1
             },
             {
                 'id': product_obj2.id,
                 'qty': 3
             },
         ]
     }
     response = self.api_client.post(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['amount'], 103)
     _, balance = wallet_api.get_balance(settings.FOOBAR_CASH_WALLET, 'SEK')
     self.assertEqual(balance, Money(103, 'SEK'))
Ejemplo n.º 3
0
 def test_purchase(self):
     account_obj = AccountFactory.create()
     wallet_obj = WalletFactory.create(owner_id=account_obj.id)
     WalletTrxFactory.create(wallet=wallet_obj, amount=Money(1000, 'SEK'))
     product_obj1 = ProductFactory.create(name='Billys Ooriginal',
                                          price=Money(13, 'SEK'))
     product_obj2 = ProductFactory.create(name='Kebabrulle',
                                          price=Money(30, 'SEK'))
     url = reverse('api:purchases-list')
     data = {
         'account_id':
         account_obj.id,
         'products': [
             {
                 'id': product_obj1.id,
                 'qty': 1
             },
             {
                 'id': product_obj2.id,
                 'qty': 3
             },
         ]
     }
     response = self.api_client.post(url, data, format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['amount'], 103)
     _, balance = wallet_api.get_balance(wallet_obj.owner_id, 'SEK')
     self.assertEqual(balance, Money(897, 'SEK'))
Ejemplo n.º 4
0
 def balance(self, obj):
     _, balance = wallet_api.get_balance(obj.owner_id,
                                         settings.DEFAULT_CURRENCY)
     return balance