Dalba has uploaded a new change for review. (
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(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/91/333291/1
diff --git a/tests/page_tests.py b/tests/page_tests.py
index ebb9a38..c78967e 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -7,9 +7,11 @@
#
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,25 @@
cls.page = pywikibot.Page(cls.site, 'Ō')
+class TestPageGetFileHistory(DefaultDrySiteTestCase):
+
+ """Test the get_file_history method of the page 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
+ self.site.loadimageinfo.assert_called_with(page, history=True)
+ 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()
+
+
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: newchange
Gerrit-Change-Id: I9b6b333eb562227a272a862f1edf5c25544a319b
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits