jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Tokens: Use the new tokens property and skip one failure ......................................................................
[FIX] Tokens: Use the new tokens property and skip one failure
Change-Id: Id81c47a996bcf61ba1ed26ca9e5613f0cdf090b7 --- M pywikibot/page.py M pywikibot/site.py M tests/site_tests.py 3 files changed, 10 insertions(+), 8 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index b63c049..1248b72 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2496,7 +2496,7 @@ params = { 'action': 'emailuser', 'target': self.username, - 'token': self.site.token(self, 'email'), + 'token': self.site.tokens['email'], 'subject': subject, 'text': text, } diff --git a/pywikibot/site.py b/pywikibot/site.py index 6aa6df4..a5c1754 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -1585,8 +1585,7 @@ # is supported by the site req = api.Request(site=self, action='echomarkread', - token=self.token(pywikibot.Page(self, u'Main Page'), - 'edit'), # Use a dummy page + token=self.tokens['edit'], **kwargs) data = req.submit() try: @@ -3798,7 +3797,7 @@ raise pywikibot.Error( u"Rollback of %s aborted; only one user in revision history." % page.title(asLink=True)) - token = self.token(page, "rollback") + token = self.tokens["rollback"] self.lock_page(page) req = api.Request(site=self, action="rollback", title=page.title(withSection=False), @@ -4064,8 +4063,7 @@ # filekey, file, url, statuskey is required # TODO: is there another way? try: - dummy = pywikibot.FilePage(self, title='dummy') - token = self.token(dummy, 'edit') + token = self.tokens['edit'] req = api.Request(site=self, action="upload", token=token, throttle=False) req.submit() diff --git a/tests/site_tests.py b/tests/site_tests.py index 1a3603f..778d5e6 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -237,8 +237,12 @@
def testInvalidToken(self): mysite = self.get_site() - mainpage = self.get_mainpage() - self.assertRaises(KeyError, mysite.token, mainpage, "invalidtype") + if LV(mysite.version()) >= LV('1.23wmf19'): + # Currently with the new token API all unknown types are treated + # as csrf tokens, so it won't throw an error here + # a patch is in development: https://gerrit.wikimedia.org/r/#/c/159394 + raise unittest.SkipTest('No invalid token with the new token API possible') + self.assertRaises(KeyError, lambda t: mysite.tokens[t], "invalidtype")
def testPreload(self): """Test that preloading works."""
pywikibot-commits@lists.wikimedia.org