locations: tests and data migration
This commit is contained in:
parent
2bbfe7dd1c
commit
831e4091dc
4 changed files with 223 additions and 0 deletions
0
ccdb/locations/tests/__init__.py
Normal file
0
ccdb/locations/tests/__init__.py
Normal file
58
ccdb/locations/tests/test_models.py
Normal file
58
ccdb/locations/tests/test_models.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
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
|
||||
|
||||
|
||||
class RegionTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
r = RegionFactory()
|
||||
self.assertTrue(isinstance(r, Region))
|
||||
self.assertEqual(r.__str__(), r.name)
|
||||
|
||||
def test_uniqueness(self):
|
||||
r1 = RegionFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
RegionFactory(name=r1.name, code=r1.code)
|
||||
r3 = RegionFactory()
|
||||
self.assertTrue(isinstance(r3, Region))
|
||||
|
||||
|
||||
class SiteTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
s = SiteFactory()
|
||||
self.assertTrue(isinstance(s, Site))
|
||||
self.assertEqual(s.__str__(), s.name)
|
||||
|
||||
|
||||
class MunicipalLocationTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
m = MunicipalLocationFactory()
|
||||
self.assertTrue(isinstance(m, MunicipalLocation))
|
||||
self.assertEqual(m.__str__(), m.name)
|
||||
|
||||
|
||||
class StudyLocationTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
s = StudyLocationFactory()
|
||||
self.assertTrue(isinstance(s, StudyLocation))
|
||||
self.assertEqual(s.__str__(), s.code)
|
||||
|
||||
def test_uniqueness(self):
|
||||
s1 = StudyLocationFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
StudyLocationFactory(site=s1.site, name=s1.name)
|
||||
s3 = StudyLocationFactory()
|
||||
self.assertTrue(isinstance(s3, StudyLocation))
|
||||
|
||||
|
||||
class StorageLocationTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
s = StorageLocationFactory()
|
||||
self.assertTrue(isinstance(s, StorageLocation))
|
||||
self.assertEqual(s.__str__(), s.code)
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue