Example #1
0
    def testLoadConfigInTemplateNamespace(self):
        """Test loading of config with TEMPLATE_PAGE in Template ns.

        Talk:For-pywikibot-archivebot-01 must have:

         {{Pywikibot_archivebot
         |archive = Talk:Main_Page/archive
         |algo = old(30d)
         }}
        """
        site = self.get_site()
        page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot-01')

        # TEMPLATE_PAGE assumed in ns=10 if ns is not explicit.
        tmpl_with_ns = pywikibot.Page(site, 'Template:Pywikibot_archivebot')
        tmpl_without_ns = pywikibot.Page(site, 'Pywikibot_archivebot', ns=10)

        try:
            archivebot.PageArchiver(page, tmpl_with_ns, '')
        except pywikibot.Error as e:
            self.fail('PageArchiver() raised {}!'.format(e))

        try:
            archivebot.PageArchiver(page, tmpl_without_ns, '')
        except pywikibot.Error as e:
            self.fail('PageArchiver() raised {}!'.format(e))
Example #2
0
    def testTwoThreadsWithCommentedOutThread(self):
        """Test recognizing two threads and ignoring a commented out thread.

        Talk:For-pywikibot-archivebot must have::

         {{User:MiszaBot/config
         |archive = Talk:Main_Page/archive
         |algo = old(30d)
         }}
         <!-- normal comments -->
         == A ==
         foo bar
         <!--
         == Z ==
         foo bar bar
         -->
         == B ==
         foo bar bar bar
        """
        site = self.get_site()
        page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot')
        tmpl = pywikibot.Page(site, 'User:MiszaBot/config')
        archiver = archivebot.PageArchiver(page=page,
                                           template=tmpl,
                                           salt='',
                                           force=False)
        page = archivebot.DiscussionPage(page, archiver)
        page.load_page()
        self.assertEqual([x.title for x in page.threads], ['A', 'B'])
Example #3
0
    def testThreadsWithSubsections(self):
        """Test recognizing threads with subsections.

        Talk:For-pywikibot-archivebot/subsections must have::

         {{User:MiszaBot/config
         |archive = Talk:Main_Page/archive
         |algo = old(30d)
         }}
         = Front matter =
         placeholder
         == A ==
         foo bar
         === A1 ===
         foo bar bar
         ==== A11 ====
         foo
         == B ==
         foo bar bar bar
        """
        site = self.get_site()
        page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot/testcase2')
        tmpl = pywikibot.Page(site, 'User:MiszaBot/config')
        archiver = archivebot.PageArchiver(page=page,
                                           template=tmpl,
                                           salt='',
                                           force=False)
        page = archivebot.DiscussionPage(page, archiver)
        page.load_page()
        self.assertEqual([x.title for x in page.threads], ['A', 'B'])
Example #4
0
 def load_page(self, title: str):
     """Load the given page."""
     page = pywikibot.Page(self.site, title)
     tmpl = pywikibot.Page(self.site, 'User:MiszaBot/config')
     archiver = archivebot.PageArchiver(page=page, template=tmpl, salt='')
     page = archivebot.DiscussionPage(page, archiver)
     page.load_page()
     self.page = page
Example #5
0
    def testLoadConfigInOtherNamespace(self):
        """Test loading of config with TEMPLATE_PAGE not in Template ns.

        Talk:For-pywikibot-archivebot must have:

         {{User:MiszaBot/config
         |archive = Talk:Main_Page/archive
         |algo = old(30d)
         }}
        """
        site = self.get_site()
        page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot')

        tmpl_with_ns = pywikibot.Page(site, 'User:MiszaBot/config', ns=10)
        tmpl_without_ns = pywikibot.Page(site, 'MiszaBot/config', ns=10)

        # TEMPLATE_PAGE assumed in ns=10 if ns is not explicit.
        try:
            archivebot.PageArchiver(page, tmpl_with_ns, '')
        except pywikibot.Error as e:
            self.fail('PageArchiver() raised {}!'.format(e))

        with self.assertRaises(archivebot.MissingConfigError):
            archivebot.PageArchiver(page, tmpl_without_ns, '')