-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtest_factories.py
More file actions
36 lines (25 loc) · 959 Bytes
/
test_factories.py
File metadata and controls
36 lines (25 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from decimal import Decimal as D
import factory
from oscar_accounts.compact_oscar import get_model
class AccountFactory(factory.DjangoModelFactory):
start_date = None
end_date = None
class Meta:
model = get_model('oscar_accounts', 'Account')
class TransferFactory(factory.DjangoModelFactory):
source = factory.SubFactory(AccountFactory)
destination = factory.SubFactory(AccountFactory)
class Meta:
model = get_model('oscar_accounts', 'Transfer')
@classmethod
def _create(cls, model_class, *args, **kwargs):
instance = model_class(**kwargs)
instance.save()
return instance
class TransactionFactory(factory.DjangoModelFactory):
amount = D('10.00')
transfer = factory.SubFactory(
TransferFactory, amount=factory.SelfAttribute('..amount'))
account = factory.SubFactory(AccountFactory)
class Meta:
model = get_model('oscar_accounts', 'Transaction')