Example #1
0
 def setUpTestData(cls):
     cls.customer = UserFactoryNoSignals(is_staff=False)
     cls.another_customer_account_rub = CustomerAccountFactory(
         owner=UserFactoryNoSignals(is_staff=False),
         currency=AccountCurrencyChoices.RUB,
         balance=Decimal(500),
     )
     cls.customer_account_rub = CustomerAccountFactory(
         owner=cls.customer,
         currency=AccountCurrencyChoices.RUB,
         balance=Decimal(500),
     )
     cls.another_customer_account_usd = CustomerAccountFactory(
         owner=UserFactoryNoSignals(is_staff=False),
         currency=AccountCurrencyChoices.USD,
         balance=Decimal(500),
     )
     cls.customer_account_usd = CustomerAccountFactory(
         owner=cls.customer,
         currency=AccountCurrencyChoices.USD,
         balance=Decimal(500),
     )
     cls.transactions = NewTransactionFactory.create_batch(3)
     cls.customer_transactions = NewTransactionFactory.create_batch(
         3, from_account=cls.customer_account_rub)
     cls.own_transaction_detail_url = reverse(
         'accounts:transaction-detail',
         kwargs={'pk': cls.customer_transactions[0].pk})
     cls.another_transaction_detail_url = reverse(
         'accounts:transaction-detail',
         kwargs={'pk': cls.transactions[0].pk})
     cls.list_url = reverse('accounts:transaction-list')
Example #2
0
 def test_customer_can_retrieve_list_of_own_accounts(self):
     CustomerAccountFactory.create_batch(3, owner=self.customer)
     response = self.client.get(self.list_url)
     self.assertEqual(
         CustomerAccount.objects.filter(owner=self.customer).count(),
         len(response.data))
     self.assertNotIn(self.another_customer_account.id,
                      [item['id'] for item in response.data])
Example #3
0
 def setUpTestData(cls):
     cls.staff_user = UserFactoryNoSignals(is_staff=True)
     cls.customer = UserFactoryNoSignals(is_staff=False)
     cls.account = CustomerAccountFactory(owner=cls.customer)
     cls.neighbor_account = CustomerAccountFactory(
         owner=UserFactoryNoSignals(is_staff=False))
     cls.detail_url = reverse('accounts:account-detail',
                              kwargs={'pk': cls.account.pk})
     cls.list_url = reverse('accounts:account-list')
Example #4
0
 def setUpTestData(cls):
     cls.customer = UserFactoryNoSignals(is_staff=False)
     cls.account = CustomerAccountFactory(
         owner=cls.customer,
         currency=AccountCurrencyChoices.RUB,
         balance=Decimal(100))
     cls.another_customer_account = CustomerAccountFactory(
         owner=UserFactoryNoSignals(is_staff=False))
     cls.detail_url = reverse('accounts:account-detail',
                              kwargs={'pk': cls.account.pk})
     cls.list_url = reverse('accounts:account-list')
Example #5
0
 def test_success_transfer(self):
     from_account = CustomerAccountFactory(balance=Decimal(60), )
     transaction = NewTransactionFactory(
         amount=Decimal(10),
         from_account=from_account,
         status=TransactionStatusChoices.PENDING,
     )
     transaction.commit()
     transaction.refresh_from_db()
     self.assertEqual(transaction.status, TransactionStatusChoices.SUCCESS)
Example #6
0
 def test_transfer_with_insufficient_funds(self):
     from_account = CustomerAccountFactory(balance=Decimal(10), )
     transaction = NewTransactionFactory(
         amount=Decimal(60),
         from_account=from_account,
         status=TransactionStatusChoices.PENDING,
     )
     with self.assertRaises(InsufficientFundsException):
         transaction.commit()
     transaction.refresh_from_db()
     self.assertEqual(transaction.status, TransactionStatusChoices.ERROR)
Example #7
0
 def test_create_new_different_currency_own_accounts(self):
     data = {
         'from_account':
         self.customer_account_rub.id,
         'to_account':
         CustomerAccountFactory(
             owner=self.customer,
             currency=AccountCurrencyChoices.EUR,
             balance=Decimal(100),
         ).id,
         'amount':
         Decimal(30)
     }
     response = self.client.post(self.list_url, data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #8
0
 def test_create_new_same_currency_own_accounts(self):
     data = {
         'from_account':
         self.customer_account_rub.id,
         'to_account':
         CustomerAccountFactory(
             owner=self.customer,
             currency=AccountCurrencyChoices.RUB,
             balance=Decimal(100),
         ).id,
         'amount':
         Decimal(30)
     }
     response = self.client.post(self.list_url, data)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertEqual(Decimal(response.data['fee']), 0)
Example #9
0
    def test_staff_user_can_access_any_account(self):
        CustomerAccountFactory.create_batch(3, owner=self.staff_user)

        response = self.client.get(self.list_url)
        self.assertEqual(CustomerAccount.objects.all().count(),
                         len(response.data))