jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/814354 )
Change subject: [tests] Fix logentries_tests ......................................................................
[tests] Fix logentries_tests
Bug: T313184 Bug: T313186 Change-Id: I26032e21e0d24bdd4812da7d6bcc787df00cb0cf --- M pywikibot/logentries.py M tests/logentries_tests.py 2 files changed, 19 insertions(+), 7 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index fcc3cdc..433ffd5 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -217,21 +217,33 @@
@property def oldgroups(self) -> List[str]: - """Return old rights groups.""" + """Return old rights groups. + + .. versionchanged:: 7.5 + No longer raise KeyError if `oldgroups` does not exists or + LogEntry has no additional data e.g. due to hidden data and + insufficient rights. + """ params = self._params if 'old' in params: # old mw style (mw < 1.25) return params['old'].split(',') if params['old'] else []
- return params['oldgroups'] + return params.get('oldgroups', [])
@property def newgroups(self) -> List[str]: - """Return new rights groups.""" + """Return new rights groups. + + .. versionchanged:: 7.5 + No longer raise KeyError if `oldgroups` does not exists or + LogEntry has no additional data e.g. due to hidden data and + insufficient rights. + """ params = self._params if 'new' in params: # old mw style (mw < 1.25) return params['new'].split(',') if params['new'] else []
- return params['newgroups'] + return params.get('newgroups', [])
class UploadEntry(LogEntry): diff --git a/tests/logentries_tests.py b/tests/logentries_tests.py index 91b3a22..a996cbd 100755 --- a/tests/logentries_tests.py +++ b/tests/logentries_tests.py @@ -88,10 +88,12 @@
try: self.assertIsInstance(logentry.comment(), str) + self.assertIsInstance(logentry.user(), str) + self.assertEqual(logentry.user(), logentry['user']) except HiddenKeyError as e: self.assertRegex( str(e), - r"Log entry ([^)]+) has a hidden 'comment' key and you " + r"Log entry ([^)]+) has a hidden '\w+' key and you " r"don't have permission to view it") except KeyError as e: self.assertRegex(str(e), "Log entry ([^)]+) has no 'comment' key") @@ -125,12 +127,10 @@ logentry.page()
self.assertEqual(logentry.type(), logtype) - self.assertIsInstance(logentry.user(), str) self.assertGreaterEqual(logentry.logid(), 0)
# test new UserDict style self.assertEqual(logentry.type(), logentry['type']) - self.assertEqual(logentry.user(), logentry['user']) self.assertEqual(logentry.logid(), logentry['logid'])
pywikibot-commits@lists.wikimedia.org