jenkins-bot has submitted this change and it was merged.
Change subject: Add Page.set_redirect_target() tests ......................................................................
Add Page.set_redirect_target() tests
Change-Id: I4009817e16a99ef93f9b73f317b9b7a8cd2b4e69 --- M tests/page_tests.py M tests/wikibase_edit_tests.py 2 files changed, 32 insertions(+), 0 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/page_tests.py b/tests/page_tests.py index c031da4..6b3eb2f 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -713,6 +713,22 @@ self.assertRaises(pywikibot.exceptions.IsRedirectPage, p2.get) self.assertRaises(pywikibot.exceptions.NoPage, p3.get)
+ def test_set_redirect_target(self): + """Test set_redirect_target method.""" + # R1 redirects to R2 and R3 doesn't exist. + site = self.get_site() + p1 = pywikibot.Page(site, u'User:Legoktm/R2') + p2 = pywikibot.Page(site, u'User:Legoktm/R1') + p3 = pywikibot.Page(site, u'User:Legoktm/R3') + + text = p2.get(get_redirect=True) + self.assertRaises(pywikibot.exceptions.IsNotRedirectPage, + p1.set_redirect_target, p2) + self.assertRaises(pywikibot.exceptions.NoPage, p3.set_redirect_target, + p2) + p2.set_redirect_target(p1, save=False) + self.assertEqual(text, p2.get(get_redirect=True)) +
class TestFlow(TestCase):
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py index 84dc056..a6bf309 100644 --- a/tests/wikibase_edit_tests.py +++ b/tests/wikibase_edit_tests.py @@ -128,6 +128,22 @@ self.assertEqual(item._defined_by(), dict()) item.editEntity(data)
+ def test_set_redirect_target(self): + """Test set_redirect_target method.""" + testsite = self.get_repo() + item = pywikibot.ItemPage(testsite, 'Q1107') + target_id = 'Q68' + if not item.isRedirectPage(): + item.editEntity(data={}, clear=True) + elif item.getRedirectTarget().getID() == 'Q68': + target_id = 'Q67' + target_item = pywikibot.ItemPage(testsite, target_id) + item.set_redirect_target(target_id, force=True) + self.assertTrue(item.isRedirectPage()) + new_item = pywikibot.ItemPage(testsite, item.getID()) + self.assertTrue(new_item.isRedirectPage()) + self.assertEqual(new_item.getRedirectTarget(), target_item) +
if __name__ == '__main__': try: