Skip to content

Commit

Permalink
Fixed #27873 -- Fixed crash in setup_test_environment() if ALLOWED_HO…
Browse files Browse the repository at this point in the history
…STS is a tuple.

Regression in 17e6616
  • Loading branch information
lamby authored and timgraham committed Feb 24, 2017
1 parent dc811cf commit 339d526
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/test/utils.py
Expand Up @@ -124,7 +124,7 @@ def setup_test_environment(debug=None):

saved_data.allowed_hosts = settings.ALLOWED_HOSTS
# 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
settings.DEBUG = debug
Expand Down
12 changes: 12 additions & 0 deletions tests/test_utils/tests.py
Expand Up @@ -2,7 +2,9 @@
import sys
import unittest
from io import StringIO
from unittest import mock

from django.conf import settings
from django.conf.urls import url
from django.contrib.staticfiles.finders import get_finder, get_finders
from django.contrib.staticfiles.storage import staticfiles_storage
Expand Down Expand Up @@ -866,6 +868,16 @@ def test_setup_test_environment_calling_more_than_once(self):
with self.assertRaisesMessage(RuntimeError, "setup_test_environment() was already called"):
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):

Expand Down

0 comments on commit 339d526

Please sign in to comment.