diff options
| author | Tim Graham <timograham@gmail.com> | 2016-06-23 12:04:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-23 12:04:05 -0400 |
| commit | 81cdcb66bc74a0768d13f0e18872d46739028e64 (patch) | |
| tree | a7b0c5577f17242f992ebc308acfccc738635d0a /tests | |
| parent | b5a1c3a6f50362b57603e1833e44bff5628dde3c (diff) | |
Fixed #26791 -- Replaced LiveServerTestCase port ranges with binding to port 0.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_scripts/tests.py | 41 | ||||
| -rwxr-xr-x | tests/runtests.py | 9 | ||||
| -rw-r--r-- | tests/servers/tests.py | 45 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_liveserver.py | 19 |
4 files changed, 6 insertions, 108 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index fd7b7869ba..1376ea9203 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -28,7 +28,6 @@ from django.db.migrations.recorder import MigrationRecorder from django.test import ( LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings, ) -from django.test.runner import DiscoverRunner from django.utils._os import npath, upath from django.utils.encoding import force_text from django.utils.six import PY2, PY3, StringIO @@ -1276,46 +1275,6 @@ class ManageCheck(AdminScriptTestCase): self.assertNoOutput(out) -class CustomTestRunner(DiscoverRunner): - - def __init__(self, *args, **kwargs): - assert 'liveserver' not in kwargs - super(CustomTestRunner, self).__init__(*args, **kwargs) - - def run_tests(self, test_labels, extra_tests=None, **kwargs): - pass - - -class ManageTestCommand(AdminScriptTestCase): - def test_liveserver(self): - """ - Ensure that the --liveserver option sets the environment variable - correctly. - Refs #2879. - """ - - # Backup original state - address_predefined = 'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ - old_address = os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS') - - call_command('test', verbosity=0, testrunner='admin_scripts.tests.CustomTestRunner') - - # Original state hasn't changed - self.assertEqual('DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ, address_predefined) - self.assertEqual(os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS'), old_address) - - call_command('test', verbosity=0, testrunner='admin_scripts.tests.CustomTestRunner', liveserver='blah') - - # Variable was correctly set - self.assertEqual(os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'], 'blah') - - # Restore original state - if address_predefined: - os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address - else: - del os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] - - class ManageRunserver(AdminScriptTestCase): def setUp(self): from django.core.management.commands.runserver import Command diff --git a/tests/runtests.py b/tests/runtests.py index 122cb73282..07f2dc7a84 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -418,12 +418,6 @@ if __name__ == "__main__": 'test side effects not apparent with normal execution lineup.', ) parser.add_argument( - '--liveserver', - help='Overrides the default address where the live server (used with ' - 'LiveServerTestCase) is expected to run from. The default value ' - 'is localhost:8081-8179.', - ) - parser.add_argument( '--selenium', dest='selenium', action=ActionSelenium, metavar='BROWSERS', help='A comma-separated list of browsers to run the Selenium tests against.', ) @@ -467,9 +461,6 @@ if __name__ == "__main__": os.environ['DJANGO_SETTINGS_MODULE'] = 'test_sqlite' options.settings = os.environ['DJANGO_SETTINGS_MODULE'] - if options.liveserver is not None: - os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options.liveserver - if options.selenium: if not options.tags: options.tags = ['selenium'] diff --git a/tests/servers/tests.py b/tests/servers/tests.py index 57573622b0..aeddf86f62 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -9,7 +9,6 @@ import errno import os import socket -from django.core.exceptions import ImproperlyConfigured from django.test import LiveServerTestCase, override_settings from django.utils._os import upath from django.utils.http import urlencode @@ -44,55 +43,13 @@ class LiveServerBase(LiveServerTestCase): class LiveServerAddress(LiveServerBase): - """ - Ensure that the address set in the environment variable is valid. - Refs #2879. - """ @classmethod def setUpClass(cls): - # Backup original environment variable - address_predefined = 'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ - old_address = os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS') - - # Just the host is not accepted - cls.raises_exception('localhost', ImproperlyConfigured) - - # The host must be valid - cls.raises_exception('blahblahblah:8081', socket.error) - - # 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) - - # Restore original environment variable - if address_predefined: - os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address - else: - del os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] - + super(LiveServerAddress, cls).setUpClass() # put it in a list to prevent descriptor lookups in test cls.live_server_url_test = [cls.live_server_url] - @classmethod - def tearDownClass(cls): - # skip it, as setUpClass doesn't call its parent either - pass - - @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 - finally: - super(LiveServerAddress, cls).tearDownClass() - def test_live_server_url_is_class_property(self): self.assertIsInstance(self.live_server_url_test[0], text_type) self.assertEqual(self.live_server_url_test[0], self.live_server_url) diff --git a/tests/staticfiles_tests/test_liveserver.py b/tests/staticfiles_tests/test_liveserver.py index 2c9d7b71db..1bbadb337b 100644 --- a/tests/staticfiles_tests/test_liveserver.py +++ b/tests/staticfiles_tests/test_liveserver.py @@ -44,35 +44,26 @@ class StaticLiveServerChecks(LiveServerBase): @classmethod def setUpClass(cls): - # Backup original environment variable - address_predefined = 'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ - old_address = os.environ.get('DJANGO_LIVE_TEST_SERVER_ADDRESS') - # 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 - cls.raises_exception('localhost:8081', ImproperlyConfigured) + cls.raises_exception() TEST_SETTINGS['STATIC_URL'] = old_STATIC_URL - # Restore original environment variable - if address_predefined: - os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address - else: - del os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] - @classmethod def tearDownClass(cls): # skip it, as setUpClass doesn't call its parent either pass @classmethod - def raises_exception(cls, address, exception): - os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = address + def raises_exception(cls): try: super(StaticLiveServerChecks, cls).setUpClass() raise Exception("The line above should have raised an exception") - except exception: + except ImproperlyConfigured: + # This raises ImproperlyConfigured("You're using the staticfiles + # app without having set the required STATIC_URL setting.") pass finally: super(StaticLiveServerChecks, cls).tearDownClass() |
