TST: Coverage and adding new model tests
This commit is contained in:
parent
5c69e774f9
commit
31714215d0
10 changed files with 65 additions and 11 deletions
|
@ -1,8 +1,9 @@
|
|||
from factory import DjangoModelFactory, Sequence, SubFactory
|
||||
from factory.fuzzy import FuzzyText, FuzzyChoice, FuzzyInteger
|
||||
|
||||
from .models import Species, CollectionSpecies
|
||||
from ..collections_ccdb.factories import CollectionFactory
|
||||
from .models import Species, TrapSpecies, CollectionSpecies
|
||||
from ..collections_ccdb.factories import (CollectionFactory,
|
||||
CollectionTrapFactory)
|
||||
|
||||
|
||||
class SpeciesFactory(DjangoModelFactory):
|
||||
|
@ -16,6 +17,17 @@ class SpeciesFactory(DjangoModelFactory):
|
|||
sort_order = Sequence(lambda n: n)
|
||||
|
||||
|
||||
class TrapSpeciesFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = TrapSpecies
|
||||
|
||||
collection_trap = SubFactory(CollectionTrapFactory)
|
||||
species = SubFactory(SpeciesFactory)
|
||||
sex = FuzzyText(length=25)
|
||||
count = FuzzyInteger(0)
|
||||
count_estimated = FuzzyChoice(choices=[True, False])
|
||||
|
||||
|
||||
class CollectionSpeciesFactory(DjangoModelFactory):
|
||||
class Meta:
|
||||
model = CollectionSpecies
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from django.test import TestCase
|
||||
from django.db import IntegrityError, transaction
|
||||
|
||||
from ..models import Species, CollectionSpecies
|
||||
from ..factories import SpeciesFactory, CollectionSpeciesFactory
|
||||
from ..models import Species, TrapSpecies, CollectionSpecies
|
||||
from ..factories import (SpeciesFactory, TrapSpeciesFactory,
|
||||
CollectionSpeciesFactory)
|
||||
|
||||
|
||||
class SpeciesTestCase(TestCase):
|
||||
|
@ -19,6 +20,14 @@ class SpeciesTestCase(TestCase):
|
|||
self.assertTrue(isinstance(s3, Species))
|
||||
|
||||
|
||||
class TrapSpeciesTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
t = TrapSpeciesFactory()
|
||||
self.assertTrue(isinstance(t, TrapSpecies))
|
||||
label = "{} {}".format(t.collection_trap, t.species)
|
||||
self.assertEqual(t.__str__(), label)
|
||||
|
||||
|
||||
class CollectionSpeciesTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
c = CollectionSpeciesFactory()
|
||||
|
@ -29,6 +38,7 @@ class CollectionSpeciesTestCase(TestCase):
|
|||
def test_uniqueness(self):
|
||||
c1 = CollectionSpeciesFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
CollectionSpeciesFactory(collection=c1.collection, species=c1.species)
|
||||
CollectionSpeciesFactory(collection=c1.collection,
|
||||
species=c1.species)
|
||||
c3 = CollectionSpeciesFactory()
|
||||
self.assertTrue(isinstance(c3, CollectionSpecies))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue