示例#1
0
def update_linkbacks(mode):
    """
    Update titles of pages that link to the instance
    @param mode: 1 update page titles of new linkbacks
                 2 update page titles of old linkbacks
                 3 update manually set page titles
                 4 detect and disable broken linkbacks
    """
    if mode in (1, 2, 3):
        if mode == 1:
            urls_and_titles = get_urls_and_titles(
                CFG_WEBLINKBACK_PAGE_TITLE_STATUS['NEW'])
        elif mode == 2:
            urls_and_titles = get_urls_and_titles(
                CFG_WEBLINKBACK_PAGE_TITLE_STATUS['OLD'])
        elif mode == 3:
            urls_and_titles = get_urls_and_titles(
                CFG_WEBLINKBACK_PAGE_TITLE_STATUS['MANUALLY_SET'])

        for (url, title, manual_set, broken_count) in urls_and_titles:  # pylint: disable=W0612
            new_title = get_title_of_page(url)
            # Only accept valid titles
            if new_title != None:
                update_url_title(url, new_title)

    elif mode == 4:
        urls_and_titles = get_urls_and_titles()
        for (url, title, manual_set, broken_count) in urls_and_titles:  # pylint: disable=W0612
            new_title = get_title_of_page(url)
            # Broken one detected
            if new_title == None:
                increment_broken_count(url)
                if broken_count + 1 == CFG_WEBLINKBACK_BROKEN_COUNT:
                    set_url_broken(url)
示例#2
0
def update_linkbacks(mode):
    """
    Update titles of pages that link to the instance
    @param mode: 1 update page titles of new linkbacks
                 2 update page titles of old linkbacks
                 3 update manually set page titles
                 4 detect and disable broken linkbacks
    """
    if mode in (1, 2, 3):
        if mode == 1:
            urls_and_titles = get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['NEW'])
        elif mode == 2:
            urls_and_titles = get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['OLD'])
        elif mode == 3:
            urls_and_titles = get_urls_and_titles(CFG_WEBLINKBACK_PAGE_TITLE_STATUS['MANUALLY_SET'])

        for (url, title, manual_set, broken_count) in urls_and_titles: # pylint: disable=W0612
            new_title = get_title_of_page(url)
            # Only accept valid titles
            if new_title != None:
                update_url_title(url, new_title)

    elif mode == 4:
        urls_and_titles = get_urls_and_titles()
        for (url, title, manual_set, broken_count) in urls_and_titles: # pylint: disable=W0612
            new_title = get_title_of_page(url)
            # Broken one detected
            if new_title == None:
                increment_broken_count(url)
                if broken_count + 1 == CFG_WEBLINKBACK_BROKEN_COUNT:
                    set_url_broken(url)
 def test_set_url_broken(self):
     """weblinkback - test set URL broken"""
     add_url_to_list('URL1', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
     set_url_broken('URL1')
     entry_table = self.get_all_from_table('lnkENTRY')
     self.assertEqual(CFG_WEBLINKBACK_STATUS['BROKEN'], entry_table[0][5])
     self.assertEqual(CFG_WEBLINKBACK_STATUS['BROKEN'], entry_table[8][5])
     self.assertEqual(9, len(self.get_all_from_table("lnkENTRY")))
     self.assertEqual(11, len(self.get_all_from_table("lnkENTRYLOG")))
    def test_delete_linkbacks_on_blacklist(self):
        """weblinkback - test delete linkbacks on blacklist"""
        for linkbackid in (1, 2, 3, 4):
            approve_linkback(linkbackid + self._max_id_lnkENTRY, self.user_info)
        for linkbackid in (5, 6):
            reject_linkback(linkbackid + self._max_id_lnkENTRY, self.user_info)

        add_url_to_list('RL1', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
        add_url_to_list('URL5', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
        add_url_to_list('RL7', CFG_WEBLINKBACK_LIST_TYPE['BLACKLIST'], self.user_info)
        set_url_broken('URL1')
        entry_table = self.get_all_from_table('lnkENTRY')
        self.assertEqual(CFG_WEBLINKBACK_STATUS['BROKEN'], entry_table[0][5])
        self.assertEqual(CFG_WEBLINKBACK_STATUS['BROKEN'], entry_table[8][5])
        self.assertEqual(9, len(self.get_all_from_table("lnkENTRY")))
        self.assertEqual(17, len(self.get_all_from_table("lnkENTRYLOG")))
        self.assertEqual(20, len(self.get_all_from_table("lnkLOG")))

        delete_linkbacks_on_blacklist()
        self.assertEqual(5, len(self.get_all_from_table("lnkENTRY")))
        self.assertEqual(9, len(self.get_all_from_table("lnkENTRYLOG")))
        self.assertEqual(12, len(self.get_all_from_table("lnkLOG")))