Use unittest2's module hooks for setting up the django environment.
[htsworkflow.git] / htsworkflow / frontend / experiments / test_experiments.py
index e6d7484151149b4f7f7ce147cbacf046c28bb9d9..d4c556a9f8c0ef1d0d864a66e4629c8c3dfa17bd 100644 (file)
@@ -14,6 +14,9 @@ from django.conf import settings
 from django.core import mail
 from django.core.exceptions import ObjectDoesNotExist
 from django.test import TestCase
+from django.test.utils import setup_test_environment, teardown_test_environment
+from django.db import connection
+from django.conf import settings
 from htsworkflow.frontend.experiments import models
 from htsworkflow.frontend.experiments import experiments
 from htsworkflow.frontend.auth import apidata
@@ -25,6 +28,18 @@ LANE_SET = range(1,9)
 
 NSMAP = {'libns':'http://jumpgate.caltech.edu/wiki/LibraryOntology#'}
 
+from django.db import connection
+OLD_DB_NAME = settings.DATABASE_NAME
+VERBOSITY = 0
+def setUpModule():
+    setup_test_environment()
+    settings.DEBUG = False
+    connection.creation.create_test_db(VERBOSITY)
+
+def tearDownModule():
+    connection.creation.destroy_test_db(OLD_DB_NAME, VERBOSITY)
+    teardown_test_environment()
+
 class ClusterStationTestCases(TestCase):
     fixtures = ['test_flowcells.json']
 
@@ -482,7 +497,6 @@ class TestFileType(TestCase):
         self.assertEqual(u"<FileType: QSEQ tarfile>",
                              unicode(file_type_object))
 
-class TestFileType(TestCase):
     def test_find_file_type(self):
         file_type_objects = models.FileType.objects
         cases = [('woldlab_090921_HWUSI-EAS627_0009_42FC3AAXX_l7_r1.tar.bz2',
@@ -649,9 +663,7 @@ class TestSequencer(TestCase):
         load_string_into_model(model, 'rdfa', response.content)
 
         errmsgs = list(inference.run_validation())
-        self.assertEqual(len(errmsgs), 2)
-        for errmsg in errmsgs:
-            self.assertEqual(errmsg, 'Missing type for: http://localhost/')
+        self.assertEqual(len(errmsgs), 0)
 
     def test_lane_with_rdf_validation(self):
         from htsworkflow.util.rdfhelp import add_default_schemas, \
@@ -673,6 +685,30 @@ class TestSequencer(TestCase):
         load_string_into_model(model, 'rdfa', response.content)
 
         errmsgs = list(inference.run_validation())
-        self.assertEqual(len(errmsgs), 2)
-        for errmsg in errmsgs:
-            self.assertEqual(errmsg, 'Missing type for: http://localhost/')
+        self.assertEqual(len(errmsgs), 0)
+
+
+OLD_DB = settings.DATABASES['default']['NAME']
+def setUpModule():
+    setup_test_environment()
+    connection.creation.create_test_db()
+
+def tearDownModule():
+    connection.creation.destroy_test_db(OLD_DB)
+    teardown_test_environment()
+
+def suite():
+    from unittest2 import TestSuite, defaultTestLoader
+    suite = TestSuite()
+    for testcase in [ClusterStationTestCases,
+                     SequencerTestCases,
+                     ExerimentsTestCases,
+                     TestFileType,
+                     TestEmailNotify,
+                     TestSequencer]:
+        suite.addTests(defaultTestLoader.loadTestsFromTestCase(testcase))
+    return suite
+
+if __name__ == "__main__":
+    from unittest2 import main
+    main(defaultTest="suite")