mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Added the ability to specify multiple ports available for the LiveServerTestCase WSGI server. This allows multiple processes to run the tests simultaneously and is particularly useful in a continuous integration context. Many thanks to Aymeric Augustin for the suggestions and feedback.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17289 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -101,10 +101,7 @@ class LiveServerBase(LiveServerTestCase):
|
||||
super(LiveServerBase, cls).tearDownClass()
|
||||
|
||||
def urlopen(self, url):
|
||||
server_address = os.environ.get(
|
||||
'DJANGO_LIVE_TEST_SERVER_ADDRESS', 'localhost:8081')
|
||||
base = 'http://%s' % server_address
|
||||
return urllib2.urlopen(base + url)
|
||||
return urllib2.urlopen(self.live_server_url + url)
|
||||
|
||||
|
||||
class LiveServerAddress(LiveServerBase):
|
||||
@@ -120,31 +117,23 @@ class LiveServerAddress(LiveServerBase):
|
||||
old_address = os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS')
|
||||
|
||||
# Just the host is not accepted
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = 'localhost'
|
||||
try:
|
||||
super(LiveServerAddress, cls).setUpClass()
|
||||
raise Exception("The line above should have raised an exception")
|
||||
except ImproperlyConfigured:
|
||||
pass
|
||||
cls.raises_exception('localhost', ImproperlyConfigured)
|
||||
|
||||
# The host must be valid
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = 'blahblahblah:8081'
|
||||
try:
|
||||
super(LiveServerAddress, cls).setUpClass()
|
||||
raise Exception("The line above should have raised an exception")
|
||||
except WSGIServerException:
|
||||
pass
|
||||
cls.raises_exception('blahblahblah:8081', WSGIServerException)
|
||||
|
||||
# The list of ports must be in a valid format
|
||||
cls.raises_exception('localhost:8081,', ImproperlyConfigured)
|
||||
cls.raises_exception('localhost:8081,blah', ImproperlyConfigured)
|
||||
cls.raises_exception('localhost:8081-', ImproperlyConfigured)
|
||||
cls.raises_exception('localhost:8081-blah', ImproperlyConfigured)
|
||||
cls.raises_exception('localhost:8081-8082-8083', ImproperlyConfigured)
|
||||
|
||||
# If contrib.staticfiles isn't configured properly, the exception
|
||||
# should bubble up to the main thread.
|
||||
old_STATIC_URL = TEST_SETTINGS['STATIC_URL']
|
||||
TEST_SETTINGS['STATIC_URL'] = None
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = 'localhost:8081'
|
||||
try:
|
||||
super(LiveServerAddress, cls).setUpClass()
|
||||
raise Exception("The line above should have raised an exception")
|
||||
except ImproperlyConfigured:
|
||||
pass
|
||||
cls.raises_exception('localhost:8081', ImproperlyConfigured)
|
||||
TEST_SETTINGS['STATIC_URL'] = old_STATIC_URL
|
||||
|
||||
# Restore original environment variable
|
||||
@@ -153,6 +142,15 @@ class LiveServerAddress(LiveServerBase):
|
||||
else:
|
||||
del os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS']
|
||||
|
||||
@classmethod
|
||||
def raises_exception(cls, address, exception):
|
||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = address
|
||||
try:
|
||||
super(LiveServerAddress, cls).setUpClass()
|
||||
raise Exception("The line above should have raised an exception")
|
||||
except exception:
|
||||
pass
|
||||
|
||||
def test_test_test(self):
|
||||
# Intentionally empty method so that the test is picked up by the
|
||||
# test runner and the overriden setUpClass() method is executed.
|
||||
|
||||
Reference in New Issue
Block a user