Example #1
0
def test_auth_failed(get_client, tmpdir, scheme):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = yield get(
            get_client(),
            url,
            auth_username=auth[0],
            auth_password=auth[1],
            raise_error=False
        )

    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        two = yield get(
            get_client(),
            url,
            auth_username=auth[0],
            auth_password=auth[1],
            raise_error=False
        )
        assert one.body == two.body
        assert one.code == two.code == 401
        assert 1 == cass.play_count
Example #2
0
def test_auth_failed(get_client, tmpdir, scheme):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        with pytest.raises(http.HTTPError) as exc_info:
            yield get(
                get_client(),
                url,
                auth_username=auth[0],
                auth_password=auth[1],
            )
        one = exc_info.value.response
        assert exc_info.value.code == 401

    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        with pytest.raises(http.HTTPError) as exc_info:
            two = yield get(
                get_client(),
                url,
                auth_username=auth[0],
                auth_password=auth[1],
            )
        two = exc_info.value.response
        assert exc_info.value.code == 401
        assert one.body == two.body
        assert one.code == two.code == 401
        assert 1 == cass.play_count
Example #3
0
def test_auth_failed(get_client, tmpdir, scheme):
    """Ensure that we can save failed auth statuses"""
    auth = ("user", "wrongwrongwrong")
    url = scheme + "://httpbin.org/basic-auth/user/passwd"
    with vcr.use_cassette(str(tmpdir.join("auth-failed.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        with pytest.raises(http.HTTPError) as exc_info:
            yield get(get_client(),
                      url,
                      auth_username=auth[0],
                      auth_password=auth[1])
        one = exc_info.value.response
        assert exc_info.value.code == 401

    with vcr.use_cassette(str(tmpdir.join("auth-failed.yaml"))) as cass:
        with pytest.raises(http.HTTPError) as exc_info:
            two = yield get(get_client(),
                            url,
                            auth_username=auth[0],
                            auth_password=auth[1])
        two = exc_info.value.response
        assert exc_info.value.code == 401
        assert one.body == two.body
        assert one.code == two.code == 401
        assert 1 == cass.play_count
Example #4
0
def test_random_body(scheme, tmpdir):
    """Ensure we can read the content, and that it's served from cache"""
    url = scheme + "://httpbin.org/bytes/1024"
    with vcr.use_cassette(str(tmpdir.join("body.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert urllib2.urlopen(url).read() == urllib2.urlopen(url).read()
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #5
0
def test_response_code(scheme, tmpdir):
    """Ensure we can read a response code from a fetch"""
    url = scheme + "://httpbin.org/"
    with vcr.use_cassette(str(tmpdir.join("atts.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert urllib2.urlopen(url).getcode() == urllib2.urlopen(url).getcode()
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #6
0
def test_headers(scheme, tmpdir):
    '''Ensure that we can read the headers back'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert requests.get(url).headers == requests.get(url).headers
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #7
0
def test_body(tmpdir, scheme):
    '''Ensure the responses are all identical enough'''
    url = scheme + '://httpbin.org/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert requests.get(url).content == requests.get(url).content
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #8
0
def test_random_body(scheme, tmpdir):
    '''Ensure we can read the content, and that it's served from cache'''
    url = scheme + '://httpbin.org/bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('body.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert urllib2.urlopen(url).read() == urllib2.urlopen(url).read()
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #9
0
def test_response_code(scheme, tmpdir):
    '''Ensure we can read a response code from a fetch'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('atts.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert urllib2.urlopen(url).getcode() == urllib2.urlopen(url).getcode()
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #10
0
def test_response_headers(scheme, tmpdir):
    """Ensure we can get information from the response"""
    url = scheme + "://httpbin.org/"
    with vcr.use_cassette(str(tmpdir.join("headers.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        open1 = urllib2.urlopen(url).info().items()
        open2 = urllib2.urlopen(url).info().items()
        assert open1 == open2
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #11
0
def test_response_headers(scheme, tmpdir):
    '''Ensure we can get information from the response'''
    url = scheme + '://httpbin.org/'
    with vcr.use_cassette(str(tmpdir.join('headers.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        open1 = urllib2.urlopen(url).info().items()
        open2 = urllib2.urlopen(url).info().items()
        assert open1 == open2
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #12
0
def test_auth_failed(tmpdir, httpbin_both):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = httpbin_both + '/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = requests.get(url, auth=auth)
        two = requests.get(url, auth=auth)
        assert one.content == two.content
        assert one.status_code == two.status_code == 401
Example #13
0
def test_redirects(tmpdir, scheme):
    '''Ensure that we can handle redirects'''
    url = scheme + '://httpbin.org/redirect-to?url=bytes/1024'
    with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        assert requests.get(url).content == requests.get(url).content
        # Ensure that we've now cached *two* responses. One for the redirect
        # and one for the final fetch
        assert len(cass) == 2
        assert cass.play_count == 2
Example #14
0
def test_auth_failed(tmpdir, scheme):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = requests.get(url, auth=auth)
        two = requests.get(url, auth=auth)
        assert one.content == two.content
        assert one.status_code == two.status_code == 401
def test_auth_failed(tmpdir, httpbin_both):
    """Ensure that we can save failed auth statuses"""
    auth = ("user", "wrongwrongwrong")
    url = httpbin_both + "/basic-auth/user/passwd"
    with vcr.use_cassette(str(tmpdir.join("auth-failed.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = requests.get(url, auth=auth)
        two = requests.get(url, auth=auth)
        assert one.content == two.content
        assert one.status_code == two.status_code == 401
Example #16
0
def test_post_data(scheme, tmpdir):
    """Ensure that it works when posting data"""
    data = urlencode({"some": 1, "data": "here"})
    url = scheme + "://httpbin.org/post"
    with vcr.use_cassette(str(tmpdir.join("post_data.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        res1 = urllib2.urlopen(url, data).read()
        res2 = urllib2.urlopen(url, data).read()
        assert res1 == res2
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #17
0
def test_post_data(scheme, tmpdir):
    '''Ensure that it works when posting data'''
    data = urlencode({'some': 1, 'data': 'here'})
    url = scheme + '://httpbin.org/post'
    with vcr.use_cassette(str(tmpdir.join('post_data.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        res1 = urllib2.urlopen(url, data).read()
        res2 = urllib2.urlopen(url, data).read()
        assert res1 == res2
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #18
0
def test_auth_failed(tmpdir, scheme, verify_pool_mgr):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    headers = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(*auth))
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = verify_pool_mgr.request('GET', url, headers=headers)
        two = verify_pool_mgr.request('GET', url, headers=headers)
        assert one.data == two.data
        assert one.status == two.status == 401
Example #19
0
def test_post(tmpdir, scheme):
    '''Ensure that we can post and cache the results'''
    data = {'key1': 'value1', 'key2': 'value2'}
    url = scheme + '://httpbin.org/post'
    with vcr.use_cassette(str(tmpdir.join('requests.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        req1 = requests.post(url, data).content
        req2 = requests.post(url, data).content
        assert req1 == req2
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
def test_auth_failed(tmpdir, httpbin_both, verify_pool_mgr):
    """Ensure that we can save failed auth statuses"""
    auth = ("user", "wrongwrongwrong")
    headers = urllib3.util.make_headers(basic_auth="{}:{}".format(*auth))
    url = httpbin_both.url + "/basic-auth/user/passwd"
    with vcr.use_cassette(str(tmpdir.join("auth-failed.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = verify_pool_mgr.request("GET", url, headers=headers)
        two = verify_pool_mgr.request("GET", url, headers=headers)
        assert one.data == two.data
        assert one.status == two.status == 401
Example #21
0
def test_auth_failed(tmpdir, httpbin_both, verify_pool_mgr):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    headers = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(*auth))
    url = httpbin_both.url + '/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = verify_pool_mgr.request('GET', url, headers=headers)
        two = verify_pool_mgr.request('GET', url, headers=headers)
        assert one.data == two.data
        assert one.status == two.status == 401
Example #22
0
def test_get_data(scheme, tmpdir):
    '''Ensure that it works with query data'''
    data = urlencode({'some': 1, 'data': 'here'})
    url = scheme + '://httpbin.org/get?' + data
    with vcr.use_cassette(str(tmpdir.join('get_data.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        res1 = urllib2.urlopen(url).read()
        res2 = urllib2.urlopen(url).read()
        assert res1 == res2
        # Ensure that we've now cached a single response
        assert len(cass) == 1
        assert cass.play_count == 1
Example #23
0
def test_auth_failed(tmpdir, scheme):
    '''Ensure that we can save failed auth statuses'''
    auth = ('user', 'wrongwrongwrong')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth-failed.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = requests.get(url, auth=auth)
        two = requests.get(url, auth=auth)
        assert one.content == two.content
        assert one.status_code == two.status_code == 401
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #24
0
def test_auth(tmpdir, scheme):
    '''Ensure that we can handle basic auth'''
    auth = ('user', 'passwd')
    url = scheme + '://httpbin.org/basic-auth/user/passwd'
    with vcr.use_cassette(str(tmpdir.join('auth.yaml'))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        one = requests.get(url, auth=auth)
        two = requests.get(url, auth=auth)
        assert one.content == two.content
        assert one.status_code == two.status_code
        # Ensure that we've now cached a single response
        assert_cassette_has_one_response(cass)
Example #25
0
def test_get_data(scheme, tmpdir):
    """Ensure that it works with query data"""
    data = urlencode({"some": 1, "data": "here"})
    url = scheme + "://httpbin.org/get?" + data
    with vcr.use_cassette(str(tmpdir.join("get_data.yaml"))) as cass:
        # Ensure that this is empty to begin with
        assert_cassette_empty(cass)
        res1 = urllib2.urlopen(url).read()
        res2 = urllib2.urlopen(url).read()
        assert res1 == res2
        # Ensure that we've now cached a single response
        assert len(cass) == 1
        assert cass.play_count == 1