Exemplo n.º 1
0
class TestASuccessfulTransfer(TestCase):
    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)

    def test_creates_2_transactions(self):
        self.assertEqual(2, self.transfer.transactions.all().count())

    def test_records_the_transferred_amount(self):
        self.assertEqual(D('10.00'), self.transfer.amount)

    def test_updates_source_balance(self):
        self.assertEqual(-D('10.00'), self.transfer.source.balance)

    def test_updates_destination_balance(self):
        self.assertEqual(D('10.00'), self.transfer.destination.balance)

    def test_cannot_be_deleted(self):
        with self.assertRaises(RuntimeError):
            self.transfer.delete()

    def test_records_static_user_information_in_case_user_is_deleted(self):
        self.assertEqual('barry', self.transfer.authorisor_username)
        self.user.delete()
        transfer = Transfer.objects.get(id=self.transfer.id)
        self.assertEqual('barry', transfer.authorisor_username)
Exemplo n.º 2
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())