jenkins-bot has submitted this change and it was merged.
Change subject: Allow APISite._request expiry = None
......................................................................
Allow APISite._request expiry = None
Revise APISite.watched_pages to use expiry=None
when force=True
Change-Id: Iaa199b2dd8b255346f5cddd4ba945b6c26d93418
---
M pywikibot/data/api.py
M pywikibot/site.py
M tests/site_tests.py
3 files changed, 39 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 8ce923b..15c1c4d 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1513,6 +1513,9 @@
@return: The normalized keyword arguments.
@rtype: dict
"""
+ if 'expiry' in kwargs and kwargs['expiry'] is None:
+ del kwargs['expiry']
+
args = set()
for super_cls in inspect.getmro(cls):
if not super_cls.__name__.endswith('Request'):
@@ -2194,6 +2197,7 @@
@param expiry: either a number of days or a datetime.timedelta object
"""
+ assert expiry is not None
super(CachedRequest, self).__init__(*args, **kwargs)
if not isinstance(expiry, datetime.timedelta):
expiry = datetime.timedelta(expiry)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 25dedf7..9dc34b3 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1885,13 +1885,16 @@
# This checks expiry in kwargs and not kwargs['parameters'] so it
won't
# create a CachedRequest when there is an expiry in an API parameter
# and kwargs here are actually in parameters mode.
- if 'expiry' in kwargs:
+ if 'expiry' in kwargs and kwargs['expiry'] is not None:
return api.CachedRequest
else:
return api.Request
def _request(self, **kwargs):
"""Create a request by forwarding all parameters
directly."""
+ if 'expiry' in kwargs and kwargs['expiry'] is None:
+ del kwargs['expiry']
+
return self._request_class(kwargs)(site=self, **kwargs)
def _simple_request(self, **kwargs):
@@ -6362,13 +6365,10 @@
self.login(sysop=sysop)
if not total:
total = pywikibot.config.special_page_limit
- if force:
- gen = api.PageGenerator(site=self, generator='watchlistraw',
- step=step, gwrlimit=total)
- else:
- gen = api.PageGenerator(
- site=self, generator='watchlistraw', step=step,
- expiry=pywikibot.config.API_config_expiry, gwrlimit=total)
+ expiry = None if force else pywikibot.config.API_config_expiry
+ gen = api.PageGenerator(site=self, generator='watchlistraw',
+ expiry=expiry,
+ step=step, gwrlimit=total)
return gen
# aliases for backwards compatibility
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b0b51f8..99ef485 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1239,6 +1239,33 @@
self.assertNotIn("patrolled", change)
+class TestUserWatchedPages(DefaultSiteTestCase):
+
+ """Test user watched pages."""
+
+ user = True
+
+ def test_watched_pages(self):
+ """Test the site.watched_pages() method."""
+ gen = self.site.watched_pages(total=5, force=False)
+ self.assertIsInstance(gen.request, api.CachedRequest)
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+ # repeat to use the cache
+ gen = self.site.watched_pages(total=5, force=False)
+ self.assertIsInstance(gen.request, api.CachedRequest)
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+
+ def test_watched_pages_uncached(self):
+ """Test the site.watched_pages() method
uncached."""
+ gen = self.site.watched_pages(total=5, force=True)
+ self.assertIsInstance(gen.request, api.Request)
+ self.assertFalse(issubclass(gen.request_class, api.CachedRequest))
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+
+
class SearchTestCase(DefaultSiteTestCase):
"""Test search method."""
--
To view, visit
https://gerrit.wikimedia.org/r/237009
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa199b2dd8b255346f5cddd4ba945b6c26d93418
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>