jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/333291 )

Change subject: page_tests.py: Add a dry test for FilePage.get_file_history
......................................................................


page_tests.py: Add a dry test for FilePage.get_file_history

12987c8085dbfd4e63ee3346d55e97795e734f8a fixed a bug in get_file_history
that was preventing the file history from being loaded. This patch adds
a test for that method which previously was not covered in any test.

Bug: T155740
Change-Id: I9b6b333eb562227a272a862f1edf5c25544a319b
---
M tests/page_tests.py
1 file changed, 26 insertions(+), 3 deletions(-)

Approvals:
  jenkins-bot: Verified
  Sn1per: Looks good to me, approved



diff --git a/tests/page_tests.py b/tests/page_tests.py
index ebb9a38..1af59a2 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1,15 +1,17 @@
 # -*- coding: utf-8 -*-
 """Tests for the page module."""
 #
-# (C) Pywikibot team, 2008-2016
+# (C) Pywikibot team, 2008-2017
 #
 # Distributed under the terms of the MIT license.
 #
 from __future__ import absolute_import, unicode_literals
 
-__version__ = '$Id$'
-
 import pickle
+try:
+    import unittest.mock as mock
+except ImportError:
+    import mock
 
 import pywikibot
 import pywikibot.page
@@ -28,6 +30,9 @@
     unittest, TestCase, DefaultSiteTestCase, SiteAttributeTestCase,
     DefaultDrySiteTestCase, DeprecationTestCase,
 )
+
+
+__version__ = '$Id$'
 
 
 class TestLinkObject(SiteAttributeTestCase):
@@ -566,6 +571,24 @@
         cls.page = pywikibot.Page(cls.site, 'Ō')
 
 
+class TestPageGetFileHistory(DefaultDrySiteTestCase):
+
+    """Test the get_file_history method of the FilePage class."""
+
+    def test_get_file_history_cache(self):
+        """Test the cache mechanism of get_file_history."""
+        with mock.patch.object(self.site, 'loadimageinfo', autospec=True):
+            page = pywikibot.FilePage(self.site, 'File:Foo.jpg')
+            _file_revisions = page.get_file_history()
+            # On the first call the history is loaded via API
+            self.assertEqual(_file_revisions, {})
+            # Fill the cache
+            _file_revisions['foo'] = 'bar'
+            # On the second call page._file_revisions is returned
+            self.assertEqual(page.get_file_history(), {'foo': 'bar'})
+            self.site.loadimageinfo.assert_called_once_with(page, history=True)
+
+
 class TestPageRepr(TestPageBaseUnicode):
 
     """Test for Page's repr implementation."""

-- 
To view, visit https://gerrit.wikimedia.org/r/333291
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9b6b333eb562227a272a862f1edf5c25544a319b
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Sn1per <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to