[1.11.x] Fixed #27873 -- Fixed crash in setup_test_environment() if ALLOWED_HOSTS is a tuple.
Regression in17e661641d
Backport of339d526d55
from master
This commit is contained in:
parent
53f5dc10cd
commit
5a85f2ca5f
|
@ -131,7 +131,7 @@ def setup_test_environment(debug=None):
|
||||||
|
|
||||||
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
|
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
|
||||||
# Add the default host of the test client.
|
# Add the default host of the test client.
|
||||||
settings.ALLOWED_HOSTS = settings.ALLOWED_HOSTS + ['testserver']
|
settings.ALLOWED_HOSTS = list(settings.ALLOWED_HOSTS) + ['testserver']
|
||||||
|
|
||||||
saved_data.debug = settings.DEBUG
|
saved_data.debug = settings.DEBUG
|
||||||
settings.DEBUG = debug
|
settings.DEBUG = debug
|
||||||
|
|
|
@ -5,6 +5,7 @@ import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.contrib.staticfiles.finders import get_finder, get_finders
|
from django.contrib.staticfiles.finders import get_finder, get_finders
|
||||||
from django.contrib.staticfiles.storage import staticfiles_storage
|
from django.contrib.staticfiles.storage import staticfiles_storage
|
||||||
|
@ -14,7 +15,7 @@ from django.forms import EmailField, IntegerField
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.test import (
|
from django.test import (
|
||||||
SimpleTestCase, TestCase, ignore_warnings, skipIfDBFeature,
|
SimpleTestCase, TestCase, ignore_warnings, mock, skipIfDBFeature,
|
||||||
skipUnlessDBFeature,
|
skipUnlessDBFeature,
|
||||||
)
|
)
|
||||||
from django.test.html import HTMLParseError, parse_html
|
from django.test.html import HTMLParseError, parse_html
|
||||||
|
@ -885,6 +886,15 @@ class SetupTestEnvironmentTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(RuntimeError, "setup_test_environment() was already called"):
|
with self.assertRaisesMessage(RuntimeError, "setup_test_environment() was already called"):
|
||||||
setup_test_environment()
|
setup_test_environment()
|
||||||
|
|
||||||
|
def test_allowed_hosts(self):
|
||||||
|
for type_ in (list, tuple):
|
||||||
|
allowed_hosts = type_('*')
|
||||||
|
with mock.patch('django.test.utils._TestState') as x:
|
||||||
|
del x.saved_data
|
||||||
|
with self.settings(ALLOWED_HOSTS=allowed_hosts):
|
||||||
|
setup_test_environment()
|
||||||
|
self.assertEqual(settings.ALLOWED_HOSTS, ['*', 'testserver'])
|
||||||
|
|
||||||
|
|
||||||
class OverrideSettingsTests(SimpleTestCase):
|
class OverrideSettingsTests(SimpleTestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue