mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-22 23:54:46 +00:00
Update dummy_request tests to use make_preview_request
This commit is contained in:
parent
e400d8d0c8
commit
0f3759ac6b
1 changed files with 24 additions and 13 deletions
|
|
@ -1444,13 +1444,14 @@ class TestIssue2024(TestCase):
|
|||
self.assertEqual(event_index.content_type, ContentType.objects.get_for_model(Page))
|
||||
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['localhost'])
|
||||
class TestDummyRequest(TestCase):
|
||||
class TestMakePreviewRequest(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
||||
def test_dummy_request_for_accessible_page(self):
|
||||
def test_make_preview_request_for_accessible_page(self):
|
||||
event_index = Page.objects.get(url_path='/home/events/')
|
||||
request = event_index.dummy_request()
|
||||
response = event_index.make_preview_request()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
request = response.context_data['request']
|
||||
|
||||
# request should have the correct path and hostname for this page
|
||||
self.assertEqual(request.path, '/events/')
|
||||
|
|
@ -1471,11 +1472,13 @@ class TestDummyRequest(TestCase):
|
|||
self.assertIn('wsgi.multiprocess', request.META)
|
||||
self.assertIn('wsgi.run_once', request.META)
|
||||
|
||||
def test_dummy_request_for_accessible_page_https(self):
|
||||
def test_make_preview_request_for_accessible_page_https(self):
|
||||
Site.objects.update(port=443)
|
||||
|
||||
event_index = Page.objects.get(url_path='/home/events/')
|
||||
request = event_index.dummy_request()
|
||||
response = event_index.make_preview_request()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
request = response.context_data['request']
|
||||
|
||||
# request should have the correct path and hostname for this page
|
||||
self.assertEqual(request.path, '/events/')
|
||||
|
|
@ -1496,11 +1499,13 @@ class TestDummyRequest(TestCase):
|
|||
self.assertIn('wsgi.multiprocess', request.META)
|
||||
self.assertIn('wsgi.run_once', request.META)
|
||||
|
||||
def test_dummy_request_for_accessible_page_non_standard_port(self):
|
||||
def test_make_preview_request_for_accessible_page_non_standard_port(self):
|
||||
Site.objects.update(port=8888)
|
||||
|
||||
event_index = Page.objects.get(url_path='/home/events/')
|
||||
request = event_index.dummy_request()
|
||||
response = event_index.make_preview_request()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
request = response.context_data['request']
|
||||
|
||||
# request should have the correct path and hostname for this page
|
||||
self.assertEqual(request.path, '/events/')
|
||||
|
|
@ -1521,7 +1526,7 @@ class TestDummyRequest(TestCase):
|
|||
self.assertIn('wsgi.multiprocess', request.META)
|
||||
self.assertIn('wsgi.run_once', request.META)
|
||||
|
||||
def test_dummy_request_for_accessible_page_with_original_request(self):
|
||||
def test_make_preview_request_for_accessible_page_with_original_request(self):
|
||||
event_index = Page.objects.get(url_path='/home/events/')
|
||||
original_headers = {
|
||||
'REMOTE_ADDR': '192.168.0.1',
|
||||
|
|
@ -1532,7 +1537,9 @@ class TestDummyRequest(TestCase):
|
|||
}
|
||||
factory = RequestFactory(**original_headers)
|
||||
original_request = factory.get('/home/events/')
|
||||
request = event_index.dummy_request(original_request)
|
||||
response = event_index.make_preview_request(original_request)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
request = response.context_data['request']
|
||||
|
||||
# request should have the all the special headers we set in original_request
|
||||
self.assertEqual(request.META['REMOTE_ADDR'], original_request.META['REMOTE_ADDR'])
|
||||
|
|
@ -1557,9 +1564,11 @@ class TestDummyRequest(TestCase):
|
|||
self.assertIn('wsgi.run_once', request.META)
|
||||
|
||||
@override_settings(ALLOWED_HOSTS=['production.example.com'])
|
||||
def test_dummy_request_for_inaccessible_page_should_use_valid_host(self):
|
||||
def test_make_preview_request_for_inaccessible_page_should_use_valid_host(self):
|
||||
root_page = Page.objects.get(url_path='/')
|
||||
request = root_page.dummy_request()
|
||||
response = root_page.make_preview_request()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
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
|
||||
|
|
@ -1569,7 +1578,9 @@ class TestDummyRequest(TestCase):
|
|||
@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()
|
||||
response = root_page.make_preview_request()
|
||||
self.assertEqual(response.status_code, 200)
|
||||
request = response.context_data['request']
|
||||
|
||||
# '*' is not a valid hostname, so ensure that we replace it with something sensible
|
||||
self.assertNotEqual(request.META['HTTP_HOST'], '*')
|
||||
|
|
|
|||
Loading…
Reference in a new issue