Happy5214 has uploaded a new change for review.

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

Change subject: Enabling the creation of Pages using links relative to another 
Page
......................................................................

Enabling the creation of Pages using links relative to another Page

This commit allows the creation of Page objects using relative
links. (i.e. /foo) The BasePage constructor is modified to prepend
the title of a passed Page to the passed title, instead of only
using the passed title string. A new test, test_subpage, is added
to page_tests.py, containing equality and namespace checks.

Bug: T57113
Change-Id: Icac660e8fb49d3dc11582df952ff53789db58df3
---
M pywikibot/page.py
M tests/page_tests.py
2 files changed, 10 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/28/200328/1

diff --git a/pywikibot/page.py b/pywikibot/page.py
index e99694e..c0a5db8 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -125,7 +125,7 @@
                                  self.__dict__[k] is None)
             if title:
                 # overwrite title
-                self._link = Link(title, source=source.site,
+                self._link = Link(source.title() + title, source=source.site,
                                   defaultNamespace=ns)
         elif isinstance(source, Link):
             self._link = source
diff --git a/tests/page_tests.py b/tests/page_tests.py
index d170cab..1ff1f53 100644
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -312,6 +312,15 @@
         # Test not valid source.
         self.assertRaises(pywikibot.Error, pywikibot.Page, 'dummy')
 
+    def test_subpage(self):
+        """Test creation of Pages for subpages using relative links."""
+        site = self.get_site()
+        p1 = pywikibot.Page(site, u"Project:Template:Test")
+        p2 = pywikibot.Page(site, u"Project:Template:Test/doc")
+        p3 = pywikibot.Page(p1, u"/doc")
+        self.assertEqual(p2, p3)
+        self.assertEqual(p3.namespace(), 4)
+
     def testTitle(self):
         """Test title() method options in article namespace."""
         # at last test article namespace

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icac660e8fb49d3dc11582df952ff53789db58df3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 <happy5...@gmail.com>

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

Reply via email to