diff options
| author | Julien Phalip <jphalip@gmail.com> | 2011-12-29 20:22:13 +0000 |
|---|---|---|
| committer | Julien Phalip <jphalip@gmail.com> | 2011-12-29 20:22:13 +0000 |
| commit | 0bf2d337701a41d9fc42c6cac608e18f989a9866 (patch) | |
| tree | 8b0e4204477051cd0be749febd60eb9187c74bec /tests | |
| parent | a82204fa9a5c9262252cb038628ce49477e0f7cf (diff) | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/servers/tests.py | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py index 8cf1b78600..d237c83c65 100644 --- a/tests/regressiontests/servers/tests.py +++ b/tests/regressiontests/servers/tests.py @@ -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. |
