예제 #1
0
 def test_uX_prefix_plus_username(self):
     normal = 'https://plus.google.com/+AnnDrake'
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/u/0/+AnnDrake/posts'))
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/u/1/+AnnDrake/posts'))
예제 #2
0
    def test_u1_prefix(self):
        normal = 'https://plus.google.com/109264603825317751107'

        self.assertEqual(
            normal,
            platformutils.normalize_social_url(
                'https://plus.google.com/u/1/109264603825317751107'))
        self.assertEqual(
            normal,
            platformutils.normalize_social_url(
                'https://plus.google.com/u/1/b/109264603825317751107'))
예제 #3
0
    def test_subpages_suffix(self):
        normal = 'https://plus.google.com/109264603825317751107'

        self.assertEqual(normal,
                         platformutils.normalize_social_url(normal + '/posts'))
        self.assertEqual(normal,
                         platformutils.normalize_social_url(normal + '/about'))
        self.assertEqual(
            normal,
            platformutils.normalize_social_url(normal +
                                               '/posts/1234/blahblah'))
예제 #4
0
    def find_owners_url(self, xbrowser):
        try:
            plus_iframes = xbrowser.driver.find_elements_by_xpath(
                self.root_xpaths[0])
            for iframe in plus_iframes:
                url_and_params = iframe.get_attribute('src')
                if url_and_params:
                    parsed = urlparse.urlparse(url_and_params)
                    query = urlparse.parse_qs(parsed.query)

                    # Try different query string params used by the different badge types.
                    gplus_urls = [
                        param
                        for param_name in ['url', 'blogFollowUrl', 'href']
                        for param in query.get(param_name, [])
                    ]
                    for gplus_url in gplus_urls:
                        if 'plus.google.com' in gplus_url and platformutils.username_from_platform_url(
                                gplus_url) is not None:
                            return platformutils.normalize_social_url(
                                gplus_url)
        except Exception as e:
            log.exception(e)

        return None
예제 #5
0
 def test_duplicate_id(self):
     normal = 'https://plus.google.com/117308936952117063631'
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/117308936952117063631/117308936952117063631/posts'
         ))
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/b/117308936952117063631/117308936952117063631/posts'
         ))
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/u/0/b/117308936952117063631/117308936952117063631/posts'
         ))
예제 #6
0
 def find_owners_url(self, xbrowser):
     try:
         gplus_anchors = xbrowser.driver.find_elements_by_xpath(
             self.root_xpaths[0])
         if gplus_anchors:
             gplus_url = gplus_anchors[0].get_attribute('href')
             if platformutils.username_from_platform_url(
                     gplus_url) is not None:
                 return platformutils.normalize_social_url(gplus_url)
     except Exception as e:
         log.exception(e)
     return None
예제 #7
0
    def find_owners_url(self, xbrowser):
        try:
            a_el = xbrowser.driver.find_elements_by_xpath(
                '//a[@class="u-url profile"]')
            if a_el:
                return a_el[0].get_attribute('href')

            f_el = xbrowser.driver.find_elements_by_xpath(
                '//a[@id="follow-button"]')
            if f_el:
                return platformutils.normalize_social_url(
                    f_el[0].get_attribute('href'))

        except Exception as e:
            log.exception(e)

        return None
예제 #8
0
 def test_querystring_params(self):
     normal = 'https://plus.google.com/+LauraDavidson-posts'
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/u/0/+LauraDavidson-posts?rel=author'))
예제 #9
0
 def test_normalized(self):
     normal = 'https://plus.google.com/109264603825317751107'
     normalized = platformutils.normalize_social_url(normal)
     self.assertEqual(normal, normalized)
예제 #10
0
 def test_plus_prefixed_username(self):
     normal = 'https://plus.google.com/+CarliBel55'
     self.assertEqual(
         normal,
         platformutils.normalize_social_url(
             'https://plus.google.com/+CarliBel55/posts'))