예제 #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_update_titles_of_old_linkbacks(self):
            """weblinkback - test update titles of old linkbacks"""
            self.assertNotEqual([], test_web_page_content(CFG_SITE_URL + '/%s/41/linkbacks/sendtrackback?url=http://www.google.au&title=Google' % CFG_SITE_RECORD, username='******'))
            self.assertNotEqual([], test_web_page_content(CFG_SITE_URL + '/%s/41/linkbacks/sendtrackback?url=http://www.google.at' % CFG_SITE_RECORD, username='******'))
            self.assertNotEqual([], test_web_page_content(CFG_SITE_URL + '/%s/41/linkbacks/sendtrackback?url=http://www.google.co.za&title=Google' % CFG_SITE_RECORD, username='******'))

            update_url_title("http://www.google.au", "Google AU")

            p = patch('invenio.weblinkback.get_title_of_page', get_title_of_page_mock1)
            p.start()
            update_linkbacks(2)
            url_entries = self.get_all_from_table("lnkENTRYURLTITLE")
            self.assertEqual(get_title_of_page_mock1(), url_entries[0][2])
            self.assertEqual("", url_entries[1][2])
            self.assertEqual("Google", url_entries[2][2])
            update_linkbacks(1)
            p.stop()

            p = patch('invenio.weblinkback.get_title_of_page', get_title_of_page_mock2)
            p.start()
            update_linkbacks(2)
            url_entries = self.get_all_from_table("lnkENTRYURLTITLE")
            self.assertEqual(get_title_of_page_mock2(), url_entries[0][2])
            self.assertEqual(get_title_of_page_mock2(), url_entries[1][2])
            self.assertEqual("Google", url_entries[2][2])
            p.stop()