Clean up unique on existing models
This commit is contained in:
parent
a44ac2fa81
commit
49eacdeef4
16 changed files with 141 additions and 12 deletions
ccdb/locations
|
@ -81,6 +81,19 @@ class Migration(migrations.Migration):
|
|||
'ordering': ['sort_order'],
|
||||
},
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='site',
|
||||
unique_together=set([('region', 'name', 'code')]),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='municipallocation',
|
||||
unique_together=set([('name', 'code')]),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='storagelocation',
|
||||
unique_together=set([('code', 'facility', 'building', 'room',
|
||||
'freezer', 'temp_c')]),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='region',
|
||||
unique_together=set([('name', 'code')]),
|
||||
|
|
|
@ -25,6 +25,7 @@ class Site(models.Model):
|
|||
return self.name
|
||||
|
||||
class Meta:
|
||||
unique_together = ('region', 'name', 'code')
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
|
@ -39,6 +40,7 @@ class MunicipalLocation(models.Model):
|
|||
return self.name
|
||||
|
||||
class Meta:
|
||||
unique_together = ('name', 'code')
|
||||
ordering = ['sort_order']
|
||||
|
||||
|
||||
|
@ -76,4 +78,6 @@ class StorageLocation(models.Model):
|
|||
return self.code
|
||||
|
||||
class Meta:
|
||||
unique_together = ('code', 'facility', 'building', 'room',
|
||||
'freezer', 'temp_c')
|
||||
ordering = ['sort_order']
|
||||
|
|
|
@ -26,6 +26,13 @@ class SiteTestCase(TestCase):
|
|||
self.assertTrue(isinstance(s, Site))
|
||||
self.assertEqual(s.__str__(), s.name)
|
||||
|
||||
def test_uniqueness(self):
|
||||
s1 = SiteFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
SiteFactory(region=s1.region, name=s1.name, code=s1.code)
|
||||
s3 = SiteFactory()
|
||||
self.assertTrue(isinstance(s3, Site))
|
||||
|
||||
|
||||
class MunicipalLocationTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
|
@ -33,6 +40,13 @@ class MunicipalLocationTestCase(TestCase):
|
|||
self.assertTrue(isinstance(m, MunicipalLocation))
|
||||
self.assertEqual(m.__str__(), m.name)
|
||||
|
||||
def test_uniqueness(self):
|
||||
m1 = MunicipalLocationFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
MunicipalLocationFactory(name=m1.name, code=m1.code)
|
||||
m3 = MunicipalLocationFactory()
|
||||
self.assertTrue(isinstance(m3, MunicipalLocation))
|
||||
|
||||
|
||||
class StudyLocationTestCase(TestCase):
|
||||
def test_creation(self):
|
||||
|
@ -54,5 +68,11 @@ class StorageLocationTestCase(TestCase):
|
|||
self.assertTrue(isinstance(s, StorageLocation))
|
||||
self.assertEqual(s.__str__(), s.code)
|
||||
|
||||
|
||||
|
||||
def test_uniqueness(self):
|
||||
s1 = StorageLocationFactory()
|
||||
with transaction.atomic(), self.assertRaises(IntegrityError):
|
||||
StorageLocationFactory(code=s1.code, facility=s1.facility,
|
||||
building=s1.building, room=s1.room,
|
||||
freezer=s1.freezer, temp_c=s1.temp_c)
|
||||
s3 = StorageLocationFactory()
|
||||
self.assertTrue(isinstance(s3, StorageLocation))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue