Commits

kkub...@bcc190cf-cafb-0310-a4f2-bffc1f526a37  committed 9fc4e0d

r10925@kevin-kubasiks-macbook: kkubasik | 2009-06-26 00:44:22 -0600
[gsoc2009-testing] Solved the threading issues. sqlite3 works again, :memory: as well. Tests run much faster now, and runtests.py behaves as expected when only running windmill tests. Still needs lots of commenting and cleanup

  • Participants
  • Parent commits bb02a52
  • Branches soc2009/test-improvements

Comments (0)

Files changed (5)

File django/test/windmill_tests.py

 except ImportError:
     from django.test.testcases import TestCase
 
+try:
+    from windmill.authoring import unit
+except Exception, e:
+    print "You don't appear to have windmill installed, please install before trying to run windmill tests again."
+    unit = None
 class StoppableWSGIServer(basehttp.WSGIServer):
     """WSGIServer with short timeout, so that server thread can stop this server."""
 
 
     def run(self):
         """Sets up test server and database and loops over handling http requests."""
+
+        # Must do database stuff in this new thread if database in memory.
+        from django.conf import settings
+        if settings.DATABASE_ENGINE == 'sqlite3' \
+            and (not settings.TEST_DATABASE_NAME or settings.TEST_DATABASE_NAME == ':memory:'):
+            from django.db import connection
+            print 'Creating test DB'
+            db_name = connection.creation.create_test_db(0)
+            #call_command('syncdb', 0, 0)
+            # Import the fixture data into the test database.
+            if hasattr(self, 'fixtures'):
+                print 'Loading fixtures.'
+                # We have to use this slightly awkward syntax due to the fact
+                # that we're using *args and **kwargs together.
+                call_command('loaddata', *self.fixtures, **{'verbosity': 0})
+
         try:
+            print "running thread"
             handler = basehttp.AdminMediaHandler(WSGIHandler())
             httpd = None
             while httpd is None:
                     httpd = StoppableWSGIServer(server_address, basehttp.WSGIRequestHandler)
                 except basehttp.WSGIServerException, e:
                     if "Address already in use" in str(e):
+                        print "Address already in use"
                         self.port +=1
                     else:
                         raise e
             self.started.set()
             return
 
-        # Must do database stuff in this new thread if database in memory.
-        from django.conf import settings
-        if settings.DATABASE_ENGINE == 'sqlite3' \
-                          and (not settings.TEST_DATABASE_NAME or settings.TEST_DATABASE_NAME == ':memory:'):
-            from django.db import connection
-            db_name = connection.creation.create_test_db(0)
-            #call_command('syncdb', 0, 0)
-            # Import the fixture data into the test database.
-            if hasattr(self, 'fixtures'):
-                # We have to use this slightly awkward syntax due to the fact
-                # that we're using *args and **kwargs together.
-                call_command('loaddata', *self.fixtures, **{'verbosity': 0})
 
         # Loop until we get a stop event.
         while not self._stopevent.isSet():
     self.server_thread.started.wait()
     if self.server_thread.error:
         raise self.server_thread.error
+    return self.server_thread.started
 
 def stop_test_server(self):
     if self.server_thread:
 
 TestCase.start_test_server = classmethod(start_test_server)
 TestCase.stop_test_server = classmethod(stop_test_server)
-try:
-    from windmill.authoring import unit
-    class WindmillDjangoUnitTest(TestCase, unit.WindmillUnitTestCase):
-        test_port = 8000
-        def setUp(self):
-            self.start_test_server('localhost', self.test_port)
-            self.test_url = 'http://localhost:%d' % self.server_thread.port
-            unit.WindmillUnitTestCase.setUp(self)
 
-        def tearDown(self):
-            unit.WindmillUnitTestCase.tearDown(self)
-            self.stop_test_server()
 
-    WindmillDjangoTransactionUnitTest = WindmillDjangoUnitTest
+class WindmillDjangoUnitTest(TestCase, unit.WindmillUnitTestCase):
+    test_port = 8000
+    def setUp(self):
+        self.start_test_server('localhost', self.test_port)
+        self.test_url = 'http://localhost:%d' % self.server_thread.port
+        unit.WindmillUnitTestCase.setUp(self)
 
