Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311337

Change subject: [bugfix] ItemPage.exists() should return True for redirects
......................................................................

[bugfix] ItemPage.exists() should return True for redirects

- If a ItemPage is a redirect to another ItemPage then its exits() method
  should return True and not raise an IsRedirectPage exception
- Test this behavior with and without get() operation because
  ItemPage.get() fills the _content instance variable

Bug: T145971
Change-Id: I8d42372f69eda864811f00d781a56374923abad8
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 13 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/37/311337/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index 79aefc3..4888c3c 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3456,7 +3456,7 @@
         """
         if not hasattr(self, '_content'):
             try:
-                self.get()
+                self.get(get_redirect=True)
                 return True
             except pywikibot.NoPage:
                 return False
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index f428475..1f6241b 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -646,6 +646,7 @@
         wikidata = self.get_repo()
         item = pywikibot.ItemPage(wikidata, 'Q1')
         self.assertFalse(item.isRedirectPage())
+        self.assertTrue(item.exits())
         self.assertRaises(pywikibot.IsNotRedirectPage, item.getRedirectTarget)
 
     def test_redirect_item(self):
@@ -654,11 +655,22 @@
         item = pywikibot.ItemPage(wikidata, 'Q10008448')
         item.get(get_redirect=True)
         target = pywikibot.ItemPage(wikidata, 'Q8422626')
+        # tests after get operation
         self.assertTrue(item.isRedirectPage())
+        self.assertTrue(item.exists())
         self.assertEqual(item.getRedirectTarget(), target)
         self.assertIsInstance(item.getRedirectTarget(), pywikibot.ItemPage)
         self.assertRaises(pywikibot.IsRedirectPage, item.get)
 
+    def test_redirect_item_without_get(self):
+        """Test redirect item without explicit get operation."""
+        wikidata = self.get_repo()
+        item = pywikibot.ItemPage(wikidata, 'Q10008448')
+        self.assertTrue(item.exists())
+        self.assertTrue(item.isRedirectPage())
+        target = pywikibot.ItemPage(wikidata, 'Q8422626')
+        self.assertEqual(item.getRedirectTarget(), target)
+
 
 class TestPropertyPage(WikidataTestCase):
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d42372f69eda864811f00d781a56374923abad8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to