jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] page: Return timestamp string ......................................................................
[FIX] page: Return timestamp string
Several methods (BasePage.getCreator(), BasePage.getLatestEditors(), FilePage.getLatestUploader() and FilePage.getFirstUploader()) use the direct result from the API and not a Timestamp instance.
The first two methods were added in f562b94d, the second in d298facc and the last in bc4df36a. Both FilePage related methods were added with or after the FileInfo class was added and the BasePage methods use the Revision class. Both classes, FileInfo and Revision used Timestamp instances at that point already.
This can technically break parts although all methods have been already deprecated when they were added to the library. So scripts should have changed to the current replacements if they were fixed.
Change-Id: I82c2984ec736529acbe3aa8ac9dde6aadb91fcdd --- M pywikibot/page.py M tests/file_tests.py M tests/page_tests.py 3 files changed, 45 insertions(+), 7 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved XZise: Looks good to me, but someone else must approve Xqt: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index adac029..7ea7337 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -1578,7 +1578,7 @@ @rtype: tuple(username, Timestamp) """ result = self.oldest_revision - return result.user, result.timestamp + return result.user, result.timestamp.isoformat()
@deprecated('contributors() or revisions()') @deprecated_args(limit="total") @@ -1590,7 +1590,7 @@ @param total: iterate no more than this number of revisions in total @rtype: list of dict, each dict containing the username and Timestamp """ - return [{'user': rev.user, 'timestamp': rev.timestamp} + return [{'user': rev.user, 'timestamp': rev.timestamp.isoformat()} for rev in self.revisions(total=total)]
@deprecate_arg("throttle", None) @@ -2229,7 +2229,8 @@ For compatibility with compat only.
""" - return [self.oldest_file_info.user, self.oldest_file_info.timestamp] + return [self.oldest_file_info.user, + self.oldest_file_info.timestamp.isoformat()]
@deprecated("FilePage.latest_file_info.user") def getLatestUploader(self): @@ -2238,7 +2239,8 @@ For compatibility with compat only.
""" - return [self.latest_file_info.user, self.latest_file_info.timestamp] + return [self.latest_file_info.user, + self.latest_file_info.timestamp.isoformat()]
@deprecated('FilePage.get_file_history()') def getFileVersionHistory(self): diff --git a/tests/file_tests.py b/tests/file_tests.py index 625df91..7cb538c 100644 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -11,7 +11,12 @@
import pywikibot
-from tests.aspects import unittest, TestCase +from pywikibot.tools import PY2 + +from tests.aspects import unittest, TestCase, DeprecationTestCase + +if not PY2: + unicode = str
class TestShareFiles(TestCase): @@ -150,6 +155,34 @@ image = image.latest_file_info
+class TestDeprecatedFilePage(DeprecationTestCase): + + """Test deprecated parts of FilePage.""" + + family = 'commons' + code = 'commons' + + cached = True + + def test_getFirstUploader(self): + """Test getFirstUploader.""" + page = pywikibot.FilePage(self.site, 'File:Albert Einstein.jpg') + first = page.getFirstUploader() + self.assertOneDeprecation() + self.assertEqual(first, ['Herbizid', '2011-03-18T10:04:48Z']) + self.assertIsInstance(first[0], unicode) + self.assertIsInstance(first[1], unicode) + + def test_getLatestUploader(self): + """Test getLatestUploader.""" + page = pywikibot.FilePage(self.site, 'File:Albert Einstein.jpg') + latest = page.getLatestUploader() + self.assertOneDeprecation() + self.assertEqual(len(latest), 2) + self.assertIsInstance(latest[0], unicode) + self.assertIsInstance(latest[1], unicode) + + if __name__ == '__main__': try: unittest.main() diff --git a/tests/page_tests.py b/tests/page_tests.py index 6504b45..ae983a6 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -516,9 +516,12 @@ def test_creator(self): """Test getCreator.""" mainpage = self.get_mainpage() - self.assertEqual(mainpage.getCreator(), + creator = mainpage.getCreator() + self.assertEqual(creator, (mainpage.oldest_revision.user, - mainpage.oldest_revision.timestamp)) + mainpage.oldest_revision.timestamp.isoformat())) + self.assertIsInstance(creator[0], unicode) + self.assertIsInstance(creator[1], unicode) self.assertDeprecation()
self._reset_messages()
pywikibot-commits@lists.wikimedia.org