jenkins-bot has submitted this change and it was merged.
Change subject: New Page.touch() method for touch edit of page without any changes ......................................................................
New Page.touch() method for touch edit of page without any changes
Also test that Page.touch() does not do a real edit.
Change-Id: I8f9cd8d9848e333633615c09c9a1b1015e4e16c3 --- M pywikibot/page.py M tests/edit_failure_tests.py 2 files changed, 29 insertions(+), 0 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 73f05ed..587e991 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1178,6 +1178,26 @@ """ return self.site.purgepages([self], **kwargs)
+ def touch(self, callback=None, **kwargs): + """Make a touch edit for this page. + + See save() method docs for all parameters. + The following parameters will be overridden by this method: + summary, watch, minor, botflag, force, async + + minor and botflag parameters are set to False which prevents hiding + the edit when it becomes a real edit due to a bug. + """ + if self.exists(): + # ensure always get the page text and not to change it. + del self.text + self.save(summary='Pywikibot touch edit', watch='nochange', + minor=False, botflag=False, force=True, async=False, + callback=callback, apply_cosmetic_changes=False, + **kwargs) + else: + raise pywikibot.NoPage(self) + def linkedPages(self, namespaces=None, step=None, total=None, content=False): """Iterate Pages that this Page links to. diff --git a/tests/edit_failure_tests.py b/tests/edit_failure_tests.py index 01b163d..c54aca4 100644 --- a/tests/edit_failure_tests.py +++ b/tests/edit_failure_tests.py @@ -55,6 +55,15 @@ page = pywikibot.Page(self.site, 'User:John Vandenberg/nobots') self.assertRaisesRegex(OtherPageSaveError, 'nobots', page.save)
+ def test_touch(self): + """Test that Page.touch() does not do a real edit.""" + page = pywikibot.Page(self.site, 'User:Xqt/sandbox') + old_text = page.text + page.text += '\n*Add a new line to page' + page.touch() + new_text = page.get(force=True) + self.assertEqual(old_text, new_text) +
class TestActionFailure(TestCase):
pywikibot-commits@lists.wikimedia.org