1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +00:00

Fixed #27873 -- Fixed crash in setup_test_environment() if ALLOWED_HOSTS is a tuple.

Regression in 17e661641ddaf8266e7430d83cfb2039abc55df7
This commit is contained in:
Chris Lamb 2017-02-25 02:58:56 +08:00 committed by Tim Graham
parent dc811cf503
commit 339d526d55
2 changed files with 13 additions and 1 deletions

View File

@ -124,7 +124,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

View File

@ -2,7 +2,9 @@ import os
import sys import sys
import unittest import unittest
from io import StringIO from io import StringIO
from unittest import mock
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
@ -866,6 +868,16 @@ 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):
with self.subTest(type_=type_):
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):