Unicodesnowman has uploaded a new change for review.
https://gerrit.wikimedia.org/r/181359
Change subject: Implement undelete tests for APISite and deletionbot
......................................................................
Implement undelete tests for APISite and deletionbot
Implements sysop write tests for Site.undelete and the deletionbot
script. (I couldn't find a way to actually test something in simulate
mode.)
Fixe issues with Page.undelete and Site.undelete_page where an error
is raised if None is passed for revisions/timestamps.
Bug: T74733
Change-Id: Ie474bc289951492f7fabc5ea53f63732df7acfdf
---
M pywikibot/page.py
M pywikibot/site.py
M tests/__init__.py
A tests/deletionbot_tests.py
M tests/site_tests.py
5 files changed, 88 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/59/181359/1
diff --git a/pywikibot/page.py b/pywikibot/page.py
index cc3012d..2fcb3a5 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -1607,8 +1607,11 @@
@type reason: basestring
"""
- undelete_revs = [ts for ts, rev in self._deletedRevs.items()
- if 'marked' in rev and rev['marked']]
+ if hasattr(self, "_deletedRevs"):
+ undelete_revs = [ts for ts, rev in self._deletedRevs.items()
+ if 'marked' in rev and rev['marked']]
+ else:
+ undelete_revs = []
if reason is None:
pywikibot.warning('Not passing a reason for undelete() is
deprecated.')
pywikibot.output(u'Undeleting %s.' % (self.title(asLink=True)))
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 6fa32a7..362f7a3 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -4198,9 +4198,14 @@
"""
token = self.tokens['undelete']
self.lock_page(page)
- req = api.Request(site=self, action="undelete", token=token,
- title=page.title(withSection=False),
- timestamps=revisions, reason=reason)
+
+ if revisions is None:
+ req = api.Request(site=self, action='undelete', token=token,
+ title=page.title(withSection=False),
reason=reason)
+ else:
+ req = api.Request(site=self, action='undelete', token=token,
+ title=page.title(withSection=False),
+ timestamps=revisions, reason=reason)
try:
req.submit()
except api.APIError as err:
diff --git a/tests/__init__.py b/tests/__init__.py
index bd6e9c5..2634a8b 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -92,6 +92,7 @@
'script',
'archivebot',
'data_ingestion',
+ 'deletionbot',
'cache',
]
diff --git a/tests/deletionbot_tests.py b/tests/deletionbot_tests.py
new file mode 100644
index 0000000..607c65d
--- /dev/null
+++ b/tests/deletionbot_tests.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+"""Tests for scripts/delete.py."""
+#
+# (C) Pywikibot team, 2014
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+
+import pywikibot
+import pywikibot.page
+from scripts import delete
+from tests.aspects import unittest, TestCase
+
+
+class TestDeletionBot(TestCase):
+
+ """Test deletionbot script."""
+
+ sites = {
+ 'test': {
+ 'family': 'test',
+ 'code': 'test',
+ },
+ }
+
+ sysop = True
+ write = True
+
+ def test_delete(self, code=None):
+ """Test deletionbot on the test wiki."""
+ site = self.get_site()
+ cat = pywikibot.Category(site, 'Pywikibot Delete Test')
+ delete.main('-cat:Pywikibot_Delete_Test', '-always')
+ self.assertEqual(len(list(cat.members())), 0)
+ delete.main('-page:User:Unicodesnowman/DeleteTest1', '-always',
+ '-undelete', '-summary=pywikibot unit tests')
+ delete.main('-page:User:Unicodesnowman/DeleteTest2', '-always',
+ '-undelete', '-summary=pywikibot unit tests')
+ self.assertEqual(len(list(cat.members())), 2)
+
+
+if __name__ == '__main__':
+ try:
+ unittest.main()
+ except SystemExit:
+ pass
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 406e969..df5b2b1 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1150,9 +1150,9 @@
total=5)
-class SiteProtectTestCase(DefaultSiteTestCase):
+class TestSiteSysopWrite(TestCase):
- """Test site protect / unprotect using a sysop account."""
+ """Test site sysop methods that require writing."""
family = 'test'
code = 'test'
@@ -1230,6 +1230,31 @@
protections={'edit': 'anInvalidValue'},
page=p1, reason='Pywikibot unit test')
+ def test_delete(self):
+ """Test the site.deletepage() and site.undelete_page() methods."""
+ site = self.get_site()
+ p = pywikibot.Page(site, u'User:Unicodesnowman/DeleteTestSite')
+ # Verify state
+ if not p.exists():
+ site.undelete_page(p, 'pywikibot unit tests')
+
+ site.deletepage(p, reason='pywikibot unit tests')
+ self.assertRaises(pywikibot.NoPage, p.get, force=True)
+
+ site.undelete_page(p, 'pywikibot unit tests',
+ revisions=[u'2014-12-21T06:07:47Z',
+ u'2014-12-21T06:07:31Z'])
+
+ revs = list(p.getVersionHistory())
+ self.assertEqual(len(revs), 2)
+ self.assertEqual(revs[0].revid, 219995)
+ self.assertEqual(revs[1].revid, 219994)
+
+ site.deletepage(p, reason='pywikibot unit tests')
+ site.undelete_page(p, 'pywikibot unit tests')
+ revs = list(p.getVersionHistory())
+ self.assertTrue(len(revs) > 2)
+
class SiteUserTestCase2(DefaultSiteTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/181359
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie474bc289951492f7fabc5ea53f63732df7acfdf
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Unicodesnowman <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits