jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/231754 )
Change subject: [IMPR] NewUsersEntry class retrieves User object for page() method ......................................................................
[IMPR] NewUsersEntry class retrieves User object for page() method
- Derive NewUsersEntry from UserTargetLogEntry which returns a User class for page() method - Do not inherit page method in UserTargetLogEntry. Otherwise instantiating the User object may fail in NewUsersEntry (and later in BlockEntry with next patch) - It is no longer necessary to change the class in welcome.py - Update logentry_tests to check User and FilePage class - Update TestLogeventsFactoryGenerator to check User class
Bug: T168784 Change-Id: Ib5c0074248102b39f4375e849bec17812afa87c0 --- M pywikibot/logentries.py M scripts/welcome.py M tests/logentry_tests.py M tests/pagegenerators_tests.py 4 files changed, 24 insertions(+), 13 deletions(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index fc278f5..c12ff73 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Objects representing Mediawiki log entries.""" # -# (C) Pywikibot team, 2007-2017 +# (C) Pywikibot team, 2007-2018 # # Distributed under the terms of the MIT license. # @@ -115,6 +115,7 @@ @note: title may be missing in data dict e.g. by oversight action to hide the title. In that case a KeyError exception will raise
+ @return: page on action was performed @rtype: pywikibot.Page @raise: KeyError: title was missing from log entry """ @@ -165,7 +166,7 @@ @rtype: pywikibot.User """ if not hasattr(self, '_page'): - self._page = pywikibot.User(super(UserTargetLogEntry, self).page()) + self._page = pywikibot.User(self.site, self.data['title']) return self._page
@@ -394,7 +395,7 @@ return 'auto' in self._params and self._params['auto'] != 0
-class NewUsersEntry(LogEntry): +class NewUsersEntry(UserTargetLogEntry):
"""New user log entry."""
diff --git a/scripts/welcome.py b/scripts/welcome.py index 3156ede..1490051 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -157,7 +157,7 @@ # (C) Filnik, 2007-2011 # (C) Daniel Herding, 2007 # (C) Alex Shih-Han Lin, 2009-2010 -# (C) xqt, 2009-2017 +# (C) xqt, 2009-2018 # (C) Pywikibot team, 2008-2018 # # Distributed under the terms of the MIT license. @@ -676,7 +676,7 @@ start=start): if ue.action() == 'create' or ( ue.action() == 'autocreate' and globalvar.welcomeAuto): - yield pywikibot.User(ue.page()) + yield ue.page()
def defineSign(self, force=False): """Setup signature.""" diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index faf0921..50f900a 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Test logentries module.""" # -# (C) Pywikibot team, 2015-2016 +# (C) Pywikibot team, 2015-2018 # # Distributed under the terms of the MIT license. # @@ -11,7 +11,7 @@
import pywikibot
-from pywikibot.logentries import LogEntryFactory +from pywikibot.logentries import LogEntryFactory, UserTargetLogEntry from pywikibot.tools import ( MediaWikiVersion, UnicodeType as unicode, @@ -86,6 +86,10 @@ if 'title' in logentry.data: # title may be missing if logtype == 'block' and logentry.isAutoblockRemoval: self.assertIsInstance(logentry.page(), int) + elif isinstance(logentry, UserTargetLogEntry): + self.assertIsInstance(logentry.page(), pywikibot.User) + elif logtype == 'upload': + self.assertIsInstance(logentry.page(), pywikibot.FilePage) else: self.assertIsInstance(logentry.page(), pywikibot.Page) else: diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 43ca6ce..81386db 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1316,7 +1316,8 @@ self.assertIsNotNone(gen) pages = set(gen) self.assertLessEqual(len(pages), 500) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in pages))
def test_logevents_default_multi(self): """Test old logevents option handling with limit argument.""" @@ -1326,7 +1327,8 @@ self.assertIsNotNone(gen) pages = set(gen) self.assertLessEqual(len(pages), 10) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in pages))
def test_logevents_ns(self): """Test old logevents option with limit argument and namespace.""" @@ -1336,7 +1338,8 @@ gen = gf.getCombinedGenerator() self.assertIsNotNone(gen) self.assertPagesInNamespaces(gen, 1) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in gen)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in gen))
def test_logevents_user_multi(self): """Test old logevents option for a given user.""" @@ -1354,7 +1357,8 @@ # (no easy way of checking from pages)
self.assertLessEqual(len(pages), 10) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in pages))
def test_logevents_with_start_timestamp(self): """Test -logevents which uses timestamp for start.""" @@ -1368,7 +1372,8 @@ self.assertIsNotNone(gen) pages = set(gen) self.assertGreater(len(pages), 0) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in pages))
def test_logevents_with_start_and_end_timestamp(self): """Test -logevents which uses timestamps for start and end.""" @@ -1387,7 +1392,8 @@ self.assertIsNotNone(gen) pages = set(gen) self.assertEqual(len(pages), 1) - self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages)) + self.assertTrue(all(isinstance(item, pywikibot.User) + for item in pages))
class PageGeneratorIntersectTestCase(GeneratorIntersectTestCase,
pywikibot-commits@lists.wikimedia.org