jenkins-bot has submitted this change and it was merged.
Change subject: Make cached requests depend on logged in user ......................................................................
Make cached requests depend on logged in user
Change-Id: I31821a431c4ac44409d4e08e1d76ddc3ab19686b --- M pywikibot/data/api.py M tests/dry_api_tests.py 2 files changed, 30 insertions(+), 1 deletion(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index a12764a..9293def 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -457,7 +457,7 @@ pass
def _uniquedescriptionstr(self): - return (repr(self.site) + repr(sorted(self.iteritems()))) + return (repr(self.site) + repr(self.site.user()) + repr(sorted(self.iteritems())))
def _create_file_name(self): self.http_params() # normalize self.iteritems() diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index 0e16a17..99d7757 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -44,6 +44,35 @@ self.assertNotEqual(self.req._cachefile_path(), self.diffreq._cachefile_path()) self.assertNotEqual(self.req._cachefile_path(), self.diffsite._cachefile_path())
+ def test_cachefile_path_different_users(self): + # Mock basesite object to test this. + class MockSite(pywikibot.site.BaseSite): + def __init__(self): + self._user = 'user' + + def user(self): + return self._user + + def encoding(self): + return 'utf-8' + + def __repr__(self): + return "MockSite()" + + def __getattr__(self, attr): + raise Exception("Attribute %r not defined" % attr) + + site = MockSite() + req = CachedRequest(expiry=1, site=site, action='query', meta='siteinfo') + userpath = req._cachefile_path() + + site._user = 'sysop' + + req = CachedRequest(expiry=1, site=site, action='query', meta='siteinfo') + sysoppath = req._cachefile_path() + + self.assertNotEqual(userpath, sysoppath) + def test_expired(self): self.assertFalse(self.req._expired(datetime.datetime.now())) self.assertTrue(self.req._expired(datetime.datetime.now() - datetime.timedelta(days=2)))
pywikibot-commits@lists.wikimedia.org