Check that page.save_revision() was given a specific page object

pull/8576/head
Karl Hobley 2021-05-27 12:44:33 +01:00 zatwierdzone przez Karl Hobley
rodzic 7c9b6fd415
commit 25138aed92
5 zmienionych plików z 39 dodań i 13 usunięć

Wyświetl plik

@ -852,7 +852,7 @@ class TestAdminPageDetail(AdminAPITestCase, TestPageDetail):
def test_meta_status_live_draft(self):
# Save revision without republish
Page.objects.get(id=16).save_revision()
Page.objects.get(id=16).specific.save_revision()
response = self.get_response(16)
content = json.loads(response.content.decode("UTF-8"))
@ -867,7 +867,7 @@ class TestAdminPageDetail(AdminAPITestCase, TestPageDetail):
# Unpublish and save revision with go live date in the future
Page.objects.get(id=16).unpublish()
tomorrow = timezone.now() + datetime.timedelta(days=1)
Page.objects.get(id=16).save_revision(approved_go_live_at=tomorrow)
Page.objects.get(id=16).specific.save_revision(approved_go_live_at=tomorrow)
response = self.get_response(16)
content = json.loads(response.content.decode("UTF-8"))
@ -1474,7 +1474,7 @@ class TestPublishPageAction(AdminAPITestCase):
content,
{
"message": (
"save_revision() was called on an alias page. "
"page.save_revision() was called on an alias page. "
"Revisions are not required for alias pages as they are an exact copy of another page."
)
},
@ -1797,11 +1797,11 @@ class TestRevertToPageRevisionAction(AdminAPITestCase):
self.events_page = Page.objects.get(id=3)
# Create revision to revert back to
self.first_revision = self.events_page.save_revision()
self.first_revision = self.events_page.specific.save_revision()
# Change page title
self.events_page.title = "Evenements"
self.events_page.save_revision().publish()
self.events_page.specific.save_revision().publish()
def get_response(self, page_id, data):
return self.client.post(

Wyświetl plik

@ -13,7 +13,9 @@ class TestWorkflowHistoryDetail(TestCase, WagtailTestUtils):
self.user = self.create_test_user()
self.login(self.user)
self.christmas_event = Page.objects.get(url_path="/home/events/christmas/")
self.christmas_event = Page.objects.get(
url_path="/home/events/christmas/"
).specific
self.christmas_event.save_revision()
workflow = self.christmas_event.get_workflow()

Wyświetl plik

@ -1673,7 +1673,7 @@ class TestPageCacheInvalidation(TestCase):
signal_handlers.unregister_signal_handlers()
def test_republish_page_purges(self, purge):
Page.objects.get(id=2).save_revision().publish()
Page.objects.get(id=2).specific.save_revision().publish()
purge.assert_any_call("http://api.example.com/api/main/pages/2/")
@ -1688,6 +1688,6 @@ class TestPageCacheInvalidation(TestCase):
purge.assert_any_call("http://api.example.com/api/main/pages/16/")
def test_save_draft_doesnt_purge(self, purge):
Page.objects.get(id=2).save_revision()
Page.objects.get(id=2).specific.save_revision()
purge.assert_not_called()

Wyświetl plik

@ -891,10 +891,17 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
:param clean: Set this to False to skip cleaning page content before saving this revision
:return: the newly created revision
"""
# Raise error if this is not the specific version of the page
if not isinstance(self, self.specific_class):
raise RuntimeError(
"page.save_revision() must be called on the specific version of the page. "
"Call page.specific.save_revision() instead."
)
# Raise an error if this page is an alias.
if self.alias_of_id:
raise RuntimeError(
"save_revision() was called on an alias page. "
"page.save_revision() was called on an alias page. "
"Revisions are not required for alias pages as they are an exact copy of another page."
)

Wyświetl plik

@ -975,6 +975,21 @@ class TestPrevNextSiblings(TestCase):
)
class TestSaveRevision(TestCase):
fixtures = ["test.json"]
def test_raises_error_if_non_specific_page_used(self):
christmas_event = Page.objects.get(url_path="/home/events/christmas/")
with self.assertRaises(RuntimeError) as e:
christmas_event.save_revision()
self.assertEqual(
e.exception.args[0],
"page.save_revision() must be called on the specific version of the page. Call page.specific.save_revision() instead.",
)
class TestLiveRevision(TestCase):
fixtures = ["test.json"]
@ -1734,7 +1749,7 @@ class TestCopyPage(TestCase):
old_christmas_event = (
events_index.get_children().filter(slug="christmas").first()
)
old_christmas_event.save_revision()
old_christmas_event.specific.save_revision()
# Copy it
new_events_index = events_index.copy(
@ -2981,7 +2996,7 @@ class TestIssue735(TestCase):
fixtures = ["test.json"]
def test_child_urls_updated_on_parent_publish(self):
event_index = Page.objects.get(url_path="/home/events/")
event_index = Page.objects.get(url_path="/home/events/").specific
christmas_event = EventPage.objects.get(url_path="/home/events/christmas/")
# Change the event index slug and publish it
@ -3021,8 +3036,10 @@ class TestIssue1216(TestCase):
fixtures = ["test.json"]
def test_url_path_can_exceed_255_characters(self):
event_index = Page.objects.get(url_path="/home/events/")
christmas_event = EventPage.objects.get(url_path="/home/events/christmas/")
event_index = Page.objects.get(url_path="/home/events/").specific
christmas_event = EventPage.objects.get(
url_path="/home/events/christmas/"
).specific
# Change the christmas_event slug first - this way, we test that the process for
# updating child url paths also handles >255 character paths correctly