summaryrefslogtreecommitdiff
path: root/tests/servers
diff options
context:
space:
mode:
authorNadège Michel <michel.nadege@gmail.com>2016-12-06 20:38:43 +0100
committerTim Graham <timograham@gmail.com>2017-02-09 19:08:32 -0500
commitbece837829eafbc22f2598dadf82c9a8364b085a (patch)
tree5dbe0327726551b6c3f5defd2a838b1add963867 /tests/servers
parentc4e2fc5d9872c9a0c9c052a2e124f8a9b87de9b4 (diff)
downloaddjango-bece837829eafbc22f2598dadf82c9a8364b085a.tar.gz
Fixed #20238 -- Added threading support to LiveServerTestCase.
Diffstat (limited to 'tests/servers')
-rw-r--r--tests/servers/tests.py16
-rw-r--r--tests/servers/urls.py3
-rw-r--r--tests/servers/views.py17
3 files changed, 36 insertions, 0 deletions
diff --git a/tests/servers/tests.py b/tests/servers/tests.py
index 5052f57908..b114b968df 100644
--- a/tests/servers/tests.py
+++ b/tests/servers/tests.py
@@ -130,3 +130,19 @@ class LiveServerPort(LiveServerBase):
finally:
if hasattr(TestCase, 'server_thread'):
TestCase.server_thread.terminate()
+
+
+class LiverServerThreadedTests(LiveServerBase):
+ """If LiverServerTestCase isn't threaded, these tests will hang."""
+
+ def test_view_calls_subview(self):
+ url = '/subview_calling_view/?%s' % urlencode({'url': self.live_server_url})
+ with self.urlopen(url) as f:
+ self.assertEqual(f.read(), b'subview calling view: subview')
+
+ def test_check_model_instance_from_subview(self):
+ url = '/check_model_instance_from_subview/?%s' % urlencode({
+ 'url': self.live_server_url,
+ })
+ with self.urlopen(url) as f:
+ self.assertIn(b'emily', f.read())
diff --git a/tests/servers/urls.py b/tests/servers/urls.py
index 868ecc34f9..4963bde357 100644
--- a/tests/servers/urls.py
+++ b/tests/servers/urls.py
@@ -7,4 +7,7 @@ urlpatterns = [
url(r'^model_view/$', views.model_view),
url(r'^create_model_instance/$', views.create_model_instance),
url(r'^environ_view/$', views.environ_view),
+ url(r'^subview_calling_view/$', views.subview_calling_view),
+ url(r'^subview/$', views.subview),
+ url(r'^check_model_instance_from_subview/$', views.check_model_instance_from_subview),
]
diff --git a/tests/servers/views.py b/tests/servers/views.py
index f1fb8714c5..3fa99380b1 100644
--- a/tests/servers/views.py
+++ b/tests/servers/views.py
@@ -1,3 +1,5 @@
+from urllib.request import urlopen
+
from django.http import HttpResponse
from .models import Person
@@ -20,3 +22,18 @@ def create_model_instance(request):
def environ_view(request):
return HttpResponse("\n".join("%s: %r" % (k, v) for k, v in request.environ.items()))
+
+
+def subview(request):
+ return HttpResponse('subview')
+
+
+def subview_calling_view(request):
+ response = urlopen(request.GET['url'] + '/subview/')
+ return HttpResponse('subview calling view: {}'.format(response.read().decode()))
+
+
+def check_model_instance_from_subview(request):
+ urlopen(request.GET['url'] + '/create_model_instance/')
+ response = urlopen(request.GET['url'] + '/model_view/')
+ return HttpResponse('subview calling view: {}'.format(response.read().decode()))