def test_DepositForm(self): data = { 'title': 'deposit', 'source_account': 'Work account', 'destination_account': self.account.pk, 'amount': 123, 'date': '2017-01-01' } for i in range(1, 3): form = DepositForm(data) self.assertTrue(form.is_valid()) transaction = form.save() self.assertIsInstance(transaction, Transaction) self.assertEquals(len(Transaction.objects.all()), i) self.assertEquals(len(Split.objects.all()), 2 * i) self.assertEquals(len(Account.objects.all()), 4) # System account is also present self.assertEquals( len(Account.objects.filter(account_type=Account.FOREIGN)), 1) new_account = Account.objects.get(account_type=Account.FOREIGN) self.assertEquals( Split.objects.all().aggregate( models.Sum('amount'))['amount__sum'], 0) self.assertTrue( Split.objects.get(account=new_account, opposing_account_id=self.account.pk, amount=-123, transaction=transaction).is_deposit) self.assertTrue( Split.objects.get(account_id=self.account.pk, opposing_account=new_account, amount=123, transaction=transaction).is_deposit)
def test_context_and_initial_DepositUpdate(self): form = DepositForm({ 'title': 'transaction_title', 'src': self.revenue.name, 'dst': self.account.id, 'amount': 123, 'date': '2017-01-01', 'transaction_type': Transaction.DEPOSIT }) self.assertTrue(form.is_valid()) transaction = form.save() url = reverse('transaction_update', args=[transaction.pk]) context = self.client.get(url).context self.assertRedirects( self.client.post(url, { 'title': 'transaction_title', 'src': self.revenue, 'dst': self.account.pk, 'amount': 123, 'date': '2017-01-01' }, args=[transaction.pk]), reverse('transaction_detail', args=[transaction.pk])) self.assertEqual(context['menu'], 'transactions') self.assertFalse('submenu' in context) self.assertEqual(context['form']['title'].value(), 'transaction_title') self.assertEqual(context['form']['src'].value(), self.revenue) self.assertEqual(context['form']['dst'].value(), self.account.pk) self.assertEqual(context['form']['amount'].value(), 123) self.assertEqual(str(context['form']['date'].value()), '2017-01-01')
def test_different_revenue_accounts(self): data = { 'title': 'deposit', 'source_account': 'Job a', 'destination_account': self.account.pk, 'amount': 123, 'date': '2017-01-01', 'transaction_type': Transaction.DEPOSIT, } form = DepositForm(data) self.assertTrue(form.is_valid()) form.save() data['source_account'] = 'Job b' form = DepositForm(data) self.assertTrue(form.is_valid()) form.save() self.assertEquals( len(Account.objects.filter(account_type=Account.FOREIGN)), 2)