Esempio n. 1
0
def test_http_retrieve_relative_location(util):
    "http_retrieve() Should deal with relative paths on Location"

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {}

    # Given a mocked response that returns a relative Location URL
    pool = Mock()
    pool.request.side_effect = [
        Mock(headers={'location': '/a/relative/url'}),
        Mock(headers={}),
    ]

    # When I check that
    downloader.http_retrieve(pool, 'http://bitbucket.com/')

    list(pool.request.call_args_list).should.equal([
        call('GET',
             'http://bitbucket.com/',
             headers={},
             preload_content=False,
             redirect=False),
        call('GET',
             'http://bitbucket.com/a/relative/url',
             headers={},
             preload_content=False,
             redirect=False),
    ])
Esempio n. 2
0
def test_http_retrieve(util):
    "http_retrieve() Should follow redirects and return the final URL"

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {}

    # Given a mocked response
    pool = Mock()
    pool.request.side_effect = [
        Mock(headers={'location': 'http://bitbucket.com'}),
        Mock(headers={}),
    ]

    # When I retrieve a URL
    response, url = downloader.http_retrieve(pool, 'http://github.com')

    # Then the url should be the output of the redirect
    url.should.equal('http://bitbucket.com')

    # Even though we originally requested a different one
    list(pool.request.call_args_list).should.equal([
        call('GET',
             'http://github.com',
             redirect=False,
             headers={},
             preload_content=False),
        call('GET',
             'http://bitbucket.com',
             redirect=False,
             headers={},
             preload_content=False),
    ])
Esempio n. 3
0
def test_pool_retrieve_no_redirect(util):
    ("http_retrieve() Should retrieve a URL and return a tuple "
     "containing the response and the final URL of the retrieved resource")

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {'foo': 'bar'}

    # Given a mocked response
    pool = Mock()
    pool.request.return_value = Mock(headers={})

    # When I retrieve a URL
    _, url = downloader.http_retrieve(pool, 'http://github.com')

    # Then the url should be the same as requested
    url.should.equal('http://github.com')
    util.get_auth_info_from_url.assert_called_once_with('http://github.com')

    # And that the request should be executed with the correct
    # parameters
    pool.request.assert_called_once_with(
        'GET',
        'http://github.com',
        headers={'foo': 'bar'},
        preload_content=False,
        redirect=False,
    )
def test_http_retrieve(util):
    "http_retrieve() Should follow redirects and return the final URL"

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {}

    # Given a mocked response
    pool = Mock()
    pool.request.side_effect = [
        Mock(headers={'location': 'http://bitbucket.com'}),
        Mock(headers={}),
    ]

    # When I retrieve a URL
    response, url = downloader.http_retrieve(pool, 'http://github.com')

    # Then the url should be the output of the redirect
    url.should.equal('http://bitbucket.com')

    # Even though we originally requested a different one
    list(pool.request.call_args_list).should.equal([
        call('GET', 'http://github.com', redirect=False, headers={}, preload_content=False),
        call('GET', 'http://bitbucket.com', redirect=False, headers={}, preload_content=False),
    ])
def test_pool_retrieve_no_redirect(util):
    ("http_retrieve() Should retrieve a URL and return a tuple "
     "containing the response and the final URL of the retrieved resource")

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {'foo': 'bar'}

    # Given a mocked response
    pool = Mock()
    pool.request.return_value = Mock(headers={})

    # When I retrieve a URL
    _, url = downloader.http_retrieve(pool, 'http://github.com')

    # Then the url should be the same as requested
    url.should.equal('http://github.com')
    util.get_auth_info_from_url.assert_called_once_with('http://github.com')

    # And that the request should be executed with the correct
    # parameters
    pool.request.assert_called_once_with(
        'GET', 'http://github.com',
        headers={'foo': 'bar'},
        preload_content=False,
        redirect=False,
    )
def test_http_retrieve_relative_location(util):
    "http_retrieve() Should deal with relative paths on Location"

    # Background:
    # util.get_auth_info_from_url returns a fake dictionary
    util.get_auth_info_from_url.return_value = {}

    # Given a mocked response that returns a relative Location URL
    pool = Mock()
    pool.request.side_effect = [
        Mock(headers={'location': '/a/relative/url'}),
        Mock(headers={}),
    ]

    # When I check that
    downloader.http_retrieve(pool, 'http://bitbucket.com/')

    list(pool.request.call_args_list).should.equal([
        call('GET', 'http://bitbucket.com/', headers={}, preload_content=False, redirect=False),
        call('GET', 'http://bitbucket.com/a/relative/url', headers={}, preload_content=False, redirect=False),
    ])