-except Exception, e:
-    print "You don't appear to have windmill installed, please install before trying to run windmill tests again."
+    def tearDown(self):
+        unit.WindmillUnitTestCase.tearDown(self)
+        self.stop_test_server()
 
-
+WindmillDjangoTransactionUnitTest = WindmillDjangoUnitTest

File tests/regressiontests/admin_views/tests.py

         self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
 
 import os
-from django.test import windmill_tests as djangotest
+#from django.test import windmill_tests as djangotest
 #from windmill.authoring import djangotest
 #from windmill.conf import global_settings
 

File tests/regressiontests/admin_views/urls.py

 from django.contrib import admin
 import views
 import customadmin
-
-#admin.autodiscover()
-
-
+admin.autodiscover()
 urlpatterns = patterns('',
     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
     (r'^admin/secure-view/$', views.secure_view),

File tests/regressiontests/admin_views/windmilltests/__init__.py

 # import os
 # from django.test import windmill_tests as djangotest
 # #from windmill.authoring import djangotest
-from windmill.conf import global_settings
-ADMIN_URL =  "%s/test_admin/admin" % global_settings.TEST_URL
+
+#from windmill.conf import global_settings
+#ADMIN_URL =  "%s/test_admin/admin" % global_settings.TEST_URL
+ADMIN_URL = 'http://localhost:8000/test_admin/admin/'
+
 #
 # class TestProjectWindmillTest(djangotest.WindmillDjangoUnitTest):
 #     fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml', 'admin-views-unicode.xml',
     client.waits.forElement(link=u'Users', timeout=u'8000')
     client.click(link=u'Users')
     client.waits.forPageLoad(timeout=u'20000')
-    print client.commands.getPageText()
+    #print client.commands.getPageText()
     client.asserts.assertNode(link=u'adduser')
     client.asserts.assertNode(link=u'changeuser')
     client.asserts.assertNode(link=u'deleteuser')
 
     client.open(url=ADMIN_URL)
     client.waits.forPageLoad(timeout=u'20000')
-    print client.commands.getPageText()
-    client.click(xpath=u"//div[@id='content-main']/div[5]/table/tbody/tr[1]/td/a")
+    #print client.commands.getPageText()
+    client.click(xpath=u"//div[@id='content-main']/div[table/caption/a/text()='Flatpages']/table/tbody/tr[1]/td/a")
     client.waits.forPageLoad(timeout=u'20000')
-    print client.commands.getPageText()
+    #print client.commands.getPageText()
     client.click(id=u'id_url')
     client.type(text=u'/testflat/test/', id=u'id_url')
     client.type(text=u'Test Flat', id=u'id_title')
     client.waits.forPageLoad(timeout=u'20000')
     client.click(link=u'Home')
     client.waits.forPageLoad(timeout=u'20000')
-    client.click(xpath=u"//div[@id='content-main']/div[6]/table/tbody/tr[1]/th/a")
+    client.click(xpath=u"//div[@id='content-main']/div[table/caption/a/text()='Redirects']/table/tbody/tr[1]/th/a")
     client.waits.forPageLoad(timeout=u'20000')
     client.click(link=u'              Add redirect             ')
     client.waits.forPageLoad(timeout=u'20000')
     client.waits.forPageLoad(timeout=u'20000')
     client.open(url=u'http://localhost:8000/events/test')
     client.waits.forPageLoad(timeout=u'8000')
-    client.asserts.assertText(xpath=u'/html/body', validator=u'This is some unique test content. ')
+    client.asserts.assertText(xpath=u'/html/body', validator=u'\nThis is some unique test content.\n')
     client.open(url=u'http://localhost:8000/test_admin/admin/')
     client.waits.forPageLoad(timeout=u'8000')

File tests/runtests.py

 def django_tests(verbosity, interactive, test_labels):
     from django.conf import settings
 
-
     old_installed_apps = settings.INSTALLED_APPS
     old_test_database_name = settings.TEST_DATABASE_NAME
     old_root_urlconf = getattr(settings, "ROOT_URLCONF", "")
     # Load all the ALWAYS_INSTALLED_APPS.
     # (This import statement is intentionally delayed until after we
     # access settings because of the USE_I18N dependency.)
-    from django.db.models.loading import get_apps, load_app
+    from django.db.models.loading import get_apps, load_app, get_app
     get_apps()
 
     # Load all the test model apps.
         from windmill.conf import global_settings
         from django.core.management.commands.test_windmill import ServerContainer, attempt_import
         from django.test.windmill_tests import WindmillDjangoUnitTest
-        from django.db.models.loading import cache
-        from django.utils.importlib import import_module
-
+        #from django.db.models.loading import cache
+        #from django.utils.importlib import import_module
+        #from django.contrib import admin
         # print cache.app_models
         #      print cache.app_store
         # m = cache.app_models['invalid_models']
         #        print m
-        if do_std:
-            mod = import_module('.models','modeltests.invalid_models')
-            try:
-               #  print '1'
-               #  print mod
-               #  print '2'
-               #  print cache.app_store
-               #  print '3'
-               # # print cache.app_models
-               #  print '4'
-               #  print cache.app_models['invalid_models']
-
-                if 'invalid_models' in cache.app_models:
-                    del cache.app_models['invalid_models']
-                del cache.app_store[mod]
-            except Exception, e:
-                print e
+        # if do_std:
+        #             #mod = import_module('.models','modeltests.invalid_models')
+        #             try:
+        #                #  print '1'
+        #                #  print mod
+        #                #  print '2'
+        #                #  print cache.app_store
+        #                #  print '3'
+        #                # # print cache.app_models
+        #                #  print '4'
+        #                #  print cache.app_models['invalid_models']
+        #
+        #                 if 'invalid_models' in cache.app_models:
+        #                     del cache.app_models['invalid_models']
+        #                 #del cache.app_store[mod]
+        #             except Exception, e:
+        #                 print e
 
 
 
         #         sys.argv.remove('manage.py')
         #     if 'test_windmill' in sys.argv:
         #         sys.argv.remove('test_windmill')
+        #tempapps = settings.INSTALLED_APPS
 
-        #Load the admin interface
-        from django.contrib import admin
-        admin.autodiscover()
-
+        #get_apps()
+        #admin.autodiscover()
+        #settings.INSTALLED_APPS = tempapps
+        # from django.contrib import admin
+        #       admin.autodiscover()
+        import threading
         #Create the threaded server.
         server_container = ServerContainer()
         #Set the server's 'fixtures' attribute so they can be loaded in-thread if using sqlite's memory backend.
         server_container.__setattr__('fixtures', WINDMILL_FIXTURES )
         #Start the server thread.
-        server_container.start_test_server()
-
+        started = server_container.start_test_server()
+        print 'Waiting for server to get online'
+        started.wait()
+        print 'Database ready'
+        #sleep(5)
+        if 'regressiontests.bug8245' in settings.INSTALLED_APPS:
+            settings.INSTALLED_APPS.remove('regressiontests.bug8245')
+        if 'django.contrib.gis' in settings.INSTALLED_APPS:
+            settings.INSTALLED_APPS.remove('django.contrib.gis')
         global_settings.TEST_URL = 'http://localhost:%d' % server_container.server_thread.port
 
-        import windmill
+        #import windmill
         # windmill.stdout, windmill.stdin = sys.stdout, sys.stdin
         from windmill.authoring import setup_module, teardown_module
 
             from functest import runner
             runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
             import windmill
-            setup_module(tests[0][1])
-            #sys.argv = sys.argv + wmtests
-            sys.argv = wmtests
-            bin.cli()
-            teardown_module(tests[0][1])
+            for t in tests:
+                setup_module(t[1])
+                #sys.argv = sys.argv + wmtests
+                sys.argv = wmtests
+                bin.cli()
+                teardown_module(t[1])
             if testtotals['fail'] is not 0:
                 sleep(.5)
                 sys.exit(1)