Revision: 5924 Author: russblau Date: 2008-09-29 21:00:54 +0000 (Mon, 29 Sep 2008)
Log Message: ----------- more tests, and fix some bugs uncovered during testing
Modified Paths: -------------- branches/rewrite/pywikibot/data/api.py branches/rewrite/pywikibot/site.py branches/rewrite/pywikibot/tests/site_tests.py
Modified: branches/rewrite/pywikibot/data/api.py =================================================================== --- branches/rewrite/pywikibot/data/api.py 2008-09-29 02:58:20 UTC (rev 5923) +++ branches/rewrite/pywikibot/data/api.py 2008-09-29 21:00:54 UTC (rev 5924) @@ -583,17 +583,17 @@ for item in pagedict['protection']: page._protection[item['type']] = item['level'], item['expiry'] if 'revisions' in pagedict: - for rev in pagedict['revisions']: - revision = pywikibot.page.Revision( - revid=rev['revid'], - timestamp=rev['timestamp'], - user=rev['user'], - anon=rev.has_key('anon'), - comment=rev.get('comment', u''), - minor=rev.has_key('minor'), - text=rev.get('*', None) - ) - page._revisions[revision.revid] = revision + for rev in pagedict['revisions']: + revision = pywikibot.page.Revision( + revid=rev['revid'], + timestamp=rev['timestamp'], + user=rev['user'], + anon=rev.has_key('anon'), + comment=rev.get('comment', u''), + minor=rev.has_key('minor'), + text=rev.get('*', None) + ) + page._revisions[revision.revid] = revision if 'lastrevid' in pagedict: page._revid = pagedict['lastrevid'] if page._revid in page._revisions:
Modified: branches/rewrite/pywikibot/site.py =================================================================== --- branches/rewrite/pywikibot/site.py 2008-09-29 02:58:20 UTC (rev 5923) +++ branches/rewrite/pywikibot/site.py 2008-09-29 21:00:54 UTC (rev 5924) @@ -827,19 +827,6 @@ continue page = cache[pagedata['title']] api.update_page(page, pagedata) - if 'revisions' in pagedata: # true if page exists - for rev in pagedata['revisions']: - revision = pywikibot.page.Revision( - revid=rev['revid'], - timestamp=rev['timestamp'], - user=rev['user'], - anon=rev.has_key('anon'), - comment=rev.get('comment', u''), - minor=rev.has_key('minor'), - text=rev.get('*', None) - ) - page._revisions[revision.revid] = revision - page._revid = revision.revid yield page
def token(self, page, tokentype): @@ -1089,11 +1076,11 @@ # assemble API request if revids is None: rvtitle = page.title(withSection=False).encode(self.encoding()) - rvgen = api.PropertyGenerator(u"revisions", titles=rvtitle, + rvgen = api.PropertyGenerator(u"info|revisions", titles=rvtitle, site=self) else: ids = u"|".join(unicode(r) for r in revids) - rvgen = api.PropertyGenerator(u"revisions", revids=ids, + rvgen = api.PropertyGenerator(u"info|revisions", revids=ids, site=self) if getText: rvgen.request[u"rvprop"] = \ @@ -1132,21 +1119,6 @@ else: page = Page(self, pagedata['title']) api.update_page(page, pagedata) - if 'revisions' not in pagedata: - continue - for rev in pagedata['revisions']: - revision = pywikibot.page.Revision( - revid=rev['revid'], - timestamp=rev['timestamp'], - user=rev['user'], - anon=rev.has_key('anon'), - comment=rev.get('comment', u''), - minor=rev.has_key('minor'), - text=rev.get('*', None) - ) - page._revisions[revision.revid] = revision - if latest: - page._revid = revision.revid
def pageinterwiki(self, page): # TODO
Modified: branches/rewrite/pywikibot/tests/site_tests.py =================================================================== --- branches/rewrite/pywikibot/tests/site_tests.py 2008-09-29 02:58:20 UTC (rev 5923) +++ branches/rewrite/pywikibot/tests/site_tests.py 2008-09-29 21:00:54 UTC (rev 5924) @@ -203,19 +203,42 @@ namespaces=[0])))) self.assertTrue(backlinks.issubset( set(mysite.pagebacklinks(mainpage, namespaces=[0, 2])))) - # - for pl in mysite.pagelinks(mainpage): + # test embeddedin arguments + self.assertTrue(embedded.issuperset( + set(mysite.page_embeddedin(mainpage, filterRedirects=True, + namespaces=[0])))) + self.assertTrue(embedded.issuperset( + set(mysite.page_embeddedin(mainpage, filterRedirects=False, + namespaces=[0])))) + self.assertTrue(embedded.issubset( + set(mysite.page_embeddedin(mainpage, namespaces=[0, 2])))) + links = set(mysite.pagelinks(mainpage)) + for pl in links: self.assertType(pl, pywikibot.Page) + # test links arguments + self.assertTrue(links.issuperset( + set(mysite.pagelinks(mainpage, namespaces=[0, 1])))) + for target in mysite.preloadpages( + mysite.pagelinks(mainpage, follow_redirects=True)): + self.assertType(target, pywikibot.Page) + self.assertFalse(target.isRedirectPage()) + # test pagecategories for cat in mysite.pagecategories(mainpage): self.assertType(cat, pywikibot.Category) for cm in mysite.categorymembers(cat): self.assertType(cat, pywikibot.Page) + # test pageimages self.assertTrue(all(isinstance(im, pywikibot.ImagePage) for im in mysite.pageimages(mainpage))) + # test pagetemplates self.assertTrue(all(isinstance(te, pywikibot.Page) for te in mysite.pagetemplates(mainpage))) + self.assertTrue(set(mysite.pagetemplates(mainpage)).issuperset( + set(mysite.pagetemplates(mainpage, namespaces=[10])))) + # test pagelanglinks for ll in mysite.pagelanglinks(mainpage): self.assertType(ll, pywikibot.Link) + # test page_extlinks self.assertTrue(all(isinstance(el, basestring) for el in mysite.page_extlinks(mainpage)))
@@ -226,16 +249,68 @@ self.assertTrue(hasattr(mainpage, "_revid")) self.assertTrue(hasattr(mainpage, "_revisions")) self.assertTrue(mainpage._revisions.has_key(mainpage._revid)) + # TODO test all the optional arguments
def testAllPages(self): """Test the site.allpages() method""" - + + global ap, ap6, ap7 ap = list(mysite.allpages(limit=10)) self.assertTrue(len(ap) <= 10) for page in ap: self.assertType(page, pywikibot.Page) self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) # TODO: test various optional arguments to allpages + ap1 = mysite.allpages(start="Py", limit=10) + for page in ap1: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + self.assertTrue(page.title() >= "Py") + ap2 = mysite.allpages(prefix="Pre", limit=10) + for page in ap2: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + self.assertTrue(page.title().startswith("Pre")) + ap3 = mysite.allpages(namespace=1, limit=10) + for page in ap3: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 1) + ap4= mysite.allpages(filterredir=True, limit=10) + for page in ap4: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + self.assertTrue(page.isRedirectPage()) + ap5= mysite.allpages(filterredir=False, limit=10) + for page in ap5: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + self.assertFalse(page.isRedirectPage()) + ap6= list(mysite.allpages(filterlanglinks=True, limit=10)) + for page in ap6: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + ap7= list(mysite.allpages(filterlanglinks=False, limit=10)) + for page in ap7: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertEqual(page.namespace(), 0) + ap8 = mysite.allpages(minsize=100, limit=10) + for page in ap8: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertTrue(len(page.text) >= 100) + ap9 = mysite.allpages(maxsize=200, limit=10) + for page in ap9: + self.assertType(page, pywikibot.Page) + self.assertTrue(mysite.page_exists(page)) + self.assertTrue(len(page.text) <= 200)
def testAllLinks(self): """Test the site.alllinks() method"""