Skip to content
Myr

Inject and use httpbin fixture everywhere.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Cory Benfield · committed by Cory Benfield · parent 9b63f9c · Browse files · 1 file+90 added−90 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+90 added−90 removed

  • other:+90 added−90 removed

1 file+90 added−90 removed

modified:test_requests.py+90 added-90 removed
116 unmodified lines
117 pr = req.prepare()118 assert pr.url == req.url119 assert pr.body == 'life=42'120121 def test_no_content_length(self):121 def test_no_content_length(self, httpbin):122 get_req = requests.Request('GET', httpbin('get')).prepare()123 assert 'Content-Length' not in get_req.headers124 head_req = requests.Request('HEAD', httpbin('head')).prepare()125 assert 'Content-Length' not in head_req.headers126127 def test_override_content_length(self):127 def test_override_content_length(self, httpbin):128 headers = {129 'Content-Length': 'not zero'130 }131 r = requests.Request('POST', httpbin('post'), headers=headers).prepare()
24 unmodified lines
156 request = requests.Request('GET', 'http://example.com',157 params=b'test=foo').prepare()158 assert request.url == 'http://example.com/?test=foo'159160 def test_mixed_case_scheme_acceptable(self):160 def test_mixed_case_scheme_acceptable(self, httpbin):161 s = requests.Session()162 s.proxies = getproxies()163 parts = urlparse(httpbin('get'))164 schemes = ['http://', 'HTTP://', 'hTTp://', 'HttP://']
2 unmodified lines
167 r = requests.Request('GET', url)168 r = s.send(r.prepare())169 assert r.status_code == 200, 'failed for scheme {0}'.format(scheme)170171 def test_HTTP_200_OK_GET_ALTERNATIVE(self):171 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):172 r = requests.Request('GET', httpbin('get'))173 s = requests.Session()174 s.proxies = getproxies()175176 r = s.send(r.prepare())177178 assert r.status_code == 200179180 def test_HTTP_302_ALLOW_REDIRECT_GET(self):180 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):181 r = requests.get(httpbin('redirect', '1'))182 assert r.status_code == 200183 assert r.history[0].status_code == 302184 assert r.history[0].is_redirect
1 unmodified line
186 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):187 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})188 # self.assertEqual(r.status_code, 200)189190 def test_HTTP_200_OK_GET_WITH_PARAMS(self):190 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):191 heads = {'User-agent': 'Mozilla/5.0'}192193 r = requests.get(httpbin('user-agent'), headers=heads)194195 assert heads['User-agent'] in r.text196 assert r.status_code == 200197198 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):198 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):199 heads = {'User-agent': 'Mozilla/5.0'}200201 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)202 assert r.status_code == 200203204 def test_set_cookie_on_301(self):204 def test_set_cookie_on_301(self, httpbin):205 s = requests.session()206 url = httpbin('cookies/set?foo=bar')207 s.get(url)208 assert s.cookies['foo'] == 'bar'209210 def test_cookie_sent_on_redirect(self):210 def test_cookie_sent_on_redirect(self, httpbin):211 s = requests.session()212 s.get(httpbin('cookies/set?foo=bar'))213 r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')214 assert 'Cookie' in r.json()['headers']215216 def test_cookie_removed_on_expire(self):216 def test_cookie_removed_on_expire(self, httpbin):217 s = requests.session()218 s.get(httpbin('cookies/set?foo=bar'))219 assert s.cookies['foo'] == 'bar'220 s.get(
4 unmodified lines
225 }226 )227 assert 'foo' not in s.cookies228229 def test_cookie_quote_wrapped(self):229 def test_cookie_quote_wrapped(self, httpbin):230 s = requests.session()231 s.get(httpbin('cookies/set?foo="bar:baz"'))232 assert s.cookies['foo'] == '"bar:baz"'233234 def test_cookie_persists_via_api(self):234 def test_cookie_persists_via_api(self, httpbin):235 s = requests.session()236 r = s.get(httpbin('redirect/1'), cookies={'foo': 'bar'})237 assert 'foo' in r.request.headers['Cookie']238 assert 'foo' in r.history[0].request.headers['Cookie']239240 def test_request_cookie_overrides_session_cookie(self):240 def test_request_cookie_overrides_session_cookie(self, httpbin):241 s = requests.session()242 s.cookies['foo'] = 'bar'243 r = s.get(httpbin('cookies'), cookies={'foo': 'baz'})244 assert r.json()['cookies']['foo'] == 'baz'245 # Session cookie should not be modified246 assert s.cookies['foo'] == 'bar'247248 def test_request_cookies_not_persisted(self):248 def test_request_cookies_not_persisted(self, httpbin):249 s = requests.session()250 s.get(httpbin('cookies'), cookies={'foo': 'baz'})251 # Sending a request with cookies should not add cookies to the session252 assert not s.cookies253254 def test_generic_cookiejar_works(self):254 def test_generic_cookiejar_works(self, httpbin):255 cj = cookielib.CookieJar()256 cookiejar_from_dict({'foo': 'bar'}, cj)257 s = requests.session()258 s.cookies = cj
2 unmodified lines
261 assert r.json()['cookies']['foo'] == 'bar'262 # Make sure the session cj is still the custom one263 assert s.cookies is cj264265 def test_param_cookiejar_works(self):265 def test_param_cookiejar_works(self, httpbin):266 cj = cookielib.CookieJar()267 cookiejar_from_dict({'foo': 'bar'}, cj)268 s = requests.session()269 r = s.get(httpbin('cookies'), cookies=cj)270 # Make sure the cookie was sent271 assert r.json()['cookies']['foo'] == 'bar'272273 def test_requests_in_history_are_not_overridden(self):273 def test_requests_in_history_are_not_overridden(self, httpbin):274 resp = requests.get(httpbin('redirect/3'))275 urls = [r.url for r in resp.history]276 req_urls = [r.request.url for r in resp.history]277 assert urls == req_urls278279 def test_history_is_always_a_list(self):279 def test_history_is_always_a_list(self, httpbin):280 """281 Show that even with redirects, Response.history is always a list.282 """283 resp = requests.get(httpbin('get'))
1 unmodified line
285 resp = requests.get(httpbin('redirect/1'))286 assert isinstance(resp.history, list)287 assert not isinstance(resp.history, tuple)288289 def test_headers_on_session_with_None_are_not_sent(self):289 def test_headers_on_session_with_None_are_not_sent(self, httpbin):290 """Do not send headers in Session.headers with None values."""291 ses = requests.Session()292 ses.headers['Accept-Encoding'] = None293 req = requests.Request('GET', httpbin('get'))294 prep = ses.prepare_request(req)295 assert 'Accept-Encoding' not in prep.headers296297 def test_user_agent_transfers(self):297 def test_user_agent_transfers(self, httpbin):298299 heads = {300 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'301 }
7 unmodified lines
309310 r = requests.get(httpbin('user-agent'), headers=heads)311 assert heads['user-agent'] in r.text312313 def test_HTTP_200_OK_HEAD(self):313 def test_HTTP_200_OK_HEAD(self, httpbin):314 r = requests.head(httpbin('get'))315 assert r.status_code == 200316317 def test_HTTP_200_OK_PUT(self):317 def test_HTTP_200_OK_PUT(self, httpbin):318 r = requests.put(httpbin('put'))319 assert r.status_code == 200320321 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):321 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):322 auth = ('user', 'pass')323 url = httpbin('basic-auth', 'user', 'pass')324325 r = requests.get(url, auth=auth)
21 unmodified lines
347 """Inputing a URL that cannot be parsed should raise an InvalidURL error"""348 with pytest.raises(InvalidURL):349 requests.get("http://fe80::5054:ff:fe5a:fc0")350351 def test_basicauth_with_netrc(self):351 def test_basicauth_with_netrc(self, httpbin):352 auth = ('user', 'pass')353 wrong_auth = ('wronguser', 'wrongpass')354 url = httpbin('basic-auth', 'user', 'pass')355
24 unmodified lines
380 assert r.status_code == 401381 finally:382 requests.sessions.get_netrc_auth = old_auth383384 def test_DIGEST_HTTP_200_OK_GET(self):384 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):385386 auth = HTTPDigestAuth('user', 'pass')387 url = httpbin('digest-auth', 'auth', 'user', 'pass')388
7 unmodified lines
396 s.auth = HTTPDigestAuth('user', 'pass')397 r = s.get(url)398 assert r.status_code == 200399400 def test_DIGEST_AUTH_RETURNS_COOKIE(self):400 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):401 url = httpbin('digest-auth', 'auth', 'user', 'pass')402 auth = HTTPDigestAuth('user', 'pass')403 r = requests.get(url)404 assert r.cookies['fake'] == 'fake_value'405406 r = requests.get(url, auth=auth)407 assert r.status_code == 200408409 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self):409 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):410 url = httpbin('digest-auth', 'auth', 'user', 'pass')411 auth = HTTPDigestAuth('user', 'pass')412 s = requests.Session()413 s.get(url, auth=auth)414 assert s.cookies['fake'] == 'fake_value'415416 def test_DIGEST_STREAM(self):416 def test_DIGEST_STREAM(self, httpbin):417418 auth = HTTPDigestAuth('user', 'pass')419 url = httpbin('digest-auth', 'auth', 'user', 'pass')420
2 unmodified lines
423424 r = requests.get(url, auth=auth, stream=False)425 assert r.raw.read() == b''426427 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):427 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):428429 auth = HTTPDigestAuth('user', 'wrongpass')430 url = httpbin('digest-auth', 'auth', 'user', 'pass')431
7 unmodified lines
439 s.auth = auth440 r = s.get(url)441 assert r.status_code == 401442443 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self):443 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):444445 auth = HTTPDigestAuth('user', 'pass')446 url = httpbin('digest-auth', 'auth', 'user', 'pass')447448 r = requests.get(url, auth=auth)449 assert '"auth"' in r.request.headers['Authorization']450451 def test_DIGESTAUTH_THREADED(self):451 def test_DIGESTAUTH_THREADED(self, httpbin):452453 auth = HTTPDigestAuth('user', 'pass')454 url = httpbin('digest-auth', 'auth', 'user', 'pass')455 session = requests.Session()
6 unmodified lines
462 if ThreadPool is not None:463 pool = ThreadPool(processes=50)464 pool.map(do_request, range(100))465466 def test_POSTBIN_GET_POST_FILES(self):466 def test_POSTBIN_GET_POST_FILES(self, httpbin):467468 url = httpbin('post')469 post1 = requests.post(url).raise_for_status()470
9 unmodified lines
480481 with pytest.raises(ValueError):482 requests.post(url, files=['bad file data'])483484 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):484 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):485486 url = httpbin('post')487 post1 = requests.post(url).raise_for_status()488
10 unmodified lines
499500 with pytest.raises(ValueError):501 requests.post(url, files=['bad file data'])502503 def test_conflicting_post_params(self):503 def test_conflicting_post_params(self, httpbin):504 url = httpbin('post')505 with open('requirements.txt') as f:506 pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")507 pytest.raises(ValueError, "requests.post(url, data=u('[{\"some\": \"data\"}]'), files={'some': f})")508509 def test_request_ok_set(self):509 def test_request_ok_set(self, httpbin):510 r = requests.get(httpbin('status', '404'))511 assert not r.ok512513 def test_status_raising(self):513 def test_status_raising(self, httpbin):514 r = requests.get(httpbin('status', '404'))515 with pytest.raises(requests.exceptions.HTTPError):516 r.raise_for_status()517518 r = requests.get(httpbin('status', '500'))519 assert not r.ok520521 def test_decompress_gzip(self):521 def test_decompress_gzip(self, httpbin):522 r = requests.get(httpbin('gzip'))523 r.content.decode('ascii')524525 def test_unicode_get(self):525 def test_unicode_get(self, httpbin):526 url = httpbin('/get')527 requests.get(url, params={'foo': 'føø'})528 requests.get(url, params={'føø': 'føø'})529 requests.get(url, params={'føø': 'føø'})530 requests.get(url, params={'foo': 'foo'})531 requests.get(httpbin('ø'), params={'foo': 'foo'})532533 def test_unicode_header_name(self):533 def test_unicode_header_name(self, httpbin):534 requests.put(535 httpbin('put'),536 headers={str('Content-Type'): 'application/octet-stream'},537 data='\xff') # compat.str is unicode.538539 def test_pyopenssl_redirect(self):540 requests.get('https://httpbin.org/status/301')539 def test_pyopenssl_redirect(self, httpsbin_url, httpbin_ca_bundle):540 requests.get(httpsbin_url('status', '301'), verify=httpbin_ca_bundle)541542 def test_urlencoded_get_query_multivalued_param(self):542 def test_urlencoded_get_query_multivalued_param(self, httpbin):543544 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))545 assert r.status_code == 200546 assert r.url == httpbin('get?test=foo&test=baz')547548 def test_different_encodings_dont_break_post(self):548 def test_different_encodings_dont_break_post(self, httpbin):549 r = requests.post(httpbin('post'),550 data={'stuff': json.dumps({'a': 123})},551 params={'blah': 'asdf1234'},552 files={'file': ('test_requests.py', open(__file__, 'rb'))})553 assert r.status_code == 200554555 def test_unicode_multipart_post(self):555 def test_unicode_multipart_post(self, httpbin):556 r = requests.post(httpbin('post'),557 data={'stuff': u('ëlïxr')},558 files={'file': ('test_requests.py', open(__file__, 'rb'))})559 assert r.status_code == 200
12 unmodified lines
572 data={'stuff': 'elixr'.encode('utf-8')},573 files={'file': ('test_requests.py', open(__file__, 'rb'))})574 assert r.status_code == 200575576 def test_unicode_multipart_post_fieldnames(self):576 def test_unicode_multipart_post_fieldnames(self, httpbin):577 filename = os.path.splitext(__file__)[0] + '.py'578 r = requests.Request(method='POST',579 url=httpbin('post'),580 data={'stuff'.encode('utf-8'): 'elixr'},
2 unmodified lines
583 prep = r.prepare()584 assert b'name="stuff"' in prep.body585 assert b'name="b\'stuff\'"' not in prep.body586587 def test_unicode_method_name(self):587 def test_unicode_method_name(self, httpbin):588 files = {'file': open('test_requests.py', 'rb')}589 r = requests.request(590 method=u('POST'), url=httpbin('post'), files=files)591 assert r.status_code == 200592593 def test_unicode_method_name_with_request_object(self):593 def test_unicode_method_name_with_request_object(self, httpbin):594 files = {'file': open('test_requests.py', 'rb')}595 s = requests.Session()596 req = requests.Request(u("POST"), httpbin('post'), files=files)597 prep = s.prepare_request(req)
2 unmodified lines
600601 resp = s.send(prep)602 assert resp.status_code == 200603604 def test_custom_content_type(self):604 def test_custom_content_type(self, httpbin):605 r = requests.post(606 httpbin('post'),607 data={'stuff': json.dumps({'a': 123})},608 files={'file1': ('test_requests.py', open(__file__, 'rb')),
1 unmodified line
610 'text/py-content-type')})611 assert r.status_code == 200612 assert b"text/py-content-type" in r.request.body613614 def test_hook_receives_request_arguments(self):614 def test_hook_receives_request_arguments(self, httpbin):615 def hook(resp, **kwargs):616 assert resp is not None617 assert kwargs != {}618619 requests.Request('GET', HTTPBIN, hooks={'response': hook})619 requests.Request('GET', httpbin(), hooks={'response': hook})620621 def test_session_hooks_are_used_with_no_request_hooks(self):621 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):622 hook = lambda x, *args, **kwargs: x623 s = requests.Session()624 s.hooks['response'].append(hook)625 r = requests.Request('GET', HTTPBIN)625 r = requests.Request('GET', httpbin())626 prep = s.prepare_request(r)627 assert prep.hooks['response'] != []628 assert prep.hooks['response'] == [hook]629630 def test_session_hooks_are_overriden_by_request_hooks(self):630 def test_session_hooks_are_overriden_by_request_hooks(self, httpbin):631 hook1 = lambda x, *args, **kwargs: x632 hook2 = lambda x, *args, **kwargs: x633 assert hook1 is not hook2634 s = requests.Session()635 s.hooks['response'].append(hook2)636 r = requests.Request('GET', HTTPBIN, hooks={'response': [hook1]})636 r = requests.Request('GET', httpbin(), hooks={'response': [hook1]})637 prep = s.prepare_request(r)638 assert prep.hooks['response'] == [hook1]639640 def test_prepared_request_hook(self):640 def test_prepared_request_hook(self, httpbin):641 def hook(resp, **kwargs):642 resp.hook_working = True643 return resp644645 req = requests.Request('GET', HTTPBIN, hooks={'response': hook})645 req = requests.Request('GET', httpbin(), hooks={'response': hook})646 prep = req.prepare()647648 s = requests.Session()649 s.proxies = getproxies()650 resp = s.send(prep)651652 assert hasattr(resp, 'hook_working')653654 def test_prepared_from_session(self):654 def test_prepared_from_session(self, httpbin):655 class DummyAuth(requests.auth.AuthBase):656 def __call__(self, r):657 r.headers['Dummy-Auth-Test'] = 'dummy-auth-test-ok'658 return r
144 unmodified lines
803 assert items == list(items)804 # make sure one can use items multiple times805 assert list(items) == list(items)806807 def test_time_elapsed_blank(self):807 def test_time_elapsed_blank(self, httpbin):808 r = requests.get(httpbin('get'))809 td = r.elapsed810 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)811 * 10**6) / 10**6)
30 unmodified lines
842 r.encoding = 'ascii'843 chunks = r.iter_content(decode_unicode=True)844 assert all(isinstance(chunk, str) for chunk in chunks)845846 def test_request_and_response_are_pickleable(self):846 def test_request_and_response_are_pickleable(self, httpbin):847 r = requests.get(httpbin('get'))848849 # verify we can pickle the original request850 assert pickle.loads(pickle.dumps(r.request))
23 unmodified lines
874 def test_get_auth_from_url_encoded_hashes(self):875 url = 'http://user:pass%23pass@complex.url.com/path?query=yes'876 assert ('user', 'pass#pass') == requests.utils.get_auth_from_url(url)877878 def test_cannot_send_unprepared_requests(self):879 r = requests.Request(url=HTTPBIN)878 def test_cannot_send_unprepared_requests(self, httpbin):879 r = requests.Request(url=httpbin())880 with pytest.raises(ValueError):881 requests.Session().send(r)882883 def test_http_error(self):
5 unmodified lines
889 error = requests.exceptions.HTTPError('message', response=response)890 assert str(error) == 'message'891 assert error.response == response892893 def test_session_pickling(self):893 def test_session_pickling(self, httpbin):894 r = requests.Request('GET', httpbin('get'))895 s = requests.Session()896897 s = pickle.loads(pickle.dumps(s))
1 unmodified line
899900 r = s.send(r.prepare())901 assert r.status_code == 200902903 def test_fixes_1329(self):903 def test_fixes_1329(self, httpbin):904 """905 Ensure that header updates are done case-insensitively.906 """907 s = requests.Session()
4 unmodified lines
912 assert headers['accept'] == 'application/json'913 assert headers['Accept'] == 'application/json'914 assert headers['ACCEPT'] == 'application/json'915916 def test_uppercase_scheme_redirect(self):916 def test_uppercase_scheme_redirect(self, httpbin):917 parts = urlparse(httpbin('html'))918 url = "HTTP://" + parts.netloc + parts.path919 r = requests.get(httpbin('redirect-to'), params={'url': url})920 assert r.status_code == 200
36 unmodified lines
957 s2.mount('https://', HTTPAdapter())958 assert 'http://' in s2.adapters959 assert 'https://' in s2.adapters960961 def test_header_remove_is_case_insensitive(self):961 def test_header_remove_is_case_insensitive(self, httpbin):962 # From issue #1321963 s = requests.Session()964 s.headers['foo'] = 'bar'965 r = s.get(httpbin('get'), headers={'FOO': None})966 assert 'foo' not in r.request.headers967968 def test_params_are_merged_case_sensitive(self):968 def test_params_are_merged_case_sensitive(self, httpbin):969 s = requests.Session()970 s.params['foo'] = 'bar'971 r = s.get(httpbin('get'), params={'FOO': 'bar'})972 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}
6 unmodified lines
979 )980 r = requests.Request('GET', url).prepare()981 assert r.url == url982983 def test_header_keys_are_native(self):983 def test_header_keys_are_native(self, httpbin):984 headers = {u('unicode'): 'blah', 'byte'.encode('ascii'): 'blah'}985 r = requests.Request('GET', httpbin('get'), headers=headers)986 p = r.prepare()987
1 unmodified line
989 # we go.990 assert 'unicode' in p.headers.keys()991 assert 'byte' in p.headers.keys()992993 def test_can_send_nonstring_objects_with_files(self):993 def test_can_send_nonstring_objects_with_files(self, httpbin):994 data = {'a': 0.0}995 files = {'b': 'foo'}996 r = requests.Request('POST', httpbin('post'), data=data, files=files)997 p = r.prepare()998999 assert 'multipart/form-data' in p.headers['Content-Type']10001001 def test_can_send_bytes_bytearray_objects_with_files(self):1001 def test_can_send_bytes_bytearray_objects_with_files(self, httpbin):1002 # Test bytes:1003 data = {'a': 'this is a string'}1004 files = {'b': b'foo'}1005 r = requests.Request('POST', httpbin('post'), data=data, files=files)
4 unmodified lines
1010 r = requests.Request('POST', httpbin('post'), data=data, files=files)1011 p = r.prepare()1012 assert 'multipart/form-data' in p.headers['Content-Type']10131014 def test_can_send_file_object_with_non_string_filename(self):1014 def test_can_send_file_object_with_non_string_filename(self, httpbin):1015 f = io.BytesIO()1016 f.name = 21017 r = requests.Request('POST', httpbin('post'), files={'f': f})1018 p = r.prepare()10191020 assert 'multipart/form-data' in p.headers['Content-Type']10211022 def test_autoset_header_values_are_native(self):1022 def test_autoset_header_values_are_native(self, httpbin):1023 data = 'this is a string'1024 length = '16'1025 req = requests.Request('POST', httpbin('post'), data=data)1026 p = req.prepare()
10 unmodified lines
1037 req = requests.Request('GET', test_url)1038 preq = req.prepare()1039 assert test_url == preq.url10401041 def test_auth_is_stripped_on_redirect_off_host(self):1041 def test_auth_is_stripped_on_redirect_off_host(self, httpbin):1042 r = requests.get(1043 httpbin('redirect-to'),1044 params={'url': 'http://www.google.co.uk'},1045 auth=('user', 'pass'),1046 )1047 assert r.history[0].request.headers['Authorization']1048 assert not r.request.headers.get('Authorization', '')10491050 def test_auth_is_retained_for_redirect_on_host(self):1050 def test_auth_is_retained_for_redirect_on_host(self, httpbin):1051 r = requests.get(httpbin('redirect/1'), auth=('user', 'pass'))1052 h1 = r.history[0].request.headers['Authorization']1053 h2 = r.request.headers['Authorization']10541055 assert h1 == h210561057 def test_manual_redirect_with_partial_body_read(self):1057 def test_manual_redirect_with_partial_body_read(self, httpbin):1058 s = requests.Session()1059 r1 = s.get(httpbin('redirect/2'), allow_redirects=False, stream=True)1060 assert r1.is_redirect1061 rg = s.resolve_redirects(r1, r1.request, stream=True)
24 unmodified lines
1086 return resp10871088 adapter.build_response = build_response10891090 def test_redirect_with_wrong_gzipped_header(self):1090 def test_redirect_with_wrong_gzipped_header(self, httpbin):1091 s = requests.Session()1092 url = httpbin('redirect/1')1093 self._patch_adapter_gzipped_redirect(s, url)1094 s.get(url)
2 unmodified lines
1097 s = _basic_auth_str("test", "test")1098 assert isinstance(s, builtin_str)1099 assert s == "Basic dGVzdDp0ZXN0"11001101 def test_requests_history_is_saved(self):1101 def test_requests_history_is_saved(self, httpbin):1102 r = requests.get(httpbin('redirect/5'))1103 total = r.history[-1].history1104 i = 01105 for item in r.history:1106 assert item.history == total[0:i]1107 i = i + 111081109 def test_json_param_post_content_type_works(self):1109 def test_json_param_post_content_type_works(self, httpbin):1110 r = requests.post(1111 httpbin('post'),1112 json={'life': 42}1113 )1114 assert r.status_code == 2001115 assert 'application/json' in r.request.headers['Content-Type']1116 assert {'life': 42} == r.json()['json']11171118 def test_json_param_post_should_not_override_data_param(self):1119 r = requests.Request(method='POST', url='http://httpbin.org/post',1118 def test_json_param_post_should_not_override_data_param(self, httpbin):1119 r = requests.Request(method='POST', url=httpbin('post'),1120 data={'stuff': 'elixr'},1121 json={'music': 'flute'})1122 prep = r.prepare()1123 assert 'stuff=elixr' == prep.body11241125 def test_response_iter_lines(self):1125 def test_response_iter_lines(self, httpbin):1126 r = requests.get(httpbin('stream/4'), stream=True)1127 assert r.status_code == 20011281129 it = r.iter_lines()1130 next(it)1131 assert len(list(it)) == 311321133 def test_unconsumed_session_response_closes_connection(self):1133 def test_unconsumed_session_response_closes_connection(self, httpbin):1134 s = requests.session()11351136 with contextlib.closing(s.get(httpbin('stream/4'), stream=True)) as response:1137 pass
1 unmodified line
1139 self.assertFalse(response._content_consumed)1140 self.assertTrue(response.raw.closed)11411142 @pytest.mark.xfail1143 def test_response_iter_lines_reentrant(self):1143 def test_response_iter_lines_reentrant(self, httpbin):1144 """Response.iter_lines() is not reentrant safe"""1145 r = requests.get(httpbin('stream/4'), stream=True)1146 assert r.status_code == 2001147
385 unmodified lines
1533 morsel_to_cookie(morsel)153415351536class TestTimeout:1537 def test_stream_timeout(self):1537 def test_stream_timeout(self, httpbin):1538 try:1539 requests.get(httpbin('delay/10'), timeout=2.0)1540 except requests.exceptions.Timeout as e:1541 assert 'Read timed out' in e.args[0].args[0]15421543 def test_invalid_timeout(self):1543 def test_invalid_timeout(self, httpbin):1544 with pytest.raises(ValueError) as e:1545 requests.get(httpbin('get'), timeout=(3, 4, 5))1546 assert '(connect, read)' in str(e)15471548 with pytest.raises(ValueError) as e:1549 requests.get(httpbin('get'), timeout="foo")1550 assert 'must be an int or float' in str(e)15511552 def test_none_timeout(self):1552 def test_none_timeout(self, httpbin):1553 """ Check that you can set None as a valid timeout value.15541555 To actually test this behavior, we'd want to check that setting the1556 timeout to None actually lets the request block past the system default
3 unmodified lines
1560 """1561 r = requests.get(httpbin('get'), timeout=None)1562 assert r.status_code == 20015631564 def test_read_timeout(self):1564 def test_read_timeout(self, httpbin):1565 try:1566 requests.get(httpbin('delay/10'), timeout=(None, 0.1))1567 assert False, "The recv() request should time out."1568 except ReadTimeout:
13 unmodified lines
1582 assert False, "The connect() request should time out."1583 except ConnectTimeout:1584 pass15851586 def test_encoded_methods(self):1586 def test_encoded_methods(self, httpbin):1587 """See: https://github.com/kennethreitz/requests/issues/2316"""1588 r = requests.request(b'GET', httpbin('get'))1589 assert r.ok1590
42 unmodified lines
1633 'allow_redirects': False,1634 'proxies': {},1635 }16361637 def test_requests_are_updated_each_time(self):1637 def test_requests_are_updated_each_time(self, httpbin):1638 session = RedirectSession([303, 307])1639 prep = requests.Request('POST', httpbin('post')).prepare()1640 r0 = session.send(prep)1641 assert r0.request.method == 'POST'
73 unmodified lines
1715 )1716 assert_copy(p, p.copy())171717181719def test_urllib3_retries():1719def test_urllib3_retries(httpbin):1720 from requests.packages.urllib3.util import Retry1721 s = requests.Session()1722 s.mount('http://', HTTPAdapter(max_retries=Retry(1723 total=2, status_forcelist=[500]
2 unmodified lines
1726 with pytest.raises(RetryError):1727 s.get(httpbin('status/500'))172817291730def test_urllib3_pool_connection_closed():1730def test_urllib3_pool_connection_closed(httpbin):1731 s = requests.Session()1732 s.mount('http://', HTTPAdapter(pool_connections=0, pool_maxsize=0))17331734 try:
13 unmodified lines