MAINT: Refactor, move factories into tests
This commit is contained in:
parent
31714215d0
commit
02a21306fe
16 changed files with 49 additions and 42 deletions
64
ccdb/locations/tests/factories.py
Normal file
64
ccdb/locations/tests/factories.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
from factory import DjangoModelFactory, Sequence, SubFactory
|
||||
from factory.fuzzy import FuzzyText, FuzzyChoice, FuzzyInteger
|
||||
|
||||
from ..models import (Region, Site, MunicipalLocation, StudyLocation,
|
||||
StorageLocation)
|
||||
|
||||
|
||||
class RegionFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Region
|
||||
|
||||
name = Sequence(lambda n: 'region{}'.format(n))
|
||||
code = Sequence(lambda n: 'r{}'.format(n))
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class SiteFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = Site
|
||||
|
||||
region = SubFactory(RegionFactory)
|
||||
name = Sequence(lambda n: 'site{}'.format(n))
|
||||
code = Sequence(lambda n: 's{}'.format(n))
|
||||
description = FuzzyText(length=100)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class MunicipalLocationFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = MunicipalLocation
|
||||
|
||||
name = Sequence(lambda n: 'municipal_location{}'.format(n))
|
||||
code = Sequence(lambda n: 'ml{}'.format(n))
|
||||
municipal_location_type = FuzzyText(length=50)
|
||||
description = FuzzyText(length=255)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class StudyLocationFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = StudyLocation
|
||||
|
||||
site = SubFactory(SiteFactory)
|
||||
name = Sequence(lambda n: 'study_location{}'.format(n))
|
||||
code = Sequence(lambda n: 'sl{}'.format(n))
|
||||
treatment_type = FuzzyText(length=100)
|
||||
municipal_location = SubFactory(MunicipalLocationFactory)
|
||||
collecting_location = FuzzyChoice([True, False])
|
||||
description = FuzzyText(length=255)
|
||||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class StorageLocationFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = StorageLocation
|
||||
|
||||
code = Sequence(lambda n: 'sl{}'.format(n))
|
||||
facility = FuzzyText(length=100)
|
||||
building = FuzzyText(length=100)
|
||||
room = FuzzyText(length=50)
|
||||
freezer = FuzzyText(length=50)
|
||||
temp_c = FuzzyInteger(-100, 100)
|
||||
description = FuzzyText(length=255)
|
||||
sort_order = Sequence(lambda n: n)
|
|
@ -1,9 +1,10 @@
|
|||
from django.test import TestCase
|
||||
from django.db import IntegrityError, transaction
|
||||
|
||||
from ..models import Region, Site, MunicipalLocation, StudyLocation, StorageLocation
|
||||
from ..factories import RegionFactory, SiteFactory, MunicipalLocationFactory, \
|
||||
StudyLocationFactory, StorageLocationFactory
|
||||
from ..models import (Region, Site, MunicipalLocation, StudyLocation,
|
||||
StorageLocation)
|
||||
from .factories import (RegionFactory, SiteFactory, MunicipalLocationFactory,
|
||||
StudyLocationFactory, StorageLocationFactory)
|
||||
|
||||
|
||||
class RegionTestCase(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue