예제 #1
0
 def test_raises_an_exception_when_trying_to_debit_negative_value(self):
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     with self.assertRaises(exceptions.InvalidAmount):
         Transfer.objects.create(source,
                                 destination,
                                 D('-20.00'),
                                 user=self.user)
예제 #2
0
 def test_includes_only_active_accounts(self):
     now = timezone.now()
     expired = AccountFactory(end_date=now - datetime.timedelta(days=1))
     AccountFactory(end_date=now + datetime.timedelta(days=1))
     AccountFactory(start_date=now,
                    end_date=now + datetime.timedelta(days=1))
     accounts = Account.active.all()
     self.assertTrue(expired not in accounts)
예제 #3
0
 def setUp(self):
     self.user = UserFactory(username="******")
     source = AccountFactory(primary_user=None, credit_limit=None)
     destination = AccountFactory()
     self.transfer = Transfer.objects.create(source,
                                             destination,
                                             D('10.00'),
                                             user=self.user)
예제 #4
0
 def setUp(self):
     self.user = UserFactory()
     self.source = AccountFactory(credit_limit=None, primary_user=None)
     self.destination = AccountFactory()
     self.transfer = facade.transfer(self.source,
                                     self.destination,
                                     D('100'),
                                     user=self.user,
                                     description="Give money to customer")
예제 #5
0
 def test_account_exception_raised_for_runtime_error(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     with mock.patch('izi_accounts.abstract_models.PostingManager._wrap'
                     ) as mock_method:
         mock_method.side_effect = RuntimeError()
         with self.assertRaises(exceptions.AccountException):
             facade.transfer(source, destination, D('100'), user)
예제 #6
0
 def test_raises_an_exception_when_trying_to_use_closed_source(self):
     source = AccountFactory(credit_limit=None)
     source.close()
     destination = AccountFactory()
     with self.assertRaises(exceptions.ClosedAccount):
         Transfer.objects.create(source,
                                 destination,
                                 D('20.00'),
                                 user=self.user)
예제 #7
0
 def test_raises_an_exception_when_trying_to_exceed_credit_limit_of_source(
         self):
     source = AccountFactory(primary_user=None, credit_limit=D('10.00'))
     destination = AccountFactory()
     with self.assertRaises(exceptions.InsufficientFunds):
         Transfer.objects.create(source,
                                 destination,
                                 D('20.00'),
                                 user=self.user)
예제 #8
0
 def test_is_permitted(self):
     self.user = UserFactory()
     now = timezone.now()
     source = AccountFactory(primary_user=None, credit_limit=None)
     destination = AccountFactory(end_date=now - timezone.timedelta(days=1))
     try:
         Transfer.objects.create(source,
                                 destination,
                                 D('20.00'),
                                 user=self.user)
     except exceptions.AccountException as e:
         self.fail("Transfer failed: %s" % e)
예제 #9
0
 def test_no_transaction_created_when_exception_raised(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     with mock.patch('izi_accounts.abstract_models.PostingManager._wrap'
                     ) as mock_method:
         mock_method.side_effect = RuntimeError()
         try:
             facade.transfer(source, destination, D('100'), user)
         except Exception:
             pass
     self.assertEqual(0, Transfer.objects.all().count())
     self.assertEqual(0, Transaction.objects.all().count())
예제 #10
0
class TestAFixedCreditLimitAccount(TestCase):
    def setUp(self):
        self.account = AccountFactory(credit_limit=D('500'),
                                      start_date=None,
                                      end_date=None)

    def test_permits_smaller_and_equal_debits(self):
        for amt in (D('0.00'), D('1.00'), D('500')):
            self.assertTrue(self.account.is_debit_permitted(amt))

    def test_does_not_permit_larger_amounts(self):
        for amt in (D('501'), D('1000')):
            self.assertFalse(self.account.is_debit_permitted(amt))
예제 #11
0
 def test_is_not_deleted_when_the_authorisor_is_deleted(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=None,
                             primary_user=user,
                             start_date=None,
                             end_date=None)
     destination = AccountFactory(start_date=None, end_date=None)
     txn = Transfer.objects.create(source,
                                   destination,
                                   D('20.00'),
                                   user=user)
     self.assertEqual(2, txn.transactions.all().count())
     user.delete()
     self.assertEqual(2, txn.transactions.all().count())
예제 #12
0
class TestAnUnlimitedCreditLimitAccount(TestCase):
    def setUp(self):
        self.account = AccountFactory(credit_limit=None,
                                      start_date=None,
                                      end_date=None)

    def test_permits_any_debit(self):
        for amt in (D('0.00'), D('1.00'), D('1000000')):
            self.assertTrue(self.account.is_debit_permitted(amt))
예제 #13
0
 def test_doesnt_explode(self):
     source = AccountFactory(credit_limit=None)
     destination = AccountFactory()
     facade.transfer(source, destination, D('1'))
예제 #14
0
 def test_account_exception_raised_for_invalid_transfer(self):
     user = UserFactory()
     source = AccountFactory(credit_limit=D('0.00'))
     destination = AccountFactory()
     with self.assertRaises(exceptions.AccountException):
         facade.transfer(source, destination, D('100'), user)
예제 #15
0
 def test_includes_only_expired_accounts(self):
     now = timezone.now()
     AccountFactory(end_date=now - datetime.timedelta(days=1))
     AccountFactory(end_date=now + datetime.timedelta(days=1))
     accounts = Account.expired.all()
     self.assertEqual(1, accounts.count())
예제 #16
0
 def setUp(self):
     self.account = AccountFactory(credit_limit=None,
                                   start_date=None,
                                   end_date=None)