jenkins-bot merged this change.
[bugfix] Ensure that required props exists as Page attribute
If page attributes langlinks or templates are required
ensure that api.update_page creates them as empty lists
even the api does not have them.
This also solves test_preload_templates_and_langlinks
and test_preload_templates failures.
Bug: T237497
Change-Id: I3bb5d8e2046006ed1e262dd9618b0407ee91dae7
---
M pywikibot/data/api.py
M tests/site_tests.py
2 files changed, 10 insertions(+), 15 deletions(-)
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 05b15ca..4ae1892 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -3333,9 +3333,13 @@
if 'templates' in pagedict:
_update_templates(page, pagedict['templates'])
+ elif 'templates' in props:
+ page._templates = []
if 'langlinks' in pagedict:
_update_langlinks(page, pagedict['langlinks'])
+ elif 'langlinks' in props:
+ page._langlinks = []
if 'coordinates' in pagedict:
_update_coordinates(page, pagedict['coordinates'])
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 188b0f4..b4fbfd0 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -3265,7 +3265,7 @@
break
def test_preload_langlinks_normal(self):
- """Test preloading continuation works."""
+ """Test preloading langlinks works."""
mysite = self.get_site()
links = mysite.pagelinks(self.get_mainpage(), total=10)
gen = mysite.preloadpages(links, groupsize=5, langlinks=True)
@@ -3318,22 +3318,14 @@
if count >= 5:
break
- @unittest.expectedFailure
def test_preload_templates_and_langlinks(self):
"""Test preloading templates and langlinks works."""
mysite = self.get_site()
- mainpage = self.get_mainpage()
- count = 0
# Use backlinks, as any backlink has at least one link
- links = mysite.pagebacklinks(mainpage, total=10)
- # Screen pages before test;
- # it is not guaranteed that all pages will have both.
- links = [l for l in links if (l.langlinks() and l.templates())]
- # Skip test if no valid pages are found.
- if not links:
- self.skipTest('No valid pages found to carry out test.')
-
- for page in mysite.preloadpages(links, langlinks=True, templates=True):
+ links = mysite.pagebacklinks(self.get_mainpage(), total=10)
+ for count, page in enumerate(mysite.preloadpages(links,
+ langlinks=True,
+ templates=True)):
with self.subTest(page=page):
self.assertIsInstance(page, pywikibot.Page)
self.assertIsInstance(page.exists(), bool)
@@ -3343,8 +3335,7 @@
self.assertFalse(hasattr(page, '_pageprops'))
self.assertTrue(hasattr(page, '_templates'))
self.assertTrue(hasattr(page, '_langlinks'))
- count += 1
- if count >= 6:
+ if count >= 5:
break
To view, visit change 555727. To unsubscribe, or for help writing mail filters, visit settings.