mirror of
https://github.com/django/django.git
synced 2025-07-05 10:19:20 +00:00
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 git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11112 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
bbcffeaabe
commit
2dd363fc0c
@ -16,6 +16,11 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from django.test.testcases import TestCase
|
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):
|
class StoppableWSGIServer(basehttp.WSGIServer):
|
||||||
"""WSGIServer with short timeout, so that server thread can stop this server."""
|
"""WSGIServer with short timeout, so that server thread can stop this server."""
|
||||||
|
|
||||||
@ -46,7 +51,24 @@ class TestServerThread(threading.Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Sets up test server and database and loops over handling http requests."""
|
"""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:
|
try:
|
||||||
|
print "running thread"
|
||||||
handler = basehttp.AdminMediaHandler(WSGIHandler())
|
handler = basehttp.AdminMediaHandler(WSGIHandler())
|
||||||
httpd = None
|
httpd = None
|
||||||
while httpd is None:
|
while httpd is None:
|
||||||
@ -55,6 +77,7 @@ class TestServerThread(threading.Thread):
|
|||||||
httpd = StoppableWSGIServer(server_address, basehttp.WSGIRequestHandler)
|
httpd = StoppableWSGIServer(server_address, basehttp.WSGIRequestHandler)
|
||||||
except basehttp.WSGIServerException, e:
|
except basehttp.WSGIServerException, e:
|
||||||
if "Address already in use" in str(e):
|
if "Address already in use" in str(e):
|
||||||
|
print "Address already in use"
|
||||||
self.port +=1
|
self.port +=1
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
@ -65,18 +88,6 @@ class TestServerThread(threading.Thread):
|
|||||||
self.started.set()
|
self.started.set()
|
||||||
return
|
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.
|
# Loop until we get a stop event.
|
||||||
while not self._stopevent.isSet():
|
while not self._stopevent.isSet():
|
||||||
@ -99,6 +110,7 @@ def start_test_server(self, address='localhost', port=8000):
|
|||||||
self.server_thread.started.wait()
|
self.server_thread.started.wait()
|
||||||
if self.server_thread.error:
|
if self.server_thread.error:
|
||||||
raise self.server_thread.error
|
raise self.server_thread.error
|
||||||
|
return self.server_thread.started
|
||||||
|
|
||||||
def stop_test_server(self):
|
def stop_test_server(self):
|
||||||
if self.server_thread:
|
if self.server_thread:
|
||||||
@ -108,22 +120,17 @@ def stop_test_server(self):
|
|||||||
|
|
||||||
TestCase.start_test_server = classmethod(start_test_server)
|
TestCase.start_test_server = classmethod(start_test_server)
|
||||||
TestCase.stop_test_server = classmethod(stop_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
|
|
||||||
|
|
||||||
except Exception, e:
|
|
||||||
print "You don't appear to have windmill installed, please install before trying to run windmill tests again."
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -1421,7 +1421,7 @@ class AdminInlineTests(TestCase):
|
|||||||
self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
|
self.failUnlessEqual(FancyDoodad.objects.all()[0].name, "Fancy Doodad 1 Updated")
|
||||||
|
|
||||||
import os
|
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.authoring import djangotest
|
||||||
#from windmill.conf import global_settings
|
#from windmill.conf import global_settings
|
||||||
|
|
||||||
|
@ -2,10 +2,7 @@ from django.conf.urls.defaults import *
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
import views
|
import views
|
||||||
import customadmin
|
import customadmin
|
||||||
|
admin.autodiscover()
|
||||||
#admin.autodiscover()
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||||
(r'^admin/secure-view/$', views.secure_view),
|
(r'^admin/secure-view/$', views.secure_view),
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
# import os
|
# 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.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):
|
# class TestProjectWindmillTest(djangotest.WindmillDjangoUnitTest):
|
||||||
# fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml', 'admin-views-unicode.xml',
|
# fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', 'admin-views-fabrics.xml', 'admin-views-unicode.xml',
|
||||||
@ -377,7 +380,7 @@ def test_AdminAuthContrib():
|
|||||||
client.waits.forElement(link=u'Users', timeout=u'8000')
|
client.waits.forElement(link=u'Users', timeout=u'8000')
|
||||||
client.click(link=u'Users')
|
client.click(link=u'Users')
|
||||||
client.waits.forPageLoad(timeout=u'20000')
|
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'adduser')
|
||||||
client.asserts.assertNode(link=u'changeuser')
|
client.asserts.assertNode(link=u'changeuser')
|
||||||
client.asserts.assertNode(link=u'deleteuser')
|
client.asserts.assertNode(link=u'deleteuser')
|
||||||
@ -423,10 +426,10 @@ def test_contribFlatSitesRedirect():
|
|||||||
|
|
||||||
client.open(url=ADMIN_URL)
|
client.open(url=ADMIN_URL)
|
||||||
client.waits.forPageLoad(timeout=u'20000')
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
print client.commands.getPageText()
|
#print client.commands.getPageText()
|
||||||
client.click(xpath=u"//div[@id='content-main']/div[5]/table/tbody/tr[1]/td/a")
|
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')
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
print client.commands.getPageText()
|
#print client.commands.getPageText()
|
||||||
client.click(id=u'id_url')
|
client.click(id=u'id_url')
|
||||||
client.type(text=u'/testflat/test/', 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.type(text=u'Test Flat', id=u'id_title')
|
||||||
@ -466,7 +469,7 @@ def test_contribFlatSitesRedirect():
|
|||||||
client.waits.forPageLoad(timeout=u'20000')
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
client.click(link=u'Home')
|
client.click(link=u'Home')
|
||||||
client.waits.forPageLoad(timeout=u'20000')
|
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.waits.forPageLoad(timeout=u'20000')
|
||||||
client.click(link=u' Add redirect ')
|
client.click(link=u' Add redirect ')
|
||||||
client.waits.forPageLoad(timeout=u'20000')
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
@ -489,6 +492,6 @@ def test_contribFlatSitesRedirect():
|
|||||||
client.waits.forPageLoad(timeout=u'20000')
|
client.waits.forPageLoad(timeout=u'20000')
|
||||||
client.open(url=u'http://localhost:8000/events/test')
|
client.open(url=u'http://localhost:8000/events/test')
|
||||||
client.waits.forPageLoad(timeout=u'8000')
|
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.open(url=u'http://localhost:8000/test_admin/admin/')
|
||||||
client.waits.forPageLoad(timeout=u'8000')
|
client.waits.forPageLoad(timeout=u'8000')
|
@ -104,7 +104,6 @@ class InvalidModelTestCase(unittest.TestCase):
|
|||||||
def django_tests(verbosity, interactive, test_labels):
|
def django_tests(verbosity, interactive, test_labels):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
old_installed_apps = settings.INSTALLED_APPS
|
old_installed_apps = settings.INSTALLED_APPS
|
||||||
old_test_database_name = settings.TEST_DATABASE_NAME
|
old_test_database_name = settings.TEST_DATABASE_NAME
|
||||||
old_root_urlconf = getattr(settings, "ROOT_URLCONF", "")
|
old_root_urlconf = getattr(settings, "ROOT_URLCONF", "")
|
||||||
@ -140,7 +139,7 @@ def django_tests(verbosity, interactive, test_labels):
|
|||||||
# Load all the ALWAYS_INSTALLED_APPS.
|
# Load all the ALWAYS_INSTALLED_APPS.
|
||||||
# (This import statement is intentionally delayed until after we
|
# (This import statement is intentionally delayed until after we
|
||||||
# access settings because of the USE_I18N dependency.)
|
# 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()
|
get_apps()
|
||||||
|
|
||||||
# Load all the test model apps.
|
# Load all the test model apps.
|
||||||
@ -207,30 +206,30 @@ def django_tests(verbosity, interactive, test_labels):
|
|||||||
from windmill.conf import global_settings
|
from windmill.conf import global_settings
|
||||||
from django.core.management.commands.test_windmill import ServerContainer, attempt_import
|
from django.core.management.commands.test_windmill import ServerContainer, attempt_import
|
||||||
from django.test.windmill_tests import WindmillDjangoUnitTest
|
from django.test.windmill_tests import WindmillDjangoUnitTest
|
||||||
from django.db.models.loading import cache
|
#from django.db.models.loading import cache
|
||||||
from django.utils.importlib import import_module
|
#from django.utils.importlib import import_module
|
||||||
|
#from django.contrib import admin
|
||||||
# print cache.app_models
|
# print cache.app_models
|
||||||
# print cache.app_store
|
# print cache.app_store
|
||||||
# m = cache.app_models['invalid_models']
|
# m = cache.app_models['invalid_models']
|
||||||
# print m
|
# print m
|
||||||
if do_std:
|
# if do_std:
|
||||||
mod = import_module('.models','modeltests.invalid_models')
|
# #mod = import_module('.models','modeltests.invalid_models')
|
||||||
try:
|
# try:
|
||||||
# print '1'
|
# # print '1'
|
||||||
# print mod
|
# # print mod
|
||||||
# print '2'
|
# # print '2'
|
||||||
# print cache.app_store
|
# # print cache.app_store
|
||||||
# print '3'
|
# # print '3'
|
||||||
# # print cache.app_models
|
# # # print cache.app_models
|
||||||
# print '4'
|
# # print '4'
|
||||||
# print cache.app_models['invalid_models']
|
# # print cache.app_models['invalid_models']
|
||||||
|
#
|
||||||
if 'invalid_models' in cache.app_models:
|
# if 'invalid_models' in cache.app_models:
|
||||||
del cache.app_models['invalid_models']
|
# del cache.app_models['invalid_models']
|
||||||
del cache.app_store[mod]
|
# #del cache.app_store[mod]
|
||||||
except Exception, e:
|
# except Exception, e:
|
||||||
print e
|
# print e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -263,21 +262,31 @@ def django_tests(verbosity, interactive, test_labels):
|
|||||||
# sys.argv.remove('manage.py')
|
# sys.argv.remove('manage.py')
|
||||||
# if 'test_windmill' in sys.argv:
|
# if 'test_windmill' in sys.argv:
|
||||||
# sys.argv.remove('test_windmill')
|
# sys.argv.remove('test_windmill')
|
||||||
|
#tempapps = settings.INSTALLED_APPS
|
||||||
|
|
||||||
#Load the admin interface
|
#get_apps()
|
||||||
from django.contrib import admin
|
#admin.autodiscover()
|
||||||
admin.autodiscover()
|
#settings.INSTALLED_APPS = tempapps
|
||||||
|
# from django.contrib import admin
|
||||||
|
# admin.autodiscover()
|
||||||
|
import threading
|
||||||
#Create the threaded server.
|
#Create the threaded server.
|
||||||
server_container = ServerContainer()
|
server_container = ServerContainer()
|
||||||
#Set the server's 'fixtures' attribute so they can be loaded in-thread if using sqlite's memory backend.
|
#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 )
|
server_container.__setattr__('fixtures', WINDMILL_FIXTURES )
|
||||||
#Start the server thread.
|
#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
|
global_settings.TEST_URL = 'http://localhost:%d' % server_container.server_thread.port
|
||||||
|
|
||||||
import windmill
|
#import windmill
|
||||||
# windmill.stdout, windmill.stdin = sys.stdout, sys.stdin
|
# windmill.stdout, windmill.stdin = sys.stdout, sys.stdin
|
||||||
from windmill.authoring import setup_module, teardown_module
|
from windmill.authoring import setup_module, teardown_module
|
||||||
|
|
||||||
@ -316,11 +325,12 @@ def django_tests(verbosity, interactive, test_labels):
|
|||||||
from functest import runner
|
from functest import runner
|
||||||
runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
|
runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) )
|
||||||
import windmill
|
import windmill
|
||||||
setup_module(tests[0][1])
|
for t in tests:
|
||||||
#sys.argv = sys.argv + wmtests
|
setup_module(t[1])
|
||||||
sys.argv = wmtests
|
#sys.argv = sys.argv + wmtests
|
||||||
bin.cli()
|
sys.argv = wmtests
|
||||||
teardown_module(tests[0][1])
|
bin.cli()
|
||||||
|
teardown_module(t[1])
|
||||||
if testtotals['fail'] is not 0:
|
if testtotals['fail'] is not 0:
|
||||||
sleep(.5)
|
sleep(.5)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user