John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/233098
Change subject: Skip tests when token not available
......................................................................
Skip tests when token not available
Bug: T85353
Change-Id: I2a14888bb3cd410f5ba43f75a7fb195b2b29d61c
---
M pywikibot/site.py
M tests/site_tests.py
2 files changed, 66 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/98/233098/1
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c09f399..18c0758 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2986,7 +2986,8 @@
# TODO: try to catch exceptions?
if 'patrol' in valid_tokens:
if MediaWikiVersion('1.14') <= _version <
MediaWikiVersion('1.17'):
- user_tokens['patrol'] = user_tokens['edit']
+ if 'edit' in user_tokens:
+ user_tokens['patrol'] = user_tokens['edit']
else:
req = self._simple_request(action='query',
list='recentchanges',
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 898f094..ad258e8 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -27,6 +27,7 @@
from tests.aspects import (
unittest, TestCase, DeprecationTestCase,
+ TestCaseBase,
DefaultSiteTestCase,
DefaultDrySiteTestCase,
WikimediaDefaultSiteTestCase,
@@ -42,28 +43,57 @@
unicode = str
-class TestSiteUserDeprecatedFunctions(DefaultSiteTestCase,
DeprecationTestCase):
+class TokenTestBase(TestCaseBase):
- """Test cases for Site deprecated methods requiring a live wiki and
user."""
+ """Verify token exists before running tests."""
- cached = True
- user = True
-
- def test_token(self):
- """Test ability to get page tokens."""
+ def setUp(self):
+ """Skip test if user does not have token and clear site wallet."""
mysite = self.get_site()
- mainpage = self.get_mainpage()
- ttype = "edit"
try:
- token = mysite.tokens[ttype]
+ self.token = mysite.tokens[self.token_type]
except pywikibot.Error as error_msg:
self.assertRegex(
unicode(error_msg),
"Action '[a-z]+' is not allowed for user .* on .* wiki.")
- else:
- self.assertEqual(token, mysite.token(mainpage, ttype))
- self.assertOneDeprecationParts('pywikibot.site.APISite.token',
- "the 'tokens' property")
+ self.assertNotIn(self.token_type, self.site.tokens)
+ raise unittest.SkipTest(error_msg)
+
+ self._orig_wallet = self.site.tokens
+ self.site.tokens = pywikibot.site.TokenWallet(self.site)
+ super(TokenTestBase, self).setUp()
+
+ def tearDown(self):
+ """Restore site tokens."""
+ self.site.tokens = self._orig_wallet
+
+
+class TestDeprecatedEditTokenFunctions(TokenTestBase,
+ DefaultSiteTestCase,
+ DeprecationTestCase):
+
+ """Test cases for Site edit token deprecated methods."""
+
+ cached = True
+ user = True
+ token_type = 'edit'
+
+ def test_token(self):
+ """Test ability to get page tokens using site.tokens."""
+ token = self.token
+ mysite = self.get_site()
+ mainpage = self.get_mainpage()
+ ttype = "edit"
+ self.assertEqual(token, mysite.token(mainpage, ttype))
+ self.assertOneDeprecationParts('pywikibot.site.APISite.token',
+ "the 'tokens' property")
+
+ def test_getToken(self):
+ """Test ability to get page tokens using site.getToken."""
+ self.mysite = self.site
+ self.assertEqual(self.mysite.getToken(), self.token)
+ self.assertOneDeprecationParts('pywikibot.site.APISite.getToken',
+ "the 'tokens' property")
class TestSiteObjectDeprecatedFunctions(DefaultSiteTestCase,
DeprecationTestCase):
@@ -1571,6 +1601,14 @@
self.assertTrue(user["name"]
in ["Jimbo Wales", "Brion VIBBER", "Tim Starling"])
+
+class PatrolTestCase(TokenTestBase, DefaultSiteTestCase):
+
+ """Test patrol method."""
+
+ token_type = 'patrol'
+ user = True
+
def testPatrol(self):
"""Test the site.patrol() method."""
mysite = self.get_site()
@@ -1735,10 +1773,20 @@
def testInvalidToken(self):
self.assertRaises(pywikibot.Error, lambda t: self.mysite.tokens[t],
"invalidtype")
- def test_deprecated_token(self):
- self.assertEqual(self.mysite.getToken(), self.mysite.tokens['edit'])
+
+class TestDeprecatedPatrolToken(DefaultSiteTestCase, DeprecationTestCase):
+
+ """Test cases for Site patrol token deprecated methods."""
+
+ cached = True
+ user = True
+
+ def test_getPatrolToken(self):
+ """Test site.getPatrolToken."""
+ self.mysite = self.site
try:
self.assertEqual(self.mysite.getPatrolToken(),
self.mysite.tokens['patrol'])
+ self.assertOneDeprecation()
except pywikibot.Error as error_msg:
self.assertRegex(
unicode(error_msg),
--
To view, visit https://gerrit.wikimedia.org/r/233098
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a14888bb3cd410f5ba43f75a7fb195b2b29d61c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits