Fixed tests adding the account

This commit is contained in:
JKuijperM 2026-02-05 17:30:40 +01:00
parent 2c3eb4fb8f
commit 618b0d9484
2 changed files with 13 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import pytest
from datetime import date
from decimal import Decimal
from django.urls import reverse
from expenses.models import Expense, Category
from expenses.models import Account, Expense, Category
pytestmark = pytest.mark.django_db
@ -33,23 +33,28 @@ def test_dashboard_groups_by_category(client, django_user_model):
food = Category.objects.create(name='Food', owner=user)
rent = Category.objects.create(name='Rent', owner=user)
general_account = Account.objects.create(name='General', owner=user, initial_balance=300, active=True)
Expense.objects.create(
owner=user,
category=food,
amount=Decimal('10'),
date=date(2024, 1, 1),
account=general_account,
)
Expense.objects.create(
owner=user,
category=food,
amount=Decimal('5'),
date=date(2024, 1, 2),
account=general_account,
)
Expense.objects.create(
owner=user,
category=rent,
amount=Decimal('20'),
date=date(2024, 1, 3),
account=general_account,
)
response = client.get(
@ -70,12 +75,14 @@ def test_dashboard_filters_by_year(client, django_user_model):
client.login(username='test', password='1234')
cat = Category.objects.create(name='General', owner=user)
general_account = Account.objects.create(name='General', owner=user, initial_balance=300, active=True)
Expense.objects.create(
owner=user,
category=cat,
amount=10,
date=date(2023, 5, 1),
account=general_account,
)
Expense.objects.create(
@ -83,6 +90,7 @@ def test_dashboard_filters_by_year(client, django_user_model):
category=cat,
amount=20,
date=date(2024, 5, 1),
account=general_account,
)
response = client.get(

View File

@ -2,7 +2,7 @@ import pytest
from datetime import date
from decimal import Decimal
from django.urls import reverse
from expenses.models import Expense, Category, Tag
from expenses.models import Expense, Category, Tag, Account
pytestmark = pytest.mark.django_db
@ -13,11 +13,14 @@ def test_expense_can_have_tags(client, django_user_model):
tag = Tag.objects.create(name='Food', owner=user)
category = Category.objects.create(name='General', owner=user)
general_account = Account.objects.create(name='General', owner=user, initial_balance=300, active=True)
expense = Expense.objects.create(
owner=user,
category=category,
amount=10,
date=date.today(),
account=general_account,
)
expense.tags.add(tag)