jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/362797 )
Change subject: [bugfix] Don't fail when creating User class for autoblock id ......................................................................
[bugfix] Don't fail when creating User class for autoblock id
- Creating a user class with autoblock ID fails with InvalidTitle when a namespace identifier is given in front of the ID. It works without that preleading namespaces. - This patch solves that issue and is needed handling BlockEvents in a proper way. - A more general solution with a different Autoblock class proposed by b4f0bdd8 may come later. - tests added
Bug: T108515 Change-Id: I6de75bea5c3287cca04700b230fdec881189f32c --- M pywikibot/page.py M tests/user_tests.py 2 files changed, 39 insertions(+), 2 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 5195af2..faf7f53 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3131,9 +3131,11 @@
All parameters are the same as for Page() constructor. """ - if len(title) > 1 and title[0] == u'#': - self._isAutoblock = True + self._isAutoblock = True + if title.startswith('#'): title = title[1:] + elif ':#' in title: + title = title.replace(':#', ':') else: self._isAutoblock = False Page.__init__(self, source, title, ns=2) diff --git a/tests/user_tests.py b/tests/user_tests.py index ace810a..d604a97 100644 --- a/tests/user_tests.py +++ b/tests/user_tests.py @@ -9,6 +9,7 @@
import pywikibot
+from pywikibot.exceptions import AutoblockUser from pywikibot.tools import suppress_warnings from pywikibot import User
@@ -128,6 +129,40 @@ self.assertIn('bot', user.groups()) self.assertFalse(user.is_thankable)
+ def test_autoblocked_user(self): + """Test autoblocked user.""" + user = User(self.site, '#1242976') + self.assertEqual('#1242976', user.username) + self.assertEqual(user.name(), user.username) + self.assertEqual(user.title(withNamespace=False), user.username[1:]) + self.assertFalse(user.isRegistered()) + self.assertFalse(user.isAnonymous()) + self.assertIsNone(user.registration()) + self.assertFalse(user.isEmailable()) + self.assertIn('invalid', user.getprops()) + self.assertTrue(user._isAutoblock) + self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID', + user.getUserPage) + self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID', + user.getUserTalkPage) + + def test_autoblocked_user_with_namespace(self): + """Test autoblocked user.""" + user = User(self.site, 'User:#1242976') + self.assertEqual('#1242976', user.username) + self.assertEqual(user.name(), user.username) + self.assertEqual(user.title(withNamespace=False), user.username[1:]) + self.assertFalse(user.isRegistered()) + self.assertFalse(user.isAnonymous()) + self.assertIsNone(user.registration()) + self.assertFalse(user.isEmailable()) + self.assertIn('invalid', user.getprops()) + self.assertTrue(user._isAutoblock) + self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID', + user.getUserPage) + self.assertRaisesRegex(AutoblockUser, 'This is an autoblock ID', + user.getUserTalkPage) +
if __name__ == '__main__': # pragma: no cover try:
pywikibot-commits@lists.wikimedia.org