MAINT: Refactor, move factories into tests
This commit is contained in:
parent
31714215d0
commit
02a21306fe
16 changed files with 49 additions and 42 deletions
52
ccdb/processing/tests/factories.py
Normal file
52
ccdb/processing/tests/factories.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
from datetime import datetime, date
|
||||
|
||||
from factory import DjangoModelFactory, Sequence, SubFactory, LazyFunction
|
||||
from factory.fuzzy import FuzzyText, FuzzyDate, FuzzyFloat, FuzzyInteger
|
||||
|
||||
from ..models import ProcessType, Reagent, Flaw, Processing
|
||||
from ccdb.misc.tests.factories import ContainerFactory, MeasurementUnitFactory
|
||||
|
||||
|
||||
class ProcessTypeFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = ProcessType
|
||||
|
||||
name = Sequence(lambda n: 'process_type{}'.format(n))
|
||||
code = Sequence(lambda n: 'pt{}'.format(n))
|
||||
description = FuzzyText(length=255)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class ReagentFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Reagent
|
||||
|
||||
name = Sequence(lambda n: 'reagent{}'.format(n))
|
||||
code = Sequence(lambda n: 'r{}'.format(n))
|
||||
reagent_class = FuzzyText(length=50)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class FlawFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Flaw
|
||||
|
||||
name = Sequence(lambda n: 'flaw{}'.format(n))
|
||||
description = FuzzyText(length=255)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class ProcessingFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Processing
|
||||
|
||||
process_type = SubFactory(ProcessTypeFactory)
|
||||
container = SubFactory(ContainerFactory)
|
||||
container_label = FuzzyText(length=50)
|
||||
process_date = FuzzyDate(date(2012, 1, 1))
|
||||
process_time = LazyFunction(datetime.now().time)
|
||||
reagent = SubFactory(ReagentFactory)
|
||||
reagent_volume = FuzzyFloat(0.0)
|
||||
measurement_unit = SubFactory(MeasurementUnitFactory)
|
||||
minutes_in_reagent = FuzzyInteger(0)
|
||||
flaw = SubFactory(FlawFactory)
|
|
@ -2,7 +2,8 @@ from django.test import TestCase
|
|||
from django.db import IntegrityError, transaction
|
||||
|
||||
from ..models import ProcessType, Reagent, Flaw, Processing
|
||||
from ..factories import ProcessTypeFactory, ReagentFactory, FlawFactory, ProcessingFactory
|
||||
from .factories import (ProcessTypeFactory, ReagentFactory, FlawFactory,
|
||||
ProcessingFactory)
|
||||
|
||||
|
||||
class ProcessTypeTestCase(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue