Use unittest2's module hooks for setting up the django environment.
[htsworkflow.git] / htsworkflow / submission / test / test_condorfastq.py
index cffb5ac17175f59a3a4fc10219c5e151f578882b..09d68083c1ec50052c450a71e9d9e24356573cf7 100644 (file)
@@ -5,7 +5,12 @@ import os
 from pprint import pprint
 import shutil
 import tempfile
-import unittest
+
+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.submission.condorfastq import CondorFastqExtract
 from htsworkflow.submission.results import ResultMap
@@ -411,7 +416,7 @@ lib_turtle = """@prefix : <http://www.w3.org/1999/xhtml> .
 """
 HOST = "http://localhost"
 
-class TestCondorFastq(unittest.TestCase):
+class TestCondorFastq(TestCase):
     def setUp(self):
         self.cwd = os.getcwd()
 
@@ -675,10 +680,22 @@ class TestCondorFastq(unittest.TestCase):
             self.assertTrue('12345_C02F9ACXX_c202_l3_r2.fastq' in arguments[3])
 
 
+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():
-    suite = unittest.makeSuite(TestCondorFastq, 'test')
+    from unittest2 import TestSuite, defaultTestLoader
+    suite = TestSuite()
+    suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestCondorFastq))
     return suite
 
 if __name__ == "__main__":
-    unittest.main(defaultTest='suite')
-
+    from unittest2 import main
+    main(defaultTest='suite')