mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +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:
|
||||
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."""
|
||||
|
||||
@ -46,7 +51,24 @@ class TestServerThread(threading.Thread):
|
||||
|
||||
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:
|
||||
@ -55,6 +77,7 @@ class TestServerThread(threading.Thread):
|
||||
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
|
||||
@ -65,18 +88,6 @@ class TestServerThread(threading.Thread):
|
||||
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():
|
||||
@ -99,6 +110,7 @@ def start_test_server(self, address='localhost', port=8000):
|
||||
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:
|
||||
@ -108,22 +120,17 @@ def stop_test_server(self):
|
||||
|
||||
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
|
||||
|
||||
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")
|
||||
|
||||
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
|
||||
|
||||
|
@ -2,10 +2,7 @@ from django.conf.urls.defaults import *
|
||||
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),
|
||||
|
@ -1,8 +1,11 @@
|
||||
# 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',
|
||||
@ -377,7 +380,7 @@ def test_AdminAuthContrib():
|
||||
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')
|
||||
@ -423,10 +426,10 @@ def test_contribFlatSitesRedirect():
|
||||
|
||||
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')
|
||||
@ -466,7 +469,7 @@ def test_contribFlatSitesRedirect():
|
||||
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')
|
||||
@ -489,6 +492,6 @@ def test_contribFlatSitesRedirect():
|
||||
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')
|
@ -104,7 +104,6 @@ class InvalidModelTestCase(unittest.TestCase):
|
||||
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", "")
|
||||
@ -140,7 +139,7 @@ def django_tests(verbosity, interactive, test_labels):
|
||||
# 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.
|
||||
@ -207,30 +206,30 @@ def django_tests(verbosity, interactive, test_labels):
|
||||
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
|
||||
|
||||
|
||||
|
||||
@ -263,21 +262,31 @@ def django_tests(verbosity, interactive, test_labels):
|
||||
# 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
|
||||
|
||||
@ -316,11 +325,12 @@ def django_tests(verbosity, interactive, test_labels):
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user