Example #1
0
    def test_follow_redirects(self):
        for i in range(2):
            self.expect_requests_head("http://will/redirect", redirected_url="http://final/url")
        self.mox.ReplayAll()

        cache = util.CacheDict()
        self.assert_equals("http://final/url", source.follow_redirects("http://will/redirect", cache=cache).url)

        self.assertEquals("http://final/url", cache["R http://will/redirect"].url)

        # another call without cache should refetch
        self.assert_equals("http://final/url", source.follow_redirects("http://will/redirect").url)

        # another call with cache shouldn't refetch
        self.assert_equals("http://final/url", source.follow_redirects("http://will/redirect", cache=cache).url)
Example #2
0
def follow_redirects(url, cache=True):
  """Wraps granary.source.follow_redirects and injects our settings.

  ...specifically memcache and USER_AGENT_HEADER.
  """
  return gr_source.follow_redirects(url, cache=memcache if cache else None,
                                    headers=USER_AGENT_HEADER)
Example #3
0
  def test_follow_redirects_with_refresh_header(self):
    headers = {'x': 'y'}
    self.expect_requests_head('http://will/redirect', headers=headers,
                              response_headers={'refresh': '0; url=http://refresh'})
    self.expect_requests_head('http://refresh', headers=headers,
                              redirected_url='http://final')

    self.mox.ReplayAll()
    cache = util.CacheDict()
    self.assert_equals('http://final',
                       source.follow_redirects('http://will/redirect', cache=cache,
                                               headers=headers).url)
Example #4
0
    def test_follow_redirects_with_refresh_header(self):
        headers = {"x": "y"}
        self.expect_requests_head(
            "http://will/redirect", headers=headers, response_headers={"refresh": "0; url=http://refresh"}
        )
        self.expect_requests_head("http://refresh", headers=headers, redirected_url="http://final")

        self.mox.ReplayAll()
        cache = util.CacheDict()
        self.assert_equals(
            "http://final", source.follow_redirects("http://will/redirect", cache=cache, headers=headers).url
        )
Example #5
0
    def test_follow_redirects(self):
        for i in range(2):
            self.expect_requests_head('http://will/redirect',
                                      redirected_url='http://final/url')
        self.mox.ReplayAll()

        cache = util.CacheDict()
        self.assert_equals(
            'http://final/url',
            source.follow_redirects('http://will/redirect', cache=cache).url)

        self.assertEquals('http://final/url',
                          cache['R http://will/redirect'].url)

        # another call without cache should refetch
        self.assert_equals('http://final/url',
                           source.follow_redirects('http://will/redirect').url)

        # another call with cache shouldn't refetch
        self.assert_equals(
            'http://final/url',
            source.follow_redirects('http://will/redirect', cache=cache).url)
Example #6
0
    def test_follow_redirects_with_refresh_header(self):
        headers = {'x': 'y'}
        self.expect_requests_head(
            'http://will/redirect',
            headers=headers,
            response_headers={'refresh': '0; url=http://refresh'})
        self.expect_requests_head('http://refresh',
                                  headers=headers,
                                  redirected_url='http://final')

        self.mox.ReplayAll()
        cache = util.CacheDict()
        self.assert_equals(
            'http://final',
            source.follow_redirects('http://will/redirect',
                                    cache=cache,
                                    headers=headers).url)
Example #7
0
 def test_follow_redirects_defaults_scheme_to_http(self):
   self.expect_requests_head('http://foo/bar', redirected_url='http://final')
   self.mox.ReplayAll()
   self.assert_equals('http://final', source.follow_redirects('foo/bar').url)
Example #8
0
 def test_follow_redirects_defaults_scheme_to_http(self):
     self.expect_requests_head("http://foo/bar", redirected_url="http://final")
     self.mox.ReplayAll()
     self.assert_equals("http://final", source.follow_redirects("foo/bar").url)
Example #9
0
 def test_follow_redirects_defaults_scheme_to_http(self):
     self.expect_requests_head('http://foo/bar',
                               redirected_url='http://final')
     self.mox.ReplayAll()
     self.assert_equals('http://final',
                        source.follow_redirects('foo/bar').url)