summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Gocławski <gocek13@gmail.com>2015-08-30 14:27:38 +0200
committerTim Graham <timograham@gmail.com>2015-09-07 08:48:17 -0400
commita7901c2e090d720ef0427552387be7f14cbe2ac6 (patch)
treed1c19ecdd21a2e44a3235d5f611434563ab62ce9
parentb929d2d09d24705bc59d1d172921e1feade2777b (diff)
Refs #25328 -- Refactored LiveServerTestCase to make it extensible.
-rw-r--r--django/test/testcases.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 1ed3124d57..0c704ad951 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1251,8 +1251,7 @@ class LiveServerThread(threading.Thread):
# one that is free to use for the WSGI server.
for index, port in enumerate(self.possible_ports):
try:
- self.httpd = WSGIServer(
- (self.host, port), QuietWSGIRequestHandler)
+ self.httpd = self._create_server(port)
except socket.error as e:
if (index + 1 < len(self.possible_ports) and
e.errno == errno.EADDRINUSE):
@@ -1276,6 +1275,9 @@ class LiveServerThread(threading.Thread):
self.error = e
self.is_ready.set()
+ def _create_server(self, port):
+ return WSGIServer((self.host, port), QuietWSGIRequestHandler)
+
def terminate(self):
if hasattr(self, 'httpd'):
# Stop the WSGI server
@@ -1338,9 +1340,7 @@ class LiveServerTestCase(TransactionTestCase):
except Exception:
msg = 'Invalid address ("%s") for live server.' % specified_address
six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg), sys.exc_info()[2])
- cls.server_thread = LiveServerThread(host, possible_ports,
- cls.static_handler,
- connections_override=connections_override)
+ cls.server_thread = cls._create_server_thread(host, possible_ports, connections_override)
cls.server_thread.daemon = True
cls.server_thread.start()
@@ -1353,6 +1353,15 @@ class LiveServerTestCase(TransactionTestCase):
raise cls.server_thread.error
@classmethod
+ def _create_server_thread(cls, host, possible_ports, connections_override):
+ return LiveServerThread(
+ host,
+ possible_ports,
+ cls.static_handler,
+ connections_override=connections_override,
+ )
+
+ @classmethod
def _tearDownClassInternal(cls):
# There may not be a 'server_thread' attribute if setUpClass() for some
# reasons has raised an exception.