2009-07-29 04:40:14 +02:00
|
|
|
"""
|
|
|
|
Tests for django.core.servers.
|
|
|
|
"""
|
2015-12-30 13:23:50 +01:00
|
|
|
import errno
|
2009-07-29 04:40:14 +02:00
|
|
|
import os
|
2013-09-22 15:55:09 +02:00
|
|
|
import socket
|
2017-07-28 16:10:13 +02:00
|
|
|
import sys
|
2015-10-31 00:38:34 +01:00
|
|
|
from http.client import HTTPConnection
|
2017-01-07 12:11:46 +01:00
|
|
|
from urllib.error import HTTPError
|
2017-01-26 14:25:15 +01:00
|
|
|
from urllib.parse import urlencode
|
2017-01-07 12:11:46 +01:00
|
|
|
from urllib.request import urlopen
|
2009-07-29 04:40:14 +02:00
|
|
|
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.test import LiveServerTestCase, override_settings
|
2009-07-29 04:40:14 +02:00
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
from .models import Person
|
2009-07-29 04:40:14 +02:00
|
|
|
|
2017-07-28 16:10:13 +02:00
|
|
|
try:
|
|
|
|
from http.client import RemoteDisconnected
|
|
|
|
except ImportError: # Python 3.4
|
|
|
|
from http.client import BadStatusLine as RemoteDisconnected
|
|
|
|
|
2017-01-20 14:01:02 +01:00
|
|
|
TEST_ROOT = os.path.dirname(__file__)
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
TEST_SETTINGS = {
|
|
|
|
'MEDIA_URL': '/media/',
|
|
|
|
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),
|
|
|
|
'STATIC_URL': '/static/',
|
|
|
|
'STATIC_ROOT': os.path.join(TEST_ROOT, 'static'),
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-18 20:03:10 +02:00
|
|
|
@override_settings(ROOT_URLCONF='servers.urls', **TEST_SETTINGS)
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
class LiveServerBase(LiveServerTestCase):
|
2013-06-04 08:09:29 +02:00
|
|
|
|
|
|
|
available_apps = [
|
|
|
|
'servers',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
]
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
fixtures = ['testdata.json']
|
|
|
|
|
|
|
|
def urlopen(self, url):
|
2012-07-20 15:36:52 +02:00
|
|
|
return urlopen(self.live_server_url + url)
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LiveServerAddress(LiveServerBase):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2017-01-21 14:13:44 +01:00
|
|
|
super().setUpClass()
|
2015-06-10 22:57:51 +02:00
|
|
|
# put it in a list to prevent descriptor lookups in test
|
|
|
|
cls.live_server_url_test = [cls.live_server_url]
|
|
|
|
|
|
|
|
def test_live_server_url_is_class_property(self):
|
2016-12-29 16:27:49 +01:00
|
|
|
self.assertIsInstance(self.live_server_url_test[0], str)
|
2015-06-10 22:57:51 +02:00
|
|
|
self.assertEqual(self.live_server_url_test[0], self.live_server_url)
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
2013-11-02 22:34:05 +01:00
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
class LiveServerViews(LiveServerBase):
|
2015-10-31 00:38:34 +01:00
|
|
|
def test_protocol(self):
|
|
|
|
"""Launched server serves with HTTP 1.1."""
|
2017-07-28 16:10:13 +02:00
|
|
|
with self.urlopen('/example_view/') as f:
|
|
|
|
self.assertEqual(f.version, 11)
|
|
|
|
|
|
|
|
@override_settings(MIDDLEWARE=[])
|
|
|
|
def test_closes_connection_without_content_length(self):
|
|
|
|
"""
|
|
|
|
The server doesn't support keep-alive because Python's http.server
|
|
|
|
module that it uses hangs if a Content-Length header isn't set (for
|
|
|
|
example, if CommonMiddleware isn't enabled or if the response is a
|
|
|
|
StreamingHttpResponse) (#28440 / https://bugs.python.org/issue31076).
|
|
|
|
"""
|
|
|
|
conn = HTTPConnection(LiveServerViews.server_thread.host, LiveServerViews.server_thread.port, timeout=1)
|
|
|
|
try:
|
|
|
|
conn.request('GET', '/example_view/', headers={'Connection': 'keep-alive'})
|
|
|
|
response = conn.getresponse().read()
|
|
|
|
conn.request('GET', '/example_view/', headers={'Connection': 'close'})
|
|
|
|
with self.assertRaises(RemoteDisconnected, msg='Server did not close the connection'):
|
|
|
|
try:
|
|
|
|
conn.getresponse()
|
|
|
|
except ConnectionAbortedError:
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
self.skipTest('Ignore nondeterministic failure on Windows.')
|
|
|
|
finally:
|
|
|
|
conn.close()
|
|
|
|
self.assertEqual(response, b'example view')
|
2015-10-31 00:38:34 +01:00
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
def test_404(self):
|
2016-06-16 15:07:51 +02:00
|
|
|
with self.assertRaises(HTTPError) as err:
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
self.urlopen('/')
|
2017-06-05 15:56:51 +02:00
|
|
|
err.exception.close()
|
2016-06-16 15:07:51 +02:00
|
|
|
self.assertEqual(err.exception.code, 404, 'Expected 404 response')
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
|
|
|
def test_view(self):
|
2017-01-19 14:50:28 +01:00
|
|
|
with self.urlopen('/example_view/') as f:
|
2015-07-01 23:37:10 +02:00
|
|
|
self.assertEqual(f.read(), b'example view')
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
|
|
|
def test_static_files(self):
|
2017-01-19 14:50:28 +01:00
|
|
|
with self.urlopen('/static/example_static_file.txt') as f:
|
2015-07-01 23:37:10 +02:00
|
|
|
self.assertEqual(f.read().rstrip(b'\r\n'), b'example static file')
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
2013-06-01 19:24:46 +02:00
|
|
|
def test_no_collectstatic_emulation(self):
|
2013-08-10 21:32:07 +02:00
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
LiveServerTestCase reports a 404 status code when HTTP client
|
2014-03-02 15:25:53 +01:00
|
|
|
tries to access a static file that isn't explicitly put under
|
2013-06-01 19:24:46 +02:00
|
|
|
STATIC_ROOT.
|
2013-08-10 21:32:07 +02:00
|
|
|
"""
|
2016-06-16 15:07:51 +02:00
|
|
|
with self.assertRaises(HTTPError) as err:
|
2013-06-01 19:24:46 +02:00
|
|
|
self.urlopen('/static/another_app/another_app_static_file.txt')
|
2017-06-05 15:56:51 +02:00
|
|
|
err.exception.close()
|
2016-06-16 15:07:51 +02:00
|
|
|
self.assertEqual(err.exception.code, 404, 'Expected 404 response')
|
2013-08-10 21:32:07 +02:00
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
def test_media_files(self):
|
2017-01-19 14:50:28 +01:00
|
|
|
with self.urlopen('/media/example_media_file.txt') as f:
|
2015-07-01 23:37:10 +02:00
|
|
|
self.assertEqual(f.read().rstrip(b'\r\n'), b'example media file')
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
2012-10-20 12:34:50 +02:00
|
|
|
def test_environ(self):
|
2017-01-19 14:50:28 +01:00
|
|
|
with self.urlopen('/environ_view/?%s' % urlencode({'q': 'тест'})) as f:
|
2015-07-01 23:37:10 +02:00
|
|
|
self.assertIn(b"QUERY_STRING: 'q=%D1%82%D0%B5%D1%81%D1%82'", f.read())
|
2012-10-20 12:34:50 +02:00
|
|
|
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
|
|
|
class LiveServerDatabase(LiveServerBase):
|
|
|
|
|
|
|
|
def test_fixtures_loaded(self):
|
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
Fixtures are properly loaded and visible to the live server thread.
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
"""
|
2017-01-19 14:50:28 +01:00
|
|
|
with self.urlopen('/model_view/') as f:
|
2015-07-01 23:37:10 +02:00
|
|
|
self.assertEqual(f.read().splitlines(), [b'jane', b'robert'])
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
|
|
|
|
def test_database_writes(self):
|
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
Data written to the database by a view can be read.
|
Fixed #2879 -- Added support for the integration with Selenium and other in-browser testing frameworks. Also added the first Selenium tests for `contrib.admin`. Many thanks to everyone for their contributions and feedback: Mikeal Rogers, Dirk Datzert, mir, Simon G., Almad, Russell Keith-Magee, Denis Golomazov, devin, robertrv, andrewbadr, Idan Gazit, voidspace, Tom Christie, hjwp2, Adam Nelson, Jannis Leidel, Anssi Kääriäinen, Preston Holmes, Bruno Renié and Jacob Kaplan-Moss.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17241 bcc190cf-cafb-0310-a4f2-bffc1f526a37
2011-12-22 09:33:58 +01:00
|
|
|
"""
|
2017-06-05 15:56:51 +02:00
|
|
|
with self.urlopen('/create_model_instance/'):
|
|
|
|
pass
|
2012-04-05 16:06:06 +02:00
|
|
|
self.assertQuerysetEqual(
|
|
|
|
Person.objects.all().order_by('pk'),
|
|
|
|
['jane', 'robert', 'emily'],
|
|
|
|
lambda b: b.name
|
|
|
|
)
|
2015-12-30 13:23:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
class LiveServerPort(LiveServerBase):
|
|
|
|
|
|
|
|
def test_port_bind(self):
|
|
|
|
"""
|
|
|
|
Each LiveServerTestCase binds to a unique port or fails to start a
|
|
|
|
server thread when run concurrently (#26011).
|
|
|
|
"""
|
2017-01-19 15:48:01 +01:00
|
|
|
TestCase = type("TestCase", (LiveServerBase,), {})
|
2015-12-30 13:23:50 +01:00
|
|
|
try:
|
|
|
|
TestCase.setUpClass()
|
|
|
|
except socket.error as e:
|
2016-01-02 16:25:53 +01:00
|
|
|
if e.errno == errno.EADDRINUSE:
|
2015-12-30 13:23:50 +01:00
|
|
|
# We're out of ports, LiveServerTestCase correctly fails with
|
|
|
|
# a socket error.
|
|
|
|
return
|
|
|
|
# Unexpected error.
|
|
|
|
raise
|
|
|
|
try:
|
|
|
|
# We've acquired a port, ensure our server threads acquired
|
|
|
|
# different addresses.
|
|
|
|
self.assertNotEqual(
|
|
|
|
self.live_server_url, TestCase.live_server_url,
|
|
|
|
"Acquired duplicate server addresses for server threads: %s" % self.live_server_url
|
|
|
|
)
|
|
|
|
finally:
|
2016-08-19 18:47:41 +02:00
|
|
|
if hasattr(TestCase, 'server_thread'):
|
|
|
|
TestCase.server_thread.terminate()
|
2016-12-06 20:38:43 +01:00
|
|
|
|
2017-05-22 19:16:56 +02:00
|
|
|
def test_specified_port_bind(self):
|
|
|
|
"""LiveServerTestCase.port customizes the server's port."""
|
|
|
|
TestCase = type(str('TestCase'), (LiveServerBase,), {})
|
|
|
|
# Find an open port and tell TestCase to use it.
|
|
|
|
s = socket.socket()
|
|
|
|
s.bind(('', 0))
|
|
|
|
TestCase.port = s.getsockname()[1]
|
|
|
|
s.close()
|
|
|
|
TestCase.setUpClass()
|
|
|
|
try:
|
|
|
|
self.assertEqual(
|
|
|
|
TestCase.port, TestCase.server_thread.port,
|
|
|
|
'Did not use specified port for LiveServerTestCase thread: %s' % TestCase.port
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
if hasattr(TestCase, 'server_thread'):
|
|
|
|
TestCase.server_thread.terminate()
|
|
|
|
|
2016-12-06 20:38:43 +01:00
|
|
|
|
|
|
|
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())
|