jenkins-bot has submitted this change and it was merged. Change subject: Fix bug in returned value of APISite.watch ......................................................................
Fix bug in returned value of APISite.watch Also add test for using Page.watch on the bot userpage, which is obtained via new method TestCase.get_userpage. Additional bug T77965 (badtoken) found. Change-Id: Ibfe513a3351fb0a8bde5dc35862abc878f30c386 --- M pywikibot/site.py M tests/aspects.py M tests/page_tests.py 3 files changed, 35 insertions(+), 4 deletions(-) Approvals: XZise: Looks good to me, approved jenkins-bot: Verified diff --git a/pywikibot/site.py b/pywikibot/site.py index 3c2c782..e0f4b49 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -4354,9 +4354,7 @@ if "watch" not in result: pywikibot.error(u"watchpage: Unexpected API response:\n%s" % result) return False - watched = result["watch"] - return ((unwatch and "unwatched" in watched) - or (not unwatch and "watched" in result)) + return ('unwatched' if unwatch else 'watched') in result["watch"] @must_be(group='user') def purgepages(self, pages, **kwargs): diff --git a/tests/aspects.py b/tests/aspects.py index 6466018..5e39c0c 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -475,6 +475,25 @@ if not site.logged_in(sysop): site.login(sysop) + def get_userpage(self, site=None): + """Create a User object for the user's userpage.""" + if not site: + site = self.get_site() + + if hasattr(self, '_userpage'): + # For multi-site test classes, or site is specified as a param, + # the cached userpage object may not be the desired site. + if self._userpage.site == site: + return self._userpage + + sysop = hasattr(self, 'sysop') and self.sysop + + userpage = pywikibot.User(site, site.username(sysop)) + + self._userpage = userpage + + return userpage + class MetaTestCaseClass(type): diff --git a/tests/page_tests.py b/tests/page_tests.py index 1bb1fde..2168ff2 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -14,6 +14,7 @@ import pywikibot.page from tests.aspects import unittest, TestCase, DefaultSiteTestCase +from tests.utils import allowed_failure if sys.version_info[0] > 2: basestring = (str, ) @@ -593,13 +594,26 @@ """Test page user actions.""" - cached = True user = True def test_purge(self): mainpage = self.get_mainpage() self.assertIsInstance(mainpage.purge(), bool) + @allowed_failure + def test_watch(self): + """Test Page.watch, with and without unwatch enabled.""" + # Note: this test uses the userpage, so that it is unwatched and + # therefore is not listed by script_tests test_watchlist_simulate. + # FIXME: T77965: fails on ar.wp and test.wd, but not en.wp and fr.wikt + userpage = self.get_userpage() + rv = userpage.watch() + self.assertIsInstance(rv, bool) + self.assertTrue(rv) + rv = userpage.watch(unwatch=True) + self.assertIsInstance(rv, bool) + self.assertTrue(rv) + if __name__ == '__main__': try: -- To view, visit https://gerrit.wikimedia.org/r/178453 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ibfe513a3351fb0a8bde5dc35862abc878f30c386 Gerrit-PatchSet: 3 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ladsgroup <ladsgr...@gmail.com> Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl> Gerrit-Reviewer: XZise <commodorefabia...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ Pywikibot-commits mailing list Pywikibot-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits