Delete temp objects to avoid constraint error
authorDiane Trout <diane@ghic.org>
Wed, 14 Sep 2016 23:03:09 +0000 (16:03 -0700)
committerDiane Trout <diane@ghic.org>
Wed, 14 Sep 2016 23:03:09 +0000 (16:03 -0700)
Django 1.10 with Postgres 9.? was throwing an error because the
samples_htsuser id that was assigned to an affiliation didn't exist in
the database.

The simplest solution I found was to delete the objects from the ORM,
I don't think they were ever actually created in the db so I'm not sure
how the constraint check was happening.

experiments/test_experiments.py

index b862d7be235d3901a2a1036074d720511657b7df..584a812aab1aacee754d31c97b74e184a30676b0 100644 (file)
@@ -91,6 +91,9 @@ class ExperimentsTestCases(TestCase):
 
     def tearDown(self):
         shutil.rmtree(self.tempdir)
+        self.user_odd.delete()
+        self.user_even.delete()
+        self.admin.delete()
 
     def test_flowcell_information(self):
         """
@@ -444,9 +447,9 @@ class TestEmailNotify(TestCase):
         self.admin = HTSUserFactory.create(username='admintest', is_staff=True)
         self.admin.set_password(self.password)
         self.admin.save()
-        self.super = HTSUserFactory.create(username='supertest', is_staff=True, is_superuser=True)
-        self.super.set_password(self.password)
-        self.super.save()
+        self.superuser = HTSUserFactory.create(username='supertest', is_staff=True, is_superuser=True)
+        self.superuser.set_password(self.password)
+        self.superuser.save()
 
         self.library = LibraryFactory.create()
         self.affiliation = AffiliationFactory()
@@ -457,6 +460,14 @@ class TestEmailNotify(TestCase):
 
         self.url = '/experiments/started/{}/'.format(self.fc.id)
 
+    def tearDown(self):
+        # with django 1.10 running against postgresql I had to delete these
+        # test objects or else I get a constraint error
+        self.affiliation.delete()
+        self.user.delete()
+        self.admin.delete()
+        self.superuser.delete()
+
     def test_started_email_not_logged_in(self):
         response = self.client.get(self.url)
         self.assertEqual(response.status_code, 302)