Skip to content

Commit 315e357

Browse files
committed
Use lazy evaluation for the tag fixture
1 parent 70a7ca8 commit 315e357

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

project/creditor/tests/fixtures/recurring.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
from .tags import TransactionTagFactory
1111

12+
def get_tag():
13+
if TransactionTag.objects.count():
14+
return factory.fuzzy.FuzzyChoice(TransactionTag.objects.all())
15+
return factory.SubFactory(TransactionTagFactory, label='Membership fee', tmatch='1')
1216

1317
class RecurringTransactionFactory(factory.django.DjangoModelFactory):
1418

@@ -19,7 +23,7 @@ class Meta:
1923
end = None
2024
rtype = factory.fuzzy.FuzzyChoice(RecurringTransaction.RTYPE_READABLE.keys())
2125
owner = factory.SubFactory(MemberFactory) # ternary expression does not really help us since the import is done before the test-db is created, TODO: Make a special helper class that can will evaluate the count later
22-
tag = (factory.fuzzy.FuzzyChoice(TransactionTag.objects.all())) if TransactionTag.objects.count() else (factory.SubFactory(TransactionTagFactory, label='Membership fee', tmatch='1'))
26+
tag = get_tag
2327
amount = factory.fuzzy.FuzzyInteger(-40, -10, 5)
2428
start = factory.LazyAttribute(lambda t: factory.fuzzy.FuzzyDate(t.owner.accepted).fuzz())
2529

0 commit comments

Comments
 (0)