MAINT: Refactor, move factories into tests
This commit is contained in:
parent
31714215d0
commit
02a21306fe
16 changed files with 49 additions and 42 deletions
40
ccdb/projects/tests/factories.py
Normal file
40
ccdb/projects/tests/factories.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from datetime import datetime
|
||||
|
||||
import factory
|
||||
|
||||
from ..models import Project, Grant, GrantReport
|
||||
|
||||
|
||||
class ProjectFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Project
|
||||
|
||||
name = factory.Sequence(lambda n: 'project{}'.format(n))
|
||||
code = factory.Sequence(lambda n: 'p{}'.format(n))
|
||||
iacuc_number = 'abc'
|
||||
description = 'lorem ipsum'
|
||||
sort_order = factory.Sequence(lambda n: n)
|
||||
|
||||
|
||||
class GrantFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Grant
|
||||
|
||||
title = factory.Sequence(lambda n: 'grant{}'.format(n))
|
||||
code = factory.Sequence(lambda n: 'g{}'.format(n))
|
||||
description = 'lorem ipsum'
|
||||
sort_order = factory.Sequence(lambda n: n)
|
||||
|
||||
|
||||
class GrantReportFactory(factory.DjangoModelFactory):
|
||||
class Meta:
|
||||
model = GrantReport
|
||||
|
||||
grant = factory.SubFactory(GrantFactory)
|
||||
title = factory.Sequence(lambda n: 'grant{}'.format(n))
|
||||
report_type = 'lorem ipsum'
|
||||
description = 'lorem ipsum'
|
||||
due_date = factory.LazyFunction(datetime.now)
|
||||
submitted_date = factory.LazyFunction(datetime.now)
|
||||
sort_order = factory.Sequence(lambda n: n)
|
||||
|
|
@ -2,7 +2,7 @@ from django.test import TestCase
|
|||
from django.db import IntegrityError, transaction
|
||||
|
||||
from ..models import Project, Grant, GrantReport
|
||||
from ..factories import ProjectFactory, GrantFactory, GrantReportFactory
|
||||
from .factories import ProjectFactory, GrantFactory, GrantReportFactory
|
||||
|
||||
|
||||
class ProjectTestCase(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue