Remove dummy_request from Page

This commit is contained in:
Matt Westcott 2020-01-23 12:09:35 +00:00 committed by Matt Westcott
parent 8ad9f8ecf7
commit be8cd8f8a9
2 changed files with 2 additions and 27 deletions

View file

@ -3,7 +3,6 @@ import logging
from collections import defaultdict
from io import StringIO
from urllib.parse import urlparse
from warnings import warn
from django.conf import settings
from django.contrib.auth.models import Group, Permission
@ -33,7 +32,6 @@ from wagtail.core.sites import get_site_for_hostname
from wagtail.core.url_routing import RouteResult
from wagtail.core.utils import WAGTAIL_APPEND_SLASH, camelcase_to_underscore, resolve_model_string
from wagtail.search import index
from wagtail.utils.deprecation import RemovedInWagtail29Warning
logger = logging.getLogger('wagtail.core')
@ -1336,29 +1334,6 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
"""
return self.full_url
def dummy_request(self, original_request=None, **meta):
warn(
"Page.dummy_request is deprecated. Use Page.make_preview_request instead",
category=RemovedInWagtail29Warning
)
dummy_values = self._get_dummy_headers(original_request)
# Add additional custom metadata sent by the caller.
dummy_values.update(**meta)
request = WSGIRequest(dummy_values)
# Add a flag to let middleware know that this is a dummy request.
request.is_dummy = True
# Apply middleware to the request
handler = BaseHandler()
handler.load_middleware()
handler._middleware_chain(request)
return request
DEFAULT_PREVIEW_MODES = [('', _('Default'))]
@property

View file

@ -1571,12 +1571,12 @@ class TestMakePreviewRequest(TestCase):
request = response.context_data['request']
# in the absence of an actual Site record where we can access this page,
# dummy_request should still provide a hostname that Django's host header
# make_preview_request should still provide a hostname that Django's host header
# 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):
def test_make_preview_request_for_inaccessible_page_with_wildcard_allowed_hosts(self):
root_page = Page.objects.get(url_path='/')
response = root_page.make_preview_request()
self.assertEqual(response.status_code, 200)