kopia lustrzana https://github.com/wagtail/wagtail
Fixed RuntimeError: dictionary changed size during iteration, raised while purging stale preview data from session
Added TestPreview.test_preview_on_edit_expiry to exercise PreviewOnEdit.remove_old_preview_data Added freezegun package in testing_extraspull/3292/merge
rodzic
d37838711b
commit
9f5ce0755a
1
setup.py
1
setup.py
|
@ -44,6 +44,7 @@ testing_extras = [
|
|||
'elasticsearch>=1.0.0,<3.0',
|
||||
'Jinja2>=2.8,<3.0',
|
||||
'boto3>=1.4,<1.5',
|
||||
'freezegun>=0.3.8',
|
||||
|
||||
# For coverage and PEP8 linting
|
||||
'coverage>=3.7.0',
|
||||
|
|
|
@ -6,6 +6,7 @@ import os
|
|||
|
||||
import django
|
||||
import mock
|
||||
from freezegun import freeze_time
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
|
@ -28,6 +29,7 @@ from wagtail.wagtailcore.models import GroupPagePermission, Page, PageRevision,
|
|||
from wagtail.wagtailcore.signals import page_published, page_unpublished
|
||||
from wagtail.wagtailsearch.index import SearchField
|
||||
from wagtail.wagtailusers.models import UserProfile
|
||||
from wagtail.wagtailadmin.views.pages import PreviewOnEdit
|
||||
|
||||
|
||||
def submittable_timestamp(timestamp):
|
||||
|
@ -4272,3 +4274,30 @@ class TestPreview(TestCase, WagtailTestUtils):
|
|||
self.assertContains(response, "Beach party")
|
||||
self.assertContains(response, "<li>Parties</li>")
|
||||
self.assertContains(response, "<li>Holidays</li>")
|
||||
|
||||
def test_preview_on_edit_expiry(self):
|
||||
initial_datetime = timezone.now()
|
||||
expiry_datetime = initial_datetime + datetime.timedelta(
|
||||
seconds=PreviewOnEdit.preview_expiration_timeout + 1)
|
||||
|
||||
with freeze_time(initial_datetime) as frozen_datetime:
|
||||
preview_url = reverse('wagtailadmin_pages:preview_on_edit',
|
||||
args=(self.event_page.id,))
|
||||
response = self.client.post(preview_url, self.post_data)
|
||||
|
||||
# Check the JSON response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(preview_url)
|
||||
|
||||
# Check the HTML response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
frozen_datetime.move_to(expiry_datetime)
|
||||
|
||||
preview_url = reverse('wagtailadmin_pages:preview_on_edit',
|
||||
args=(self.home_page.id,))
|
||||
response = self.client.post(preview_url, self.post_data)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
response = self.client.get(preview_url)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
|
@ -562,13 +562,12 @@ class PreviewOnEdit(View):
|
|||
|
||||
def remove_old_preview_data(self):
|
||||
expiration = time() - self.preview_expiration_timeout
|
||||
for k, v in self.request.session.items():
|
||||
if not k.startswith(self.session_key_prefix):
|
||||
continue
|
||||
post_data, timestamp = v
|
||||
if timestamp < expiration:
|
||||
# Removes the session key gracefully
|
||||
self.request.session.pop(k)
|
||||
expired_keys = [
|
||||
k for k, v in self.request.session.items()
|
||||
if k.startswith(self.session_key_prefix) and v[1] < expiration]
|
||||
# Removes the session key gracefully
|
||||
for k in expired_keys:
|
||||
self.request.session.pop(k)
|
||||
|
||||
@property
|
||||
def session_key(self):
|
||||
|
|
Ładowanie…
Reference in New Issue