jenkins-bot has submitted this change and it was merged.
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(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py index 76cf4ae..c05e416 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -3454,7 +3454,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 d5dab0d..990d9ab 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -646,6 +646,7 @@ wikidata = self.get_repo() item = 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 = ItemPage(wikidata, 'Q10008448') item.get(get_redirect=True) target = ItemPage(wikidata, 'Q8422626') + # tests after get operation self.assertTrue(item.isRedirectPage()) + self.assertTrue(item.exists()) self.assertEqual(item.getRedirectTarget(), target) self.assertIsInstance(item.getRedirectTarget(), 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):
pywikibot-commits@lists.wikimedia.org