kopia lustrzana https://github.com/wagtail/wagtail
clean tests and add ALLOWED_HOSTS globally
rodzic
b7e6b8e655
commit
0d2442fc1f
|
@ -3,34 +3,25 @@ Tests for the search box in the admin side menu, and the custom search hooks.
|
|||
"""
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.template import Context, Template
|
||||
from django.test import RequestFactory, TestCase, override_settings
|
||||
from django.test import RequestFactory, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from wagtail.admin.utils import user_has_any_page_permission
|
||||
from wagtail.core.models import Site
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
class BaseSearchAreaTestCase(WagtailTestUtils, TestCase):
|
||||
rf = RequestFactory()
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def search_other(self, current_url='/admin/', data=None):
|
||||
request = self.rf.get(current_url, data=data)
|
||||
request.user = self.user
|
||||
site = Site.objects.get()
|
||||
request.META['HTTP_HOST'] = site.hostname
|
||||
request.META['SERVER_PORT'] = site.port
|
||||
template = Template("{% load wagtailadmin_tags %}{% search_other %}")
|
||||
return template.render(Context({'request': request}))
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def menu_search(self, current_url='/admin/', data=None):
|
||||
request = self.rf.get(current_url, data=data)
|
||||
request.user = self.user
|
||||
site = Site.objects.get()
|
||||
request.META['HTTP_HOST'] = site.hostname
|
||||
request.META['SERVER_PORT'] = site.port
|
||||
template = Template("{% load wagtailadmin_tags %}{% menu_search %}")
|
||||
return template.render(Context({'request': request}))
|
||||
|
||||
|
|
|
@ -2,12 +2,11 @@ from django.contrib.auth import get_user_model
|
|||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.http import HttpRequest
|
||||
from django.template import engines
|
||||
from django.test import TestCase, override_settings
|
||||
from django.test import TestCase
|
||||
|
||||
from wagtail.core.models import PAGE_TEMPLATE_VAR, Page, Site
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestCoreJinja(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
|
@ -572,7 +572,6 @@ class TestExplorablePageVisibility(TestCase, WagtailTestUtils):
|
|||
self.assertNotContains(response, """<li class="home"><a href="/admin/pages/4/" class="icon icon-home text-replace">Home</a></li>""")
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestPageCreation(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
# Find root page
|
||||
|
@ -1885,7 +1884,6 @@ class TestPageEdit(TestCase, WagtailTestUtils):
|
|||
# Check that a form error was raised
|
||||
self.assertFormError(response, 'form', 'slug', "This slug is already in use")
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def test_preview_on_edit(self):
|
||||
post_data = {
|
||||
'title': "I've been edited!",
|
||||
|
@ -4151,7 +4149,6 @@ class TestChildRelationsOnSuperclass(TestCase, WagtailTestUtils):
|
|||
self.assertContains(response, "alwaysDirty: true")
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestRevisions(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test.json']
|
||||
|
||||
|
@ -4549,7 +4546,6 @@ class TestRevisionsUnscheduleForUnpublishedPages(TestCase, WagtailTestUtils):
|
|||
self.assertIsNone(self.unpublished_event.revisions.get(id=self.unpublished_revision.id).approved_go_live_at)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestIssue2599(TestCase, WagtailTestUtils):
|
||||
"""
|
||||
When previewing a page on creation, we need to assign it a path value consistent with its
|
||||
|
@ -5209,7 +5205,6 @@ class TestValidationErrorMessages(TestCase, WagtailTestUtils):
|
|||
self.assertContains(response, "<li>Title: This field is required.</li>", count=1)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestDraftAccess(TestCase, WagtailTestUtils):
|
||||
"""Tests for the draft view access restrictions."""
|
||||
|
||||
|
@ -5270,7 +5265,6 @@ class TestDraftAccess(TestCase, WagtailTestUtils):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestPreview(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test.json']
|
||||
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.template import Context, Template
|
||||
from django.test import TestCase, override_settings
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.urls import reverse
|
||||
|
||||
from wagtail.core.models import PAGE_TEMPLATE_VAR, Page, Site
|
||||
from wagtail.core.models import PAGE_TEMPLATE_VAR, Page
|
||||
from wagtail.tests.testapp.models import BusinessChild, BusinessIndex
|
||||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestUserbarTag(TestCase):
|
||||
def setUp(self):
|
||||
|
||||
|
@ -24,9 +23,6 @@ class TestUserbarTag(TestCase):
|
|||
def dummy_request(self, user=None):
|
||||
request = RequestFactory().get('/')
|
||||
request.user = user or AnonymousUser()
|
||||
site = Site.objects.first()
|
||||
request.META['HTTP_HOST'] = site.hostname
|
||||
request.META['SERVER_PORT'] = site.port
|
||||
return request
|
||||
|
||||
|
||||
|
@ -69,7 +65,6 @@ class TestUserbarTag(TestCase):
|
|||
self.assertEqual(content, '')
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestUserbarFrontend(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
@ -91,7 +86,6 @@ class TestUserbarFrontend(TestCase, WagtailTestUtils):
|
|||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestUserbarAddLink(TestCase, WagtailTestUtils):
|
||||
fixtures = ['test.json']
|
||||
|
||||
|
@ -125,7 +119,6 @@ class TestUserbarAddLink(TestCase, WagtailTestUtils):
|
|||
self.assertNotContains(response, expected_link)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TestUserbarModeration(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
self.login()
|
||||
|
|
|
@ -151,7 +151,6 @@ class TestRoutablePage(TestCase):
|
|||
|
||||
class TestRoutablePageTemplateTag(TestCase):
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def setUp(self):
|
||||
self.home_page = Page.objects.get(id=2)
|
||||
self.routable_page = self.home_page.add_child(instance=RoutablePageTest(
|
||||
|
@ -256,7 +255,7 @@ class TestRoutablePageTemplateTagForSecondSiteAtSameRoot(TestCase):
|
|||
self.assertEqual(url, expected)
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
@override_settings(ALLOWED_HOSTS=['events.local'])
|
||||
class TestRoutablePageTemplateTagForSecondSiteAtDifferentRoot(TestCase):
|
||||
"""
|
||||
When multiple sites exist, relative URLs between such sites should include the domain portion
|
||||
|
|
|
@ -7,7 +7,6 @@ from wagtail.tests.testapp.models import TestSetting
|
|||
from wagtail.tests.utils import WagtailTestUtils
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
class TemplateTestCase(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
root = Page.objects.first()
|
||||
|
@ -51,6 +50,7 @@ class TestContextProcessor(TemplateTestCase):
|
|||
self.render(request, '{{ settings.tests.TestSetting.title }}'),
|
||||
self.test_setting.title)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'other'])
|
||||
def test_multisite(self):
|
||||
""" Check that the correct setting for the current site is returned """
|
||||
request = self.get_request(site=self.default_site)
|
||||
|
@ -104,6 +104,7 @@ class TestTemplateTag(TemplateTestCase):
|
|||
context = Context()
|
||||
self.assertEqual(template.render(context), '')
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'other'])
|
||||
def test_get_settings_request_context(self):
|
||||
""" Check that the {% get_settings %} tag works """
|
||||
request = self.get_request(site=self.other_site)
|
||||
|
@ -191,6 +192,7 @@ class TestSettingsJinja(TemplateTestCase):
|
|||
self.render('{{ settings("tests.TestSetting").title }}'),
|
||||
self.test_setting.title)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'other'])
|
||||
def test_multisite(self):
|
||||
""" Check that the correct setting for the current site is returned """
|
||||
context = {'site': self.default_site}
|
||||
|
|
|
@ -254,7 +254,7 @@ class TestRouting(TestCase):
|
|||
self.assertEqual(root.relative_url(default_site), None)
|
||||
self.assertEqual(root.get_site(), None)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'events.example.com', 'second-events.example.com'])
|
||||
def test_urls_with_multiple_sites(self):
|
||||
events_page = Page.objects.get(url_path='/home/events/')
|
||||
events_site = Site.objects.create(hostname='events.example.com', root_page=events_page)
|
||||
|
@ -341,7 +341,6 @@ class TestRouting(TestCase):
|
|||
(found_page, args, kwargs) = homepage.route(request, ['events', 'christmas'])
|
||||
self.assertEqual(found_page, christmas_page)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def test_request_serving(self):
|
||||
christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
|
||||
|
||||
|
@ -376,7 +375,7 @@ class TestRouting(TestCase):
|
|||
# Override CACHES so we don't generate any cache-related SQL queries (tests use DatabaseCache
|
||||
# otherwise) and so cache.get will always return None.
|
||||
@override_settings(CACHES={'default': {'BACKEND': 'django.core.cache.backends.dummy.DummyCache'}})
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'dummy'])
|
||||
def test_request_scope_site_root_paths_cache(self):
|
||||
homepage = Page.objects.get(url_path='/home/')
|
||||
christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
|
||||
|
@ -392,6 +391,7 @@ class TestRouting(TestCase):
|
|||
self.assertEqual(christmas_page.get_url(), '/events/christmas/')
|
||||
|
||||
# with a request, the first call to get_url should issue 1 SQL query
|
||||
|
||||
request = HttpRequest()
|
||||
request.META['HTTP_HOST'] = "dummy"
|
||||
request.META['SERVER_PORT'] = "8888"
|
||||
|
@ -1517,7 +1517,6 @@ class TestDummyRequest(TestCase):
|
|||
# validation won't reject
|
||||
self.assertEqual(request.META['HTTP_HOST'], 'production.example.com')
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
def test_dummy_request_for_inaccessible_page_with_wildcard_allowed_hosts(self):
|
||||
root_page = Page.objects.get(url_path='/')
|
||||
request = root_page.dummy_request()
|
||||
|
|
|
@ -63,7 +63,7 @@ class TestPageUrlTags(TestCase):
|
|||
result = slugurl(context=template.Context({'request': HttpRequest()}), slug='bad-slug-doesnt-exist')
|
||||
self.assertEqual(result, None)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'site2.example.com'])
|
||||
def test_slugurl_tag_returns_url_for_current_site(self):
|
||||
home_page = Page.objects.get(url_path='/home/')
|
||||
new_home_page = home_page.copy(update_attrs={'title': "New home page", 'slug': 'new-home'})
|
||||
|
@ -78,7 +78,7 @@ class TestPageUrlTags(TestCase):
|
|||
url = slugurl(context=template.Context({'request': request}), slug='christmas')
|
||||
self.assertEqual(url, '/christmas/')
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['*'])
|
||||
@override_settings(ALLOWED_HOSTS=['localhost', 'site2.example.com'])
|
||||
def test_slugurl_tag_returns_url_for_other_site(self):
|
||||
home_page = Page.objects.get(url_path='/home/')
|
||||
new_home_page = home_page.copy(update_attrs={'title': "New home page", 'slug': 'new-home'})
|
||||
|
|
|
@ -8,6 +8,8 @@ MEDIA_URL = '/media/'
|
|||
|
||||
TIME_ZONE = 'Asia/Tokyo'
|
||||
|
||||
ALLOWED_HOSTS = ['localhost', ]
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
|
||||
|
|
Ładowanie…
Reference in New Issue