-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix updating recurrences when no transactions are available
- Loading branch information
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from datetime import date | ||
|
||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
from silverstrike.models import Account, RecurringTransaction, Transaction | ||
from silverstrike.tests import create_transaction | ||
|
||
|
||
class UpdateRecurrenceDateTests(TestCase): | ||
def setUp(self): | ||
User.objects.create_superuser(username='admin', email='email@example.com', password='pass') | ||
self.client.login(username='admin', password='pass') | ||
self.account = Account.objects.create(name='first account') | ||
self.foreign = Account.objects.create( | ||
name="other account", account_type=Account.FOREIGN) | ||
self.recurrence = RecurringTransaction.objects.create( | ||
title='A recurrence', | ||
amount=500, | ||
date=date(2019, 1, 1), | ||
src=self.account, | ||
dst=self.foreign, | ||
interval=RecurringTransaction.MONTHLY, | ||
transaction_type=Transaction.WITHDRAW, | ||
usual_month_day=1 | ||
) | ||
self.transaction = create_transaction('title', self.account, self.foreign, 500, | ||
Transaction.WITHDRAW, date(2019, 1, 1)) | ||
self.transaction.recurrence = self.recurrence | ||
self.transaction.save() | ||
|
||
def test_no_update_when_transactions_are_in_past(self): | ||
self.recurrence.date = date(2019, 2, 1) | ||
response = self.client.post(reverse('update_current_recurrences')) | ||
self.assertRedirects(response, reverse('recurrences')) | ||
self.recurrence.refresh_from_db() | ||
self.assertEqual(self.recurrence.date, date(2019, 2, 1)) | ||
|
||
def test_recurrence_gets_updated(self): | ||
response = self.client.post(reverse('update_current_recurrences')) | ||
self.assertRedirects(response, reverse('recurrences')) | ||
self.recurrence.refresh_from_db() | ||
self.assertEqual(self.recurrence.date, date(2019, 2, 1)) | ||
|
||
def test_recurrence_with_no_transactions(self): | ||
self.transaction.delete() | ||
response = self.client.post(reverse('update_current_recurrences')) | ||
self.assertRedirects(response, reverse('recurrences')) | ||
self.recurrence.refresh_from_db() | ||
self.assertEqual(self.recurrence.date, date(2019, 1, 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters