test_requests.py
This file
Path
tests/test_requests.py
2,983 lines · 102.1 KiB · Python
Last changed by
Merge pull request #6757 from nateprewitt/urllib-1.x-testsNate Prewittbefore adoption79b74ef
History of this fileTake it
The walk stopped after 200 commits: lines older than 9cd2d33 point at it.
Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1why, one step back1"""Tests for Requests."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 2why, one step back2Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 3–5why, one step back3import collections4import contextlib5import ioAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 6–9why, one step back6import json7import os8import pickle9import reMerge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a
line 10why, one step back10import threadingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 11why, one step back11import warningsRemove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 12why, one step back12from unittest import mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 13why, one step back13Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 14why, one step back14import pytestWrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 15why, one step back15import urllib3Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 16why, one step back16from urllib3.util import Timeout as Urllib3TimeoutAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 17–27why, one step back1718import requests19from requests.adapters import HTTPAdapter20from requests.auth import HTTPDigestAuth, _basic_auth_str21from requests.compat import (22 JSONDecodeError,23 Morsel,24 MutableMapping,25 builtin_str,26 cookielib,27 getproxies,Merge pull request #6757 from nateprewitt/urllib-1.x-testsNate Prewittbefore adoption79b74ef
line 28why, one step back28 is_urllib3_1,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 29–53why, one step back29 urlparse,30)31from requests.cookies import cookiejar_from_dict, morsel_to_cookie32from requests.exceptions import (33 ChunkedEncodingError,34 ConnectionError,35 ConnectTimeout,36 ContentDecodingError,37 InvalidHeader,38 InvalidProxyURL,39 InvalidSchema,40 InvalidURL,41 MissingSchema,42 ProxyError,43 ReadTimeout,44 RequestException,45 RetryError,46)47from requests.exceptions import SSLError as RequestsSSLError48from requests.exceptions import Timeout, TooManyRedirects, UnrewindableBodyError49from requests.hooks import default_hooks50from requests.models import PreparedRequest, urlencode51from requests.sessions import SessionRedirectMixin52from requests.structures import CaseInsensitiveDict53Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
line 54why, one step back54from . import SNIMissingWarningAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 55why, one step back55from .compat import StringIOMerge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a
line 56why, one step back56from .testserver.server import TLSServer, consume_socket_contentAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 57–58why, one step back57from .utils import override_environ58Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 59–60why, one step back59# Requests to this URL should always fail with a connection timeout (nothing60# listening on that port)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 61–62why, one step back61TARPIT = "http://10.255.255.1"62Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 63why, one step back63# This is to avoid waiting the timeout of using TARPITAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 64–66why, one step back64INVALID_PROXY = "http://localhost:1"6566try:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 67why, one step back67 from ssl import SSLContextAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 68why, one step back68Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 69–72why, one step back69 del SSLContext70 HAS_MODERN_SSL = True71except ImportError:72 HAS_MODERN_SSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 73–74why, one step back7374try:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 75–78why, one step back75 requests.pyopenssl76 HAS_PYOPENSSL = True77except AttributeError:78 HAS_PYOPENSSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 79–80why, one step back7980Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 81why, one step back81class TestRequests:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 82–83why, one step back82 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")83Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 84–93why, one step back84 def test_entry_points(self):85 requests.session86 requests.session().get87 requests.session().head88 requests.get89 requests.head90 requests.put91 requests.patch92 requests.post93 # Not really an entry point, but people rely on it.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 94–107why, one step back94 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F4019596 @pytest.mark.parametrize(97 "exception, url",98 (99 (MissingSchema, "hiwpefhipowhefopw"),100 (InvalidSchema, "localhost:3128"),101 (InvalidSchema, "localhost.localdomain:3128/"),102 (InvalidSchema, "10.122.1.1:3128/"),103 (InvalidURL, "http://"),104 (InvalidURL, "http://*example.com"),105 (InvalidURL, "http://.example.com"),106 ),107 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 108why, one step back108 def test_invalid_url(self, exception, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 109why, one step back109 with pytest.raises(exception):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 110why, one step back110 requests.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 111why, one step back111Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 112–113why, one step back112 def test_basic_building(self):113 req = requests.Request()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 114–116why, one step back114 req.url = "http://kennethreitz.org/"115 req.data = {"life": "42"}116Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 117–118why, one step back117 pr = req.prepare()118 assert pr.url == req.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 119–121why, one step back119 assert pr.body == "life=42"120121 @pytest.mark.parametrize("method", ("GET", "HEAD"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 122why, one step back122 def test_no_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 123–126why, one step back123 req = requests.Request(method, httpbin(method.lower())).prepare()124 assert "Content-Length" not in req.headers125126 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 127why, one step back127 def test_no_body_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 128–131why, one step back128 req = requests.Request(method, httpbin(method.lower())).prepare()129 assert req.headers["Content-Length"] == "0"130131 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 132why, one step back132 def test_empty_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 133–135why, one step back133 req = requests.Request(method, httpbin(method.lower()), data="").prepare()134 assert req.headers["Content-Length"] == "0"135Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 136why, one step back136 def test_override_content_length(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 137–141why, one step back137 headers = {"Content-Length": "not zero"}138 r = requests.Request("POST", httpbin("post"), headers=headers).prepare()139 assert "Content-Length" in r.headers140 assert r.headers["Content-Length"] == "not zero"141Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 142why, one step back142 def test_path_is_not_double_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 143–159why, one step back143 request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()144145 assert request.path_url == "/get/test%20case"146147 @pytest.mark.parametrize(148 "url, expected",149 (150 (151 "http://example.com/path#fragment",152 "http://example.com/path?a=b#fragment",153 ),154 (155 "http://example.com/path?key=value#fragment",156 "http://example.com/path?key=value&a=b#fragment",157 ),158 ),159 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 160why, one step back160 def test_params_are_added_before_fragment(self, url, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 161why, one step back161 request = requests.Request("GET", url, params={"a": "b"}).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 162why, one step back162 assert request.url == expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 163why, one step back163Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 164why, one step back164 def test_params_original_order_is_preserved_by_default(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 165–171why, one step back165 param_ordered_dict = collections.OrderedDict(166 (("z", 1), ("a", 1), ("k", 1), ("d", 1))167 )168 session = requests.Session()169 request = requests.Request(170 "GET", "http://example.com/", params=param_ordered_dict171 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 172why, one step back172 prep = session.prepare_request(request)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 173–174why, one step back173 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"174Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 175why, one step back175 def test_params_bytes_are_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 176–180why, one step back176 request = requests.Request(177 "GET", "http://example.com", params=b"test=foo"178 ).prepare()179 assert request.url == "http://example.com/?test=foo"180Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 181why, one step back181 def test_binary_put(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 182–184why, one step back182 request = requests.Request(183 "PUT", "http://example.com", data="ööö".encode()184 ).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 185why, one step back185 assert isinstance(request.body, bytes)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 186why, one step back186Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 187–188why, one step back187 def test_whitespaces_are_removed_from_url(self):188 # Test for issue #3696Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 189–192why, one step back189 request = requests.Request("GET", " http://example.com").prepare()190 assert request.url == "http://example.com/"191192 @pytest.mark.parametrize("scheme", ("http://", "HTTP://", "hTTp://", "HttP://"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 193why, one step back193 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 194–196why, one step back194 s = requests.Session()195 s.proxies = getproxies()196 parts = urlparse(httpbin("get"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 197why, one step back197 url = scheme + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 198–201why, one step back198 r = requests.Request("GET", url)199 r = s.send(r.prepare())200 assert r.status_code == 200, f"failed for scheme {scheme}"201Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 202why, one step back202 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 203–210why, one step back203 r = requests.Request("GET", httpbin("get"))204 s = requests.Session()205 s.proxies = getproxies()206207 r = s.send(r.prepare())208209 assert r.status_code == 200210Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 211why, one step back211 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 212–216why, one step back212 r = requests.get(httpbin("redirect", "1"))213 assert r.status_code == 200214 assert r.history[0].status_code == 302215 assert r.history[0].is_redirect216Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 217why, one step back217 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 218–227why, one step back218 r = requests.post(219 httpbin("redirect-to"),220 data="test",221 params={"url": "post", "status_code": 307},222 )223 assert r.status_code == 200224 assert r.history[0].status_code == 307225 assert r.history[0].is_redirect226 assert r.json()["data"] == "test"227Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 228why, one step back228 def test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 229–239why, one step back229 byte_str = b"test"230 r = requests.post(231 httpbin("redirect-to"),232 data=io.BytesIO(byte_str),233 params={"url": "post", "status_code": 307},234 )235 assert r.status_code == 200236 assert r.history[0].status_code == 307237 assert r.history[0].is_redirect238 assert r.json()["data"] == byte_str.decode("utf-8")239Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 240why, one step back240 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 241–246why, one step back241 try:242 requests.get(httpbin("relative-redirect", "50"))243 except TooManyRedirects as e:244 url = httpbin("relative-redirect", "20")245 assert e.request.url == url246 assert e.response.url == urlMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 247why, one step back247 assert len(e.response.history) == 30Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 248–250why, one step back248 else:249 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")250Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 251why, one step back251 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 252why, one step back252 s = requests.session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 253why, one step back253 s.max_redirects = 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 254–259why, one step back254 try:255 s.get(httpbin("relative-redirect", "50"))256 except TooManyRedirects as e:257 url = httpbin("relative-redirect", "45")258 assert e.request.url == url259 assert e.response.url == urlMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 260why, one step back260 assert len(e.response.history) == 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 261–265why, one step back261 else:262 pytest.fail(263 "Expected custom max number of redirects to be respected but was not"264 )265Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 266why, one step back266 def test_http_301_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 267–272why, one step back267 r = requests.post(httpbin("status", "301"))268 assert r.status_code == 200269 assert r.request.method == "GET"270 assert r.history[0].status_code == 301271 assert r.history[0].is_redirect272Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 273why, one step back273 def test_http_301_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 274why, one step back274 r = requests.head(httpbin("status", "301"), allow_redirects=True)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 275why, one step back275 print(r.content)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 276–280why, one step back276 assert r.status_code == 200277 assert r.request.method == "HEAD"278 assert r.history[0].status_code == 301279 assert r.history[0].is_redirect280Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 281why, one step back281 def test_http_302_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 282–287why, one step back282 r = requests.post(httpbin("status", "302"))283 assert r.status_code == 200284 assert r.request.method == "GET"285 assert r.history[0].status_code == 302286 assert r.history[0].is_redirect287Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 288why, one step back288 def test_http_302_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 289–294why, one step back289 r = requests.head(httpbin("status", "302"), allow_redirects=True)290 assert r.status_code == 200291 assert r.request.method == "HEAD"292 assert r.history[0].status_code == 302293 assert r.history[0].is_redirect294Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 295why, one step back295 def test_http_303_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 296–301why, one step back296 r = requests.post(httpbin("status", "303"))297 assert r.status_code == 200298 assert r.request.method == "GET"299 assert r.history[0].status_code == 303300 assert r.history[0].is_redirect301Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 302why, one step back302 def test_http_303_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 303–308why, one step back303 r = requests.head(httpbin("status", "303"), allow_redirects=True)304 assert r.status_code == 200305 assert r.request.method == "HEAD"306 assert r.history[0].status_code == 303307 assert r.history[0].is_redirect308Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 309why, one step back309 def test_header_and_body_removal_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 310–313why, one step back310 purged_headers = ("Content-Length", "Content-Type")311 ses = requests.Session()312 req = requests.Request("POST", httpbin("post"), data={"test": "data"})313 prep = ses.prepare_request(req)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 314why, one step back314 resp = ses.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 315–319why, one step back315316 # Mimic a redirect response317 resp.status_code = 302318 resp.headers["location"] = "get"319Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 320why, one step back320 # Run request through resolve_redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 321–325why, one step back321 next_resp = next(ses.resolve_redirects(resp, prep))322 assert next_resp.request.body is None323 for header in purged_headers:324 assert header not in next_resp.request.headers325Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 326why, one step back326 def test_transfer_enc_removal_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 327–332why, one step back327 purged_headers = ("Transfer-Encoding", "Content-Type")328 ses = requests.Session()329 req = requests.Request("POST", httpbin("post"), data=(b"x" for x in range(1)))330 prep = ses.prepare_request(req)331 assert "Transfer-Encoding" in prep.headers332Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 333why, one step back333 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 334–335why, one step back334 resp = requests.Response()335 resp.raw = io.BytesIO(b"the content")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 336why, one step back336 resp.request = prepAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 337–342why, one step back337 setattr(resp.raw, "release_conn", lambda *args: args)338339 # Mimic a redirect response340 resp.status_code = 302341 resp.headers["location"] = httpbin("get")342Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 343why, one step back343 # Run request through resolve_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 344–348why, one step back344 next_resp = next(ses.resolve_redirects(resp, prep))345 assert next_resp.request.body is None346 for header in purged_headers:347 assert header not in next_resp.request.headers348Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 349–350why, one step back349 def test_fragment_maintained_on_redirect(self, httpbin):350 fragment = "#view=edit&token=hunter2"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 351–352why, one step back351 r = requests.get(httpbin("redirect-to?url=get") + fragment)352Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 353why, one step back353 assert len(r.history) > 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 354–356why, one step back354 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment355 assert r.url == httpbin("get") + fragment356Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 357why, one step back357 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 358–364why, one step back358 heads = {"User-agent": "Mozilla/5.0"}359360 r = requests.get(httpbin("user-agent"), headers=heads)361362 assert heads["User-agent"] in r.text363 assert r.status_code == 200364Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 365why, one step back365 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 366–372why, one step back366 heads = {"User-agent": "Mozilla/5.0"}367368 r = requests.get(369 httpbin("get") + "?test=true", params={"q": "test"}, headers=heads370 )371 assert r.status_code == 200372Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 373why, one step back373 def test_set_cookie_on_301(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 374–378why, one step back374 s = requests.session()375 url = httpbin("cookies/set?foo=bar")376 s.get(url)377 assert s.cookies["foo"] == "bar"378Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 379why, one step back379 def test_cookie_sent_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 380–384why, one step back380 s = requests.session()381 s.get(httpbin("cookies/set?foo=bar"))382 r = s.get(httpbin("redirect/1")) # redirects to httpbin('get')383 assert "Cookie" in r.json()["headers"]384Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 385why, one step back385 def test_cookie_removed_on_expire(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 386–388why, one step back386 s = requests.session()387 s.get(httpbin("cookies/set?foo=bar"))388 assert s.cookies["foo"] == "bar"Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 389why, one step back389 s.get(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 390–394why, one step back390 httpbin("response-headers"),391 params={"Set-Cookie": "foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT"},392 )393 assert "foo" not in s.cookies394Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 395why, one step back395 def test_cookie_quote_wrapped(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 396why, one step back396 s = requests.session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 397why, one step back397 s.get(httpbin('cookies/set?foo="bar:baz"'))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 398–399why, one step back398 assert s.cookies["foo"] == '"bar:baz"'399Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 400why, one step back400 def test_cookie_persists_via_api(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 401–405why, one step back401 s = requests.session()402 r = s.get(httpbin("redirect/1"), cookies={"foo": "bar"})403 assert "foo" in r.request.headers["Cookie"]404 assert "foo" in r.history[0].request.headers["Cookie"]405Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 406why, one step back406 def test_request_cookie_overrides_session_cookie(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 407–410why, one step back407 s = requests.session()408 s.cookies["foo"] = "bar"409 r = s.get(httpbin("cookies"), cookies={"foo": "baz"})410 assert r.json()["cookies"]["foo"] == "baz"Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 411why, one step back411 # Session cookie should not be modifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 412–413why, one step back412 assert s.cookies["foo"] == "bar"413Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 414why, one step back414 def test_request_cookies_not_persisted(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 415–416why, one step back415 s = requests.session()416 s.get(httpbin("cookies"), cookies={"foo": "baz"})Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 417–418why, one step back417 # Sending a request with cookies should not add cookies to the session418 assert not s.cookiesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 419why, one step back419Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 420why, one step back420 def test_generic_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 421–423why, one step back421 cj = cookielib.CookieJar()422 cookiejar_from_dict({"foo": "bar"}, cj)423 s = requests.session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 424why, one step back424 s.cookies = cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 425–427why, one step back425 r = s.get(httpbin("cookies"))426 # Make sure the cookie was sent427 assert r.json()["cookies"]["foo"] == "bar"Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 428–429why, one step back428 # Make sure the session cj is still the custom one429 assert s.cookies is cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 430why, one step back430Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 431why, one step back431 def test_param_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 432–438why, one step back432 cj = cookielib.CookieJar()433 cookiejar_from_dict({"foo": "bar"}, cj)434 s = requests.session()435 r = s.get(httpbin("cookies"), cookies=cj)436 # Make sure the cookie was sent437 assert r.json()["cookies"]["foo"] == "bar"438Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 439–441why, one step back439 def test_cookielib_cookiejar_on_redirect(self, httpbin):440 """Tests resolve_redirect doesn't fail when merging cookies441 with non-RequestsCookieJar cookiejar.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 442why, one step back442Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 443why, one step back443 See GH #3579Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 444–448why, one step back444 """445 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())446 s = requests.Session()447 s.cookies = cookiejar_from_dict({"cookie": "tasty"})448Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 449why, one step back449 # Prepare request without using SessionAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 450why, one step back450 req = requests.Request("GET", httpbin("headers"), cookies=cj)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 451why, one step back451 prep_req = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 452why, one step back452Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 453–454why, one step back453 # Send request and simulate redirect454 resp = s.send(prep_req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 455–456why, one step back455 resp.status_code = 302456 resp.headers["location"] = httpbin("get")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 457–458why, one step back457 redirects = s.resolve_redirects(resp, prep_req)458 resp = next(redirects)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 459why, one step back459Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 460–463why, one step back460 # Verify CookieJar isn't being converted to RequestsCookieJar461 assert isinstance(prep_req._cookies, cookielib.CookieJar)462 assert isinstance(resp.request._cookies, cookielib.CookieJar)463 assert not isinstance(resp.request._cookies, requests.cookies.RequestsCookieJar)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 464why, one step back464Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 465–467why, one step back465 cookies = {}466 for c in resp.request._cookies:467 cookies[c.name] = c.valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 468–470why, one step back468 assert cookies["foo"] == "bar"469 assert cookies["cookie"] == "tasty"470Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 471why, one step back471 def test_requests_in_history_are_not_overridden(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 472why, one step back472 resp = requests.get(httpbin("redirect/3"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 473–475why, one step back473 urls = [r.url for r in resp.history]474 req_urls = [r.request.url for r in resp.history]475 assert urls == req_urlsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 476why, one step back476Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 477–478why, one step back477 def test_history_is_always_a_list(self, httpbin):478 """Show that even with redirects, Response.history is always a list."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 479–482why, one step back479 resp = requests.get(httpbin("get"))480 assert isinstance(resp.history, list)481 resp = requests.get(httpbin("redirect/1"))482 assert isinstance(resp.history, list)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 483why, one step back483 assert not isinstance(resp.history, tuple)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 484why, one step back484Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 485–486why, one step back485 def test_headers_on_session_with_None_are_not_sent(self, httpbin):486 """Do not send headers in Session.headers with None values."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 487–492why, one step back487 ses = requests.Session()488 ses.headers["Accept-Encoding"] = None489 req = requests.Request("GET", httpbin("get"))490 prep = ses.prepare_request(req)491 assert "Accept-Encoding" not in prep.headers492Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 493–494why, one step back493 def test_headers_preserve_order(self, httpbin):494 """Preserve order when headers provided as OrderedDict."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 495why, one step back495 ses = requests.Session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 496why, one step back496 ses.headers = collections.OrderedDict()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 497–504why, one step back497 ses.headers["Accept-Encoding"] = "identity"498 ses.headers["First"] = "1"499 ses.headers["Second"] = "2"500 headers = collections.OrderedDict([("Third", "3"), ("Fourth", "4")])501 headers["Fifth"] = "5"502 headers["Second"] = "222"503 req = requests.Request("GET", httpbin("get"), headers=headers)504 prep = ses.prepare_request(req)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 505why, one step back505 items = list(prep.headers.items())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 506–513why, one step back506 assert items[0] == ("Accept-Encoding", "identity")507 assert items[1] == ("First", "1")508 assert items[2] == ("Second", "222")509 assert items[3] == ("Third", "3")510 assert items[4] == ("Fourth", "4")511 assert items[5] == ("Fifth", "5")512513 @pytest.mark.parametrize("key", ("User-agent", "user-agent"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 514why, one step back514 def test_user_agent_transfers(self, httpbin, key):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 515–517why, one step back515 heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}516517 r = requests.get(httpbin("user-agent"), headers=heads)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 518why, one step back518 assert heads[key] in r.textAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 519why, one step back519Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 520why, one step back520 def test_HTTP_200_OK_HEAD(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 521–523why, one step back521 r = requests.head(httpbin("get"))522 assert r.status_code == 200523Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 524why, one step back524 def test_HTTP_200_OK_PUT(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 525–527why, one step back525 r = requests.put(httpbin("put"))526 assert r.status_code == 200527Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 528why, one step back528 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 529–531why, one step back529 auth = ("user", "pass")530 url = httpbin("basic-auth", "user", "pass")531Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 532why, one step back532 r = requests.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 533–534why, one step back533 assert r.status_code == 200534Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 535–536why, one step back535 r = requests.get(url)536 assert r.status_code == 401Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 537–538why, one step back537538 s = requests.session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 539–540why, one step back539 s.auth = auth540 r = s.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 541–547why, one step back541 assert r.status_code == 200542543 @pytest.mark.parametrize(544 "username, password",545 (546 ("user", "pass"),547 ("имя".encode(), "пароль".encode()),Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 548–549why, one step back548 (42, 42),549 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 550–551why, one step back550 ),551 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 552–553why, one step back552 def test_set_basicauth(self, httpbin, username, password):553 auth = (username, password)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 554–560why, one step back554 url = httpbin("get")555556 r = requests.Request("GET", url, auth=auth)557 p = r.prepare()558559 assert p.headers["Authorization"] == _basic_auth_str(username, password)560Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 561–563why, one step back561 def test_basicauth_encodes_byte_strings(self):562 """Ensure b'test' formats as the byte string "test" rather563 than the unicode string "b'test'" in Python 3.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 564–573why, one step back564 """565 auth = (b"\xc5\xafsername", b"test\xc6\xb6")566 r = requests.Request("GET", "http://localhost", auth=auth)567 p = r.prepare()568569 assert p.headers["Authorization"] == "Basic xa9zZXJuYW1lOnRlc3TGtg=="570571 @pytest.mark.parametrize(572 "url, exception",573 (Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 574why, one step back574 # Connecting to an unknown domain should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 575why, one step back575 ("http://doesnotexist.google.com", ConnectionError),Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 576why, one step back576 # Connecting to an invalid port should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 577why, one step back577 ("http://localhost:1", ConnectionError),Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 578why, one step back578 # Inputing a URL that cannot be parsed should raise an InvalidURL errorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 579–581why, one step back579 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),580 ),581 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 582why, one step back582 def test_errors(self, url, exception):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 583why, one step back583 with pytest.raises(exception):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 584why, one step back584 requests.get(url, timeout=1)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 585why, one step back585Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 586–588why, one step back586 def test_proxy_error(self):587 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError588 with pytest.raises(ProxyError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 589–592why, one step back589 requests.get(590 "http://localhost:1", proxies={"http": "non-resolvable-address"}591 )592Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 593why, one step back593 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 594–605why, one step back594 with pytest.raises(InvalidProxyURL):595 requests.get(httpbin_secure(), proxies={"https": "http:/badproxyurl:3128"})596597 with pytest.raises(InvalidProxyURL):598 requests.get(httpbin(), proxies={"http": "http://:8080"})599600 with pytest.raises(InvalidProxyURL):601 requests.get(httpbin_secure(), proxies={"https": "https://"})602603 with pytest.raises(InvalidProxyURL):604 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})605Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 606why, one step back606 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 607–612why, one step back607 with override_environ(http_proxy=INVALID_PROXY):608 with pytest.raises(ProxyError):609 session = requests.Session()610 request = requests.Request("GET", httpbin())611 session.send(request.prepare())612Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 613why, one step back613 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 614–617why, one step back614 with override_environ(http_proxy=INVALID_PROXY):615 with pytest.raises(ProxyError):616 session = requests.Session()617 request = requests.Request("GET", httpbin())Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
lines 618–619why, one step back618 prepared = session.prepare_request(request)619 session.send(prepared)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 620why, one step back620Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 621why, one step back621 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 622–625why, one step back622 with override_environ(http_proxy=INVALID_PROXY):623 with pytest.raises(ProxyError):624 session = requests.Session()625 url = httpbin("redirect/1")Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 626why, one step back626 print(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 627–629why, one step back627 request = requests.Request("GET", url)628 session.send(request.prepare())629Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 630why, one step back630 def test_respect_proxy_env_on_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 631–633why, one step back631 with override_environ(http_proxy=INVALID_PROXY):632 with pytest.raises(ProxyError):633 session = requests.Session()Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 634why, one step back634 session.get(httpbin())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 635why, one step back635Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 636why, one step back636 def test_respect_proxy_env_on_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 637–641why, one step back637 with override_environ(http_proxy=INVALID_PROXY):638 with pytest.raises(ProxyError):639 session = requests.Session()640 session.request(method="GET", url=httpbin())641Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
lines 642–643why, one step back642 def test_proxy_authorization_preserved_on_request(self, httpbin):643 proxy_auth_value = "Bearer XXX"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 644why, one step back644 session = requests.Session()Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
line 645why, one step back645 session.headers.update({"Proxy-Authorization": proxy_auth_value})Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 646–648why, one step back646 resp = session.request(method="GET", url=httpbin("get"))647 sent_headers = resp.json().get("headers", {})648Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
line 649why, one step back649 assert sent_headers.get("Proxy-Authorization") == proxy_auth_valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 650why, one step back650Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 651–653why, one step back651 @pytest.mark.parametrize(652 "url,has_proxy_auth",653 (Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 654–655why, one step back654 ("http://example.com", True),655 ("https://example.com", False),Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 656–657why, one step back656 ),657 )Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 658–660why, one step back658 def test_proxy_authorization_not_appended_to_https_request(659 self, url, has_proxy_auth660 ):Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 661–662why, one step back661 session = requests.Session()662 proxies = {Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 663–664why, one step back663 "http": "http://test:pass@localhost:8080",664 "https": "http://test:pass@localhost:8090",Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
line 665why, one step back665 }Fix linting issuesNate Prewittbefore adoption6e5b15d
line 666why, one step back666 req = requests.Request("GET", url)Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 667–669why, one step back667 prep = req.prepare()668 session.rebuild_proxies(prep, proxies)669Fix linting issuesNate Prewittbefore adoption6e5b15d
line 670why, one step back670 assert ("Proxy-Authorization" in prep.headers) is has_proxy_authMerge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
line 671why, one step back671Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 672why, one step back672 def test_basicauth_with_netrc(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 673–676why, one step back673 auth = ("user", "pass")674 wrong_auth = ("wronguser", "wrongpass")675 url = httpbin("basic-auth", "user", "pass")676Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 677why, one step back677 old_auth = requests.sessions.get_netrc_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 678–680why, one step back678679 try:680Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 681–682why, one step back681 def get_netrc_auth_mock(url):682 return authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 683why, one step back683Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 684why, one step back684 requests.sessions.get_netrc_auth = get_netrc_auth_mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 685–690why, one step back685686 # Should use netrc and work.687 r = requests.get(url)688 assert r.status_code == 200689690 # Given auth should override and fail.Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 691why, one step back691 r = requests.get(url, auth=wrong_auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 692–700why, one step back692 assert r.status_code == 401693694 s = requests.session()695696 # Should use netrc and work.697 r = s.get(url)698 assert r.status_code == 200699700 # Given auth should override and fail.Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 701why, one step back701 s.auth = wrong_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 702–703why, one step back702 r = s.get(url)703 assert r.status_code == 401Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 704–705why, one step back704 finally:705 requests.sessions.get_netrc_auth = old_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 706why, one step back706Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 707why, one step back707 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 708–723why, one step back708 for authtype in self.digest_auth_algo:709 auth = HTTPDigestAuth("user", "pass")710 url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")711712 r = requests.get(url, auth=auth)713 assert r.status_code == 200714715 r = requests.get(url)716 assert r.status_code == 401717 print(r.headers["WWW-Authenticate"])718719 s = requests.session()720 s.auth = HTTPDigestAuth("user", "pass")721 r = s.get(url)722 assert r.status_code == 200723Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 724why, one step back724 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 725–733why, one step back725 for authtype in self.digest_auth_algo:726 url = httpbin("digest-auth", "auth", "user", "pass", authtype)727 auth = HTTPDigestAuth("user", "pass")728 r = requests.get(url)729 assert r.cookies["fake"] == "fake_value"730731 r = requests.get(url, auth=auth)732 assert r.status_code == 200733Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 734why, one step back734 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 735–737why, one step back735 for authtype in self.digest_auth_algo:736 url = httpbin("digest-auth", "auth", "user", "pass", authtype)737 auth = HTTPDigestAuth("user", "pass")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 738–739why, one step back738 s = requests.Session()739 s.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 740–741why, one step back740 assert s.cookies["fake"] == "fake_value"741Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 742why, one step back742 def test_DIGEST_STREAM(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 743–746why, one step back743 for authtype in self.digest_auth_algo:744 auth = HTTPDigestAuth("user", "pass")745 url = httpbin("digest-auth", "auth", "user", "pass", authtype)746Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 747why, one step back747 r = requests.get(url, auth=auth, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 748–749why, one step back748 assert r.raw.read() != b""749Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 750why, one step back750 r = requests.get(url, auth=auth, stream=False)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 751–752why, one step back751 assert r.raw.read() == b""752Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 753why, one step back753 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 754–764why, one step back754 for authtype in self.digest_auth_algo:755 auth = HTTPDigestAuth("user", "wrongpass")756 url = httpbin("digest-auth", "auth", "user", "pass", authtype)757758 r = requests.get(url, auth=auth)759 assert r.status_code == 401760761 r = requests.get(url)762 assert r.status_code == 401763764 s = requests.session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 765why, one step back765 s.auth = authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 766–768why, one step back766 r = s.get(url)767 assert r.status_code == 401768Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 769why, one step back769 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 770–776why, one step back770 for authtype in self.digest_auth_algo:771 auth = HTTPDigestAuth("user", "pass")772 url = httpbin("digest-auth", "auth", "user", "pass", authtype)773774 r = requests.get(url, auth=auth)775 assert '"auth"' in r.request.headers["Authorization"]776Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 777why, one step back777 def test_POSTBIN_GET_POST_FILES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 778–793why, one step back778 url = httpbin("post")779 requests.post(url).raise_for_status()780781 post1 = requests.post(url, data={"some": "data"})782 assert post1.status_code == 200783784 with open("requirements-dev.txt") as f:785 post2 = requests.post(url, files={"some": f})786 assert post2.status_code == 200787788 post4 = requests.post(url, data='[{"some": "json"}]')789 assert post4.status_code == 200790791 with pytest.raises(ValueError):792 requests.post(url, files=["bad file data"])793Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 794why, one step back794 def test_invalid_files_input(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 795–796why, one step back795 url = httpbin("post")796 post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 797–798why, one step back797 assert b'name="random-file-1"' not in post.request.body798 assert b'name="random-file-2"' in post.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 799why, one step back799Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 800why, one step back800 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 801–802why, one step back801 class TestStream:802 def __init__(self, data):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 803–805why, one step back803 self.data = data.encode()804 self.length = len(self.data)805 self.index = 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 806–807why, one step back806807 def __len__(self):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 808why, one step back808 return self.lengthAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 809why, one step back809Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 810–811why, one step back810 def read(self, size=None):811 if size:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 812why, one step back812 ret = self.data[self.index : self.index + size]Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 813–814why, one step back813 self.index += size814 else:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 815why, one step back815 ret = self.data[self.index :]Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 816–817why, one step back816 self.index = self.length817 return retAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 818–819why, one step back818819 def tell(self):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 820why, one step back820 return self.indexAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 821why, one step back821Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 822–828why, one step back822 def seek(self, offset, where=0):823 if where == 0:824 self.index = offset825 elif where == 1:826 self.index += offset827 elif where == 2:828 self.index = self.length + offsetAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 829–835why, one step back829830 test = TestStream("test")831 post1 = requests.post(httpbin("post"), data=test)832 assert post1.status_code == 200833 assert post1.json()["data"] == "test"834835 test = TestStream("test")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 836why, one step back836 test.seek(2)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 837–840why, one step back837 post2 = requests.post(httpbin("post"), data=test)838 assert post2.status_code == 200839 assert post2.json()["data"] == "st"840Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 841why, one step back841 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 842–857why, one step back842 url = httpbin("post")843 requests.post(url).raise_for_status()844845 post1 = requests.post(url, data={"some": "data"})846 assert post1.status_code == 200847848 with open("requirements-dev.txt") as f:849 post2 = requests.post(url, data={"some": "data"}, files={"some": f})850 assert post2.status_code == 200851852 post4 = requests.post(url, data='[{"some": "json"}]')853 assert post4.status_code == 200854855 with pytest.raises(ValueError):856 requests.post(url, files=["bad file data"])857Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 858–861why, one step back858 def test_post_with_custom_mapping(self, httpbin):859 class CustomMapping(MutableMapping):860 def __init__(self, *args, **kwargs):861 self.data = dict(*args, **kwargs)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 862why, one step back862Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 863–864why, one step back863 def __delitem__(self, key):864 del self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 865why, one step back865Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 866–867why, one step back866 def __getitem__(self, key):867 return self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 868why, one step back868Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 869–870why, one step back869 def __setitem__(self, key, value):870 self.data[key] = valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 871–872why, one step back871872 def __iter__(self):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 873why, one step back873 return iter(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 874–875why, one step back874875 def __len__(self):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 876why, one step back876 return len(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 877–882why, one step back877878 data = CustomMapping({"some": "data"})879 url = httpbin("post")880 found_json = requests.post(url, data=data).json().get("form")881 assert found_json == {"some": "data"}882Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 883why, one step back883 def test_conflicting_post_params(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 884–885why, one step back884 url = httpbin("post")885 with open("requirements-dev.txt") as f:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 886why, one step back886 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 887–888why, one step back887 requests.post(url, data='[{"some": "data"}]', files={"some": f})888Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 889why, one step back889 def test_request_ok_set(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 890–892why, one step back890 r = requests.get(httpbin("status", "404"))891 assert not r.ok892Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 893why, one step back893 def test_status_raising(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 894why, one step back894 r = requests.get(httpbin("status", "404"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 895why, one step back895 with pytest.raises(requests.exceptions.HTTPError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 896–900why, one step back896 r.raise_for_status()897898 r = requests.get(httpbin("status", "500"))899 assert not r.ok900Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 901why, one step back901 def test_decompress_gzip(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 902–914why, one step back902 r = requests.get(httpbin("gzip"))903 r.content.decode("ascii")904905 @pytest.mark.parametrize(906 "url, params",907 (908 ("/get", {"foo": "føø"}),909 ("/get", {"føø": "føø"}),910 ("/get", {"føø": "føø"}),911 ("/get", {"foo": "foo"}),912 ("ø", {"foo": "foo"}),913 ),914 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 915–916why, one step back915 def test_unicode_get(self, httpbin, url, params):916 requests.get(httpbin(url), params=params)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 917why, one step back917Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 918–919why, one step back918 def test_unicode_header_name(self, httpbin):919 requests.put(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 920–924why, one step back920 httpbin("put"),921 headers={"Content-Type": "application/octet-stream"},922 data="\xff",923 ) # compat.str is unicode.924Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 925why, one step back925 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 926–927why, one step back926 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)927Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 928why, one step back928 def test_invalid_ca_certificate_path(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 929–930why, one step back929 INVALID_PATH = "/garbage"930 with pytest.raises(IOError) as e:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 931why, one step back931 requests.get(httpbin_secure(), verify=INVALID_PATH)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 932–937why, one step back932 assert str(933 e.value934 ) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format(935 INVALID_PATH936 )937Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 938why, one step back938 def test_invalid_ssl_certificate_files(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 939–940why, one step back939 INVALID_PATH = "/garbage"940 with pytest.raises(IOError) as e:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 941why, one step back941 requests.get(httpbin_secure(), cert=INVALID_PATH)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 942–956why, one step back942 assert str(943 e.value944 ) == "Could not find the TLS certificate file, invalid path: {}".format(945 INVALID_PATH946 )947948 with pytest.raises(IOError) as e:949 requests.get(httpbin_secure(), cert=(".", INVALID_PATH))950 assert str(e.value) == (951 f"Could not find the TLS key file, invalid path: {INVALID_PATH}"952 )953954 @pytest.mark.parametrize(955 "env, expected",956 (Merge pull request #6074 from nateprewitt/curl_ca_bundleIan Stapleton Cordascobefore adoption79f6027
line 957why, one step back957 ({}, True),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 958–978why, one step back958 ({"REQUESTS_CA_BUNDLE": "/some/path"}, "/some/path"),959 ({"REQUESTS_CA_BUNDLE": ""}, True),960 ({"CURL_CA_BUNDLE": "/some/path"}, "/some/path"),961 ({"CURL_CA_BUNDLE": ""}, True),962 ({"REQUESTS_CA_BUNDLE": "", "CURL_CA_BUNDLE": ""}, True),963 (964 {965 "REQUESTS_CA_BUNDLE": "/some/path",966 "CURL_CA_BUNDLE": "/curl/path",967 },968 "/some/path",969 ),970 (971 {972 "REQUESTS_CA_BUNDLE": "",973 "CURL_CA_BUNDLE": "/curl/path",974 },975 "/curl/path",976 ),977 ),978 )Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 979why, one step back979 def test_env_cert_bundles(self, httpbin, env, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 980why, one step back980 s = requests.Session()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 981–984why, one step back981 with mock.patch("os.environ", env):982 settings = s.merge_environment_settings(983 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None984 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 985–986why, one step back985 assert settings["verify"] == expected986Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 987why, one step back987 def test_http_with_certificate(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 988–990why, one step back988 r = requests.get(httpbin(), cert=".")989 assert r.status_code == 200990Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
lines 991–994why, one step back991 @pytest.mark.skipif(992 SNIMissingWarning is None,993 reason="urllib3 2.0 removed that warning and errors out instead",994 )Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba
line 995why, one step back995 def test_https_warnings(self, nosan_server):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 996why, one step back996 """warnings are emitted with requests.get"""Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba
line 997why, one step back997 host, port, ca_bundle = nosan_serverMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 998why, one step back998 if HAS_MODERN_SSL or HAS_PYOPENSSL:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 999–1006why, one step back999 warnings_expected = ("SubjectAltNameWarning",)1000 else:1001 warnings_expected = (1002 "SNIMissingWarning",1003 "InsecurePlatformWarning",1004 "SubjectAltNameWarning",1005 )1006Merge pull request #6682 from frenzymadness/pytest8Ian Stapleton Cordascobefore adoption31ebb81
line 1007why, one step back1007 with pytest.warns() as warning_records:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1008–1017why, one step back1008 warnings.simplefilter("always")1009 requests.get(f"https://localhost:{port}/", verify=ca_bundle)10101011 warning_records = [1012 item1013 for item in warning_records1014 if item.category.__name__ != "ResourceWarning"1015 ]10161017 warnings_category = tuple(item.category.__name__ for item in warning_records)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1018why, one step back1018 assert warnings_category == warnings_expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1019why, one step back1019Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1020why, one step back1020 def test_certificate_failure(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1021why, one step back1021 """Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1022why, one step back1022 When underlying SSL problems occur, an SSLError is raised.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1023why, one step back1023 """Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1024why, one step back1024 with pytest.raises(RequestsSSLError):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1025–1026why, one step back1025 # Our local httpbin does not have a trusted CA, so this call will1026 # fail if we use our default trust bundle.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1027–1028why, one step back1027 requests.get(httpbin_secure("status", "200"))1028Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1029why, one step back1029 def test_urlencoded_get_query_multivalued_param(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1030–1033why, one step back1030 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})1031 assert r.status_code == 2001032 assert r.url == httpbin("get?test=foo&test=baz")1033Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1034why, one step back1034 def test_form_encoded_post_query_multivalued_element(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1035–1040why, one step back1035 r = requests.Request(1036 method="POST", url=httpbin("post"), data=dict(test=["foo", "baz"])1037 )1038 prep = r.prepare()1039 assert prep.body == "test=foo&test=baz"1040Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1041why, one step back1041 def test_different_encodings_dont_break_post(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1042–1048why, one step back1042 with open(__file__, "rb") as f:1043 r = requests.post(1044 httpbin("post"),1045 data={"stuff": json.dumps({"a": 123})},1046 params={"blah": "asdf1234"},1047 files={"file": ("test_requests.py", f)},1048 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1049–1059why, one step back1049 assert r.status_code == 20010501051 @pytest.mark.parametrize(1052 "data",1053 (1054 {"stuff": "ëlïxr"},1055 {"stuff": "ëlïxr".encode()},1056 {"stuff": "elixr"},1057 {"stuff": b"elixr"},1058 ),1059 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1060why, one step back1060 def test_unicode_multipart_post(self, httpbin, data):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1061–1066why, one step back1061 with open(__file__, "rb") as f:1062 r = requests.post(1063 httpbin("post"),1064 data=data,1065 files={"file": ("test_requests.py", f)},1066 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1067–1068why, one step back1067 assert r.status_code == 2001068Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1069why, one step back1069 def test_unicode_multipart_post_fieldnames(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1070why, one step back1070 filename = os.path.splitext(__file__)[0] + ".py"Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1071–1079why, one step back1071 with open(filename, "rb") as f:1072 r = requests.Request(1073 method="POST",1074 url=httpbin("post"),1075 data={b"stuff": "elixr"},1076 files={"file": ("test_requests.py", f)},1077 )1078 prep = r.prepare()1079Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1080why, one step back1080 assert b'name="stuff"' in prep.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1081–1082why, one step back1081 assert b"name=\"b'stuff'\"" not in prep.body1082Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1083why, one step back1083 def test_unicode_method_name(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1084–1090why, one step back1084 with open(__file__, "rb") as f:1085 files = {"file": f}1086 r = requests.request(1087 method="POST",1088 url=httpbin("post"),1089 files=files,1090 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1091–1092why, one step back1091 assert r.status_code == 2001092Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1093why, one step back1093 def test_unicode_method_name_with_request_object(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1094why, one step back1094 s = requests.Session()Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1095–1098why, one step back1095 with open(__file__, "rb") as f:1096 files = {"file": f}1097 req = requests.Request("POST", httpbin("post"), files=files)1098 prep = s.prepare_request(req)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1099why, one step back1099 assert isinstance(prep.method, builtin_str)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1100–1104why, one step back1100 assert prep.method == "POST"11011102 resp = s.send(prep)1103 assert resp.status_code == 2001104Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1105why, one step back1105 def test_non_prepared_request_error(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1106–1109why, one step back1106 s = requests.Session()1107 req = requests.Request("POST", "/")11081109 with pytest.raises(ValueError) as e:Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1110why, one step back1110 s.send(req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1111–1112why, one step back1111 assert str(e.value) == "You can only send PreparedRequests."1112Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1113why, one step back1113 def test_custom_content_type(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1114–1115why, one step back1114 with open(__file__, "rb") as f1:1115 with open(__file__, "rb") as f2:Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1116why, one step back1116 data = {"stuff": json.dumps({"a": 123})}Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1117–1121why, one step back1117 files = {1118 "file1": ("test_requests.py", f1),1119 "file2": ("test_requests", f2, "text/py-content-type"),1120 }1121 r = requests.post(httpbin("post"), data=data, files=files)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1122why, one step back1122 assert r.status_code == 200Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1123why, one step back1123 assert b"text/py-content-type" in r.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1124why, one step back1124Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1125why, one step back1125 def test_hook_receives_request_arguments(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1126why, one step back1126 def hook(resp, **kwargs):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1127–1128why, one step back1127 assert resp is not None1128 assert kwargs != {}Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1129–1132why, one step back11291130 s = requests.Session()1131 r = requests.Request("GET", httpbin(), hooks={"response": hook})1132 prep = s.prepare_request(r)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1133why, one step back1133 s.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1134why, one step back1134Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1135why, one step back1135 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1136–1145why, one step back1136 def hook(*args, **kwargs):1137 pass11381139 s = requests.Session()1140 s.hooks["response"].append(hook)1141 r = requests.Request("GET", httpbin())1142 prep = s.prepare_request(r)1143 assert prep.hooks["response"] != []1144 assert prep.hooks["response"] == [hook]1145Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1146why, one step back1146 def test_session_hooks_are_overridden_by_request_hooks(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1147–1152why, one step back1147 def hook1(*args, **kwargs):1148 pass11491150 def hook2(*args, **kwargs):1151 pass1152Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1153why, one step back1153 assert hook1 is not hook2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1154–1159why, one step back1154 s = requests.Session()1155 s.hooks["response"].append(hook2)1156 r = requests.Request("GET", httpbin(), hooks={"response": [hook1]})1157 prep = s.prepare_request(r)1158 assert prep.hooks["response"] == [hook1]1159Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1160why, one step back1160 def test_prepared_request_hook(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1161why, one step back1161 def hook(resp, **kwargs):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1162why, one step back1162 resp.hook_working = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1163–1165why, one step back1163 return resp11641165 req = requests.Request("GET", httpbin(), hooks={"response": hook})Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1166why, one step back1166 prep = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1167–1173why, one step back11671168 s = requests.Session()1169 s.proxies = getproxies()1170 resp = s.send(prep)11711172 assert hasattr(resp, "hook_working")1173Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1174–1176why, one step back1174 def test_prepared_from_session(self, httpbin):1175 class DummyAuth(requests.auth.AuthBase):1176 def __call__(self, r):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1177why, one step back1177 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1178why, one step back1178 return rAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1179–1180why, one step back11791180 req = requests.Request("GET", httpbin("headers"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1181why, one step back1181 assert not req.authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1182–1183why, one step back11821183 s = requests.Session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1184why, one step back1184 s.auth = DummyAuth()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1185–1190why, one step back11851186 prep = s.prepare_request(req)1187 resp = s.send(prep)11881189 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1190Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1191why, one step back1191 def test_prepare_request_with_bytestring_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1192–1194why, one step back1192 req = requests.Request("GET", b"https://httpbin.org/")1193 s = requests.Session()1194 prep = s.prepare_request(req)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1195why, one step back1195 assert prep.url == "https://httpbin.org/"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1196why, one step back1196Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1197why, one step back1197 def test_request_with_bytestring_host(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1198why, one step back1198 s = requests.Session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1199why, one step back1199 resp = s.request(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1200–1201why, one step back1200 "GET",1201 httpbin("cookies/set?cookie=value"),Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1202why, one step back1202 allow_redirects=False,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1203–1206why, one step back1203 headers={"Host": b"httpbin.org"},1204 )1205 assert resp.cookies.get("cookie") == "value"1206Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1207why, one step back1207 def test_links(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1208why, one step back1208 r = requests.Response()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1209why, one step back1209 r.headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1210–1232why, one step back1210 "cache-control": "public, max-age=60, s-maxage=60",1211 "connection": "keep-alive",1212 "content-encoding": "gzip",1213 "content-type": "application/json; charset=utf-8",1214 "date": "Sat, 26 Jan 2013 16:47:56 GMT",1215 "etag": '"6ff6a73c0e446c1f61614769e3ceb778"',1216 "last-modified": "Sat, 26 Jan 2013 16:22:39 GMT",1217 "link": (1218 "<https://api.github.com/users/kennethreitz/repos?"1219 'page=2&per_page=10>; rel="next", <https://api.github.'1220 "com/users/kennethreitz/repos?page=7&per_page=10>; "1221 ' rel="last"'1222 ),1223 "server": "GitHub.com",1224 "status": "200 OK",1225 "vary": "Accept",1226 "x-content-type-options": "nosniff",1227 "x-github-media-type": "github.beta",1228 "x-ratelimit-limit": "60",1229 "x-ratelimit-remaining": "57",1230 }1231 assert r.links["next"]["rel"] == "next"1232Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1233why, one step back1233 def test_cookie_parameters(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1234–1235why, one step back1234 key = "some_cookie"1235 value = "some_value"Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1236why, one step back1236 secure = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1237–1240why, one step back1237 domain = "test.com"1238 rest = {"HttpOnly": True}12391240 jar = requests.cookies.RequestsCookieJar()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1241why, one step back1241 jar.set(key, value, secure=secure, domain=domain, rest=rest)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1242why, one step back1242Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1243why, one step back1243 assert len(jar) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1244–1245why, one step back1244 assert "some_cookie" in jar1245Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1246–1248why, one step back1246 cookie = list(jar)[0]1247 assert cookie.secure == secure1248 assert cookie.domain == domainAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1249–1250why, one step back1249 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]1250Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1251why, one step back1251 def test_cookie_as_dict_keeps_len(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1252–1265why, one step back1252 key = "some_cookie"1253 value = "some_value"12541255 key1 = "some_cookie1"1256 value1 = "some_value1"12571258 jar = requests.cookies.RequestsCookieJar()1259 jar.set(key, value)1260 jar.set(key1, value1)12611262 d1 = dict(jar)1263 d2 = dict(jar.iteritems())1264 d3 = dict(jar.items())1265Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1266–1269why, one step back1266 assert len(jar) == 21267 assert len(d1) == 21268 assert len(d2) == 21269 assert len(d3) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1270why, one step back1270Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1271why, one step back1271 def test_cookie_as_dict_keeps_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1272–1289why, one step back1272 key = "some_cookie"1273 value = "some_value"12741275 key1 = "some_cookie1"1276 value1 = "some_value1"12771278 jar = requests.cookies.RequestsCookieJar()1279 jar.set(key, value)1280 jar.set(key1, value1)12811282 d1 = dict(jar)1283 d2 = dict(jar.iteritems())1284 d3 = dict(jar.items())12851286 assert d1["some_cookie"] == "some_value"1287 assert d2["some_cookie"] == "some_value"1288 assert d3["some_cookie1"] == "some_value1"1289Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1290why, one step back1290 def test_cookie_as_dict_keys(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1291–1300why, one step back1291 key = "some_cookie"1292 value = "some_value"12931294 key1 = "some_cookie1"1295 value1 = "some_value1"12961297 jar = requests.cookies.RequestsCookieJar()1298 jar.set(key, value)1299 jar.set(key1, value1)1300Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1301–1304why, one step back1301 keys = jar.keys()1302 assert keys == list(keys)1303 # make sure one can use keys multiple times1304 assert list(keys) == list(keys)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1305why, one step back1305Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1306why, one step back1306 def test_cookie_as_dict_values(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1307–1316why, one step back1307 key = "some_cookie"1308 value = "some_value"13091310 key1 = "some_cookie1"1311 value1 = "some_value1"13121313 jar = requests.cookies.RequestsCookieJar()1314 jar.set(key, value)1315 jar.set(key1, value1)1316Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1317–1320why, one step back1317 values = jar.values()1318 assert values == list(values)1319 # make sure one can use values multiple times1320 assert list(values) == list(values)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1321why, one step back1321Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1322why, one step back1322 def test_cookie_as_dict_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1323–1333why, one step back1323 key = "some_cookie"1324 value = "some_value"13251326 key1 = "some_cookie1"1327 value1 = "some_value1"13281329 jar = requests.cookies.RequestsCookieJar()1330 jar.set(key, value)1331 jar.set(key1, value1)13321333 items = jar.items()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1334–1336why, one step back1334 assert items == list(items)1335 # make sure one can use items multiple times1336 assert list(items) == list(items)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1337why, one step back1337Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1338why, one step back1338 def test_cookie_duplicate_names_different_domains(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1339–1344why, one step back1339 key = "some_cookie"1340 value = "some_value"1341 domain1 = "test1.com"1342 domain2 = "test2.com"13431344 jar = requests.cookies.RequestsCookieJar()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1345–1347why, one step back1345 jar.set(key, value, domain=domain1)1346 jar.set(key, value, domain=domain2)1347 assert key in jarAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1348why, one step back1348 items = jar.items()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1349why, one step back1349 assert len(items) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1350why, one step back1350Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1351why, one step back1351 # Verify that CookieConflictError is raised if domain is not specifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1352–1354why, one step back1352 with pytest.raises(requests.cookies.CookieConflictError):1353 jar.get(key)1354Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1355–1357why, one step back1355 # Verify that CookieConflictError is not raised if domain is specified1356 cookie = jar.get(key, domain=domain1)1357 assert cookie == valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1358why, one step back1358Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1359why, one step back1359 def test_cookie_duplicate_names_raises_cookie_conflict_error(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1360–1364why, one step back1360 key = "some_cookie"1361 value = "some_value"1362 path = "some_path"13631364 jar = requests.cookies.RequestsCookieJar()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1365why, one step back1365 jar.set(key, value, path=path)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1366–1369why, one step back1366 jar.set(key, value)1367 with pytest.raises(requests.cookies.CookieConflictError):1368 jar.get(key)1369Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1370–1371why, one step back1370 def test_cookie_policy_copy(self):1371 class MyCookiePolicy(cookielib.DefaultCookiePolicy):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1372–1374why, one step back1372 pass13731374 jar = requests.cookies.RequestsCookieJar()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1375–1376why, one step back1375 jar.set_policy(MyCookiePolicy())1376 assert isinstance(jar.copy().get_policy(), MyCookiePolicy)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1377why, one step back1377Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1378why, one step back1378 def test_time_elapsed_blank(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1379why, one step back1379 r = requests.get(httpbin("get"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1380why, one step back1380 td = r.elapsedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1381–1383why, one step back1381 total_seconds = (1382 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61383 ) / 10**6Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1384why, one step back1384 assert total_seconds > 0.0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1385why, one step back1385Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1386why, one step back1386 def test_empty_response_has_content_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1387–1389why, one step back1387 r = requests.Response()1388 assert r.content is None1389Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1390why, one step back1390 def test_response_is_iterable(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1391–1392why, one step back1391 r = requests.Response()1392 io = StringIO.StringIO("abc")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1393why, one step back1393 read_ = io.readAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1394why, one step back1394Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1395–1396why, one step back1395 def read_mock(amt, decode_content=None):1396 return read_(amt)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1397–1398why, one step back13971398 setattr(io, "read", read_mock)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1399–1401why, one step back1399 r.raw = io1400 assert next(iter(r))1401 io.close()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1402why, one step back1402Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1403–1405why, one step back1403 def test_response_decode_unicode(self):1404 """When called with decode_unicode, Response.iter_content should always1405 return unicode.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1406–1407why, one step back1406 """1407 r = requests.Response()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1408why, one step back1408 r._content_consumed = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1409–1414why, one step back1409 r._content = b"the content"1410 r.encoding = "ascii"14111412 chunks = r.iter_content(decode_unicode=True)1413 assert all(isinstance(chunk, str) for chunk in chunks)1414Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1415why, one step back1415 # also for streamingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1416–1421why, one step back1416 r = requests.Response()1417 r.raw = io.BytesIO(b"the content")1418 r.encoding = "ascii"1419 chunks = r.iter_content(decode_unicode=True)1420 assert all(isinstance(chunk, str) for chunk in chunks)1421Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1422–1423why, one step back1422 def test_response_reason_unicode(self):1423 # check for unicode HTTP statusAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1424–1426why, one step back1424 r = requests.Response()1425 r.url = "unicode URL"1426 r.reason = "Komponenttia ei löydy".encode()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1427why, one step back1427 r.status_code = 404Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1428why, one step back1428 r.encoding = NoneMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1429why, one step back1429 assert not r.ok # old behaviour - crashes hereAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1430why, one step back1430Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1431–1432why, one step back1431 def test_response_reason_unicode_fallback(self):1432 # check raise_status falls back to ISO-8859-1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1433–1436why, one step back1433 r = requests.Response()1434 r.url = "some url"1435 reason = "Komponenttia ei löydy"1436 r.reason = reason.encode("latin-1")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1437why, one step back1437 r.status_code = 500Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1438why, one step back1438 r.encoding = NoneMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1439why, one step back1439 with pytest.raises(requests.exceptions.HTTPError) as e:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1440why, one step back1440 r.raise_for_status()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1441why, one step back1441 assert reason in e.value.args[0]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1442why, one step back1442Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1443–1445why, one step back1443 def test_response_chunk_size_type(self):1444 """Ensure that chunk_size is passed as None or an integer, otherwise1445 raise a TypeError.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1446–1448why, one step back1446 """1447 r = requests.Response()1448 r.raw = io.BytesIO(b"the content")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1449–1450why, one step back1449 chunks = r.iter_content(1)1450 assert all(len(chunk) == 1 for chunk in chunks)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1451–1453why, one step back14511452 r = requests.Response()1453 r.raw = io.BytesIO(b"the content")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1454why, one step back1454 chunks = r.iter_content(None)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1455–1459why, one step back1455 assert list(chunks) == [b"the content"]14561457 r = requests.Response()1458 r.raw = io.BytesIO(b"the content")1459 with pytest.raises(TypeError):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1460why, one step back1460 chunks = r.iter_content("1024")Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1461–1464why, one step back14611462 @pytest.mark.parametrize(1463 "exception, args, expected",1464 (Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1465–1466why, one step back1465 (urllib3.exceptions.ProtocolError, tuple(), ChunkedEncodingError),1466 (urllib3.exceptions.DecodeError, tuple(), ContentDecodingError),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1467why, one step back1467 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1468why, one step back1468 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1469–1470why, one step back1469 ),1470 )Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1471why, one step back1471 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1472why, one step back1472 r = requests.Response()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1473why, one step back1473 r.raw = mock.Mock()Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1474–1476why, one step back1474 # ReadTimeoutError can't be initialized by mock1475 # so we'll manually create the instance with args1476 r.raw.stream.side_effect = exception(*args)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1477why, one step back1477Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1478–1479why, one step back1478 with pytest.raises(expected):1479 next(r.iter_content(1024))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1480why, one step back1480Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1481why, one step back1481 def test_request_and_response_are_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1482–1483why, one step back1482 r = requests.get(httpbin("get"))1483Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1484–1485why, one step back1484 # verify we can pickle the original request1485 assert pickle.loads(pickle.dumps(r.request))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1486why, one step back1486Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1487–1491why, one step back1487 # verify we can pickle the response and that we have access to1488 # the original request.1489 pr = pickle.loads(pickle.dumps(r))1490 assert r.request.url == pr.request.url1491 assert r.request.headers == pr.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1492why, one step back1492Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1493why, one step back1493 def test_prepared_request_is_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1494–1506why, one step back1494 p = requests.Request("GET", httpbin("get")).prepare()14951496 # Verify PreparedRequest can be pickled and unpickled1497 r = pickle.loads(pickle.dumps(p))1498 assert r.url == p.url1499 assert r.headers == p.headers1500 assert r.body == p.body15011502 # Verify unpickled PreparedRequest sends properly1503 s = requests.Session()1504 resp = s.send(r)1505 assert resp.status_code == 2001506Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1507why, one step back1507 def test_prepared_request_with_file_is_pickleable(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1508–1510why, one step back1508 with open(__file__, "rb") as f:1509 r = requests.Request("POST", httpbin("post"), files={"file": f})1510 p = r.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1511–1522why, one step back15111512 # Verify PreparedRequest can be pickled and unpickled1513 r = pickle.loads(pickle.dumps(p))1514 assert r.url == p.url1515 assert r.headers == p.headers1516 assert r.body == p.body15171518 # Verify unpickled PreparedRequest sends properly1519 s = requests.Session()1520 resp = s.send(r)1521 assert resp.status_code == 2001522Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1523why, one step back1523 def test_prepared_request_with_hook_is_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1524–1526why, one step back1524 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())1525 p = r.prepare()1526Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1527why, one step back1527 # Verify PreparedRequest can be pickledAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1528–1531why, one step back1528 r = pickle.loads(pickle.dumps(p))1529 assert r.url == p.url1530 assert r.headers == p.headers1531 assert r.body == p.bodyMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1532why, one step back1532 assert r.hooks == p.hooksAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1533–1538why, one step back15331534 # Verify unpickled PreparedRequest sends properly1535 s = requests.Session()1536 resp = s.send(r)1537 assert resp.status_code == 2001538Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1539–1540why, one step back1539 def test_cannot_send_unprepared_requests(self, httpbin):1540 r = requests.Request(url=httpbin())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1541why, one step back1541 with pytest.raises(ValueError):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1542why, one step back1542 requests.Session().send(r)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1543why, one step back1543Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1544–1548why, one step back1544 def test_http_error(self):1545 error = requests.exceptions.HTTPError()1546 assert not error.response1547 response = requests.Response()1548 error = requests.exceptions.HTTPError(response=response)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1549–1553why, one step back1549 assert error.response == response1550 error = requests.exceptions.HTTPError("message", response=response)1551 assert str(error) == "message"1552 assert error.response == response1553Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1554why, one step back1554 def test_session_pickling(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1555–1557why, one step back1555 r = requests.Request("GET", httpbin("get"))1556 s = requests.Session()1557Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1558why, one step back1558 s = pickle.loads(pickle.dumps(s))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1559–1563why, one step back1559 s.proxies = getproxies()15601561 r = s.send(r.prepare())1562 assert r.status_code == 2001563Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1564–1565why, one step back1564 def test_fixes_1329(self, httpbin):1565 """Ensure that header updates are done case-insensitively."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1566–1569why, one step back1566 s = requests.Session()1567 s.headers.update({"ACCEPT": "BOGUS"})1568 s.headers.update({"accept": "application/json"})1569 r = s.get(httpbin("get"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1570why, one step back1570 headers = r.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1571–1574why, one step back1571 assert headers["accept"] == "application/json"1572 assert headers["Accept"] == "application/json"1573 assert headers["ACCEPT"] == "application/json"1574Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1575why, one step back1575 def test_uppercase_scheme_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1576why, one step back1576 parts = urlparse(httpbin("html"))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1577why, one step back1577 url = "HTTP://" + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1578–1579why, one step back1578 r = requests.get(httpbin("redirect-to"), params={"url": url})1579 assert r.status_code == 200Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1580why, one step back1580 assert r.url.lower() == url.lower()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1581why, one step back1581Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1582why, one step back1582 def test_transport_adapter_ordering(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1583–1613why, one step back1583 s = requests.Session()1584 order = ["https://", "http://"]1585 assert order == list(s.adapters)1586 s.mount("http://git", HTTPAdapter())1587 s.mount("http://github", HTTPAdapter())1588 s.mount("http://github.com", HTTPAdapter())1589 s.mount("http://github.com/about/", HTTPAdapter())1590 order = [1591 "http://github.com/about/",1592 "http://github.com",1593 "http://github",1594 "http://git",1595 "https://",1596 "http://",1597 ]1598 assert order == list(s.adapters)1599 s.mount("http://gittip", HTTPAdapter())1600 s.mount("http://gittip.com", HTTPAdapter())1601 s.mount("http://gittip.com/about/", HTTPAdapter())1602 order = [1603 "http://github.com/about/",1604 "http://gittip.com/about/",1605 "http://github.com",1606 "http://gittip.com",1607 "http://github",1608 "http://gittip",1609 "http://git",1610 "https://",1611 "http://",1612 ]1613 assert order == list(s.adapters)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1614why, one step back1614 s2 = requests.Session()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1615–1619why, one step back1615 s2.adapters = {"http://": HTTPAdapter()}1616 s2.mount("https://", HTTPAdapter())1617 assert "http://" in s2.adapters1618 assert "https://" in s2.adapters1619Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1620why, one step back1620 def test_session_get_adapter_prefix_matching(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1621–1628why, one step back1621 prefix = "https://example.com"1622 more_specific_prefix = prefix + "/some/path"16231624 url_matching_only_prefix = prefix + "/another/path"1625 url_matching_more_specific_prefix = more_specific_prefix + "/longer/path"1626 url_not_matching_prefix = "https://another.example.com/"16271628 s = requests.Session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1629–1632why, one step back1629 prefix_adapter = HTTPAdapter()1630 more_specific_prefix_adapter = HTTPAdapter()1631 s.mount(prefix, prefix_adapter)1632 s.mount(more_specific_prefix, more_specific_prefix_adapter)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1633why, one step back1633Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1634why, one step back1634 assert s.get_adapter(url_matching_only_prefix) is prefix_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1635–1643why, one step back1635 assert (1636 s.get_adapter(url_matching_more_specific_prefix)1637 is more_specific_prefix_adapter1638 )1639 assert s.get_adapter(url_not_matching_prefix) not in (1640 prefix_adapter,1641 more_specific_prefix_adapter,1642 )1643Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1644why, one step back1644 def test_session_get_adapter_prefix_matching_mixed_case(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1645–1651why, one step back1645 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"1646 url_matching_prefix = mixed_case_prefix + "/full_url"16471648 s = requests.Session()1649 my_adapter = HTTPAdapter()1650 s.mount(mixed_case_prefix, my_adapter)1651Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1652why, one step back1652 assert s.get_adapter(url_matching_prefix) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1653why, one step back1653Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1654why, one step back1654 def test_session_get_adapter_prefix_matching_is_case_insensitive(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1655–1663why, one step back1655 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"1656 url_matching_prefix_with_different_case = (1657 "HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url"1658 )16591660 s = requests.Session()1661 my_adapter = HTTPAdapter()1662 s.mount(mixed_case_prefix, my_adapter)1663Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1664why, one step back1664 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1665why, one step back1665Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1666–1667why, one step back1666 def test_header_remove_is_case_insensitive(self, httpbin):1667 # From issue #1321Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1668–1672why, one step back1668 s = requests.Session()1669 s.headers["foo"] = "bar"1670 r = s.get(httpbin("get"), headers={"FOO": None})1671 assert "foo" not in r.request.headers1672Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1673why, one step back1673 def test_params_are_merged_case_sensitive(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1674–1678why, one step back1674 s = requests.Session()1675 s.params["foo"] = "bar"1676 r = s.get(httpbin("get"), params={"FOO": "bar"})1677 assert r.json()["args"] == {"foo": "bar", "FOO": "bar"}1678Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1679why, one step back1679 def test_long_authinfo_in_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1680–1685why, one step back1680 url = "http://{}:{}@{}:9000/path?query#frag".format(1681 "E8A3BE87-9E3F-4620-8858-95478E385B5B",1682 "EA770032-DA4D-4D84-8CE9-29C6D910BF1E",1683 "exactly-------------sixty-----------three------------characters",1684 )1685 r = requests.Request("GET", url).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1686why, one step back1686 assert r.url == urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1687why, one step back1687Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1688why, one step back1688 def test_header_keys_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1689–1692why, one step back1689 headers = {"unicode": "blah", b"byte": "blah"}1690 r = requests.Request("GET", httpbin("get"), headers=headers)1691 p = r.prepare()1692Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1693–1694why, one step back1693 # This is testing that they are builtin strings. A bit weird, but there1694 # we go.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1695–1697why, one step back1695 assert "unicode" in p.headers.keys()1696 assert "byte" in p.headers.keys()1697Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1698–1699why, one step back1698 def test_header_validation(self, httpbin):1699 """Ensure prepare_headers regex isn't flagging valid header contents."""Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1700why, one step back1700 valid_headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1701–1705why, one step back1701 "foo": "bar baz qux",1702 "bar": b"fbbq",1703 "baz": "",1704 "qux": "1",1705 }Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1706–1707why, one step back1706 r = requests.get(httpbin("get"), headers=valid_headers)1707 for key in valid_headers.keys():Merge pull request #6552 from swims-hjkl/issue/test_header_validationNate Prewittbefore adoption839a8ed
line 1708why, one step back1708 assert valid_headers[key] == r.request.headers[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1709why, one step back1709Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1710–1718why, one step back1710 @pytest.mark.parametrize(1711 "invalid_header, key",1712 (1713 ({"foo": 3}, "foo"),1714 ({"bar": {"foo": "bar"}}, "bar"),1715 ({"baz": ["foo", "bar"]}, "baz"),1716 ),1717 )1718 def test_header_value_not_str(self, httpbin, invalid_header, key):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1719–1720why, one step back1719 """Ensure the header value is of type string or bytes as1720 per discussion in GH issue #3386Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1721–1722why, one step back1721 """1722 with pytest.raises(InvalidHeader) as excinfo:Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1723–1724why, one step back1723 requests.get(httpbin("get"), headers=invalid_header)1724 assert key in str(excinfo.value)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1725why, one step back1725Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1726–1739why, one step back1726 @pytest.mark.parametrize(1727 "invalid_header",1728 (1729 {"foo": "bar\r\nbaz: qux"},1730 {"foo": "bar\n\rbaz: qux"},1731 {"foo": "bar\nbaz: qux"},1732 {"foo": "bar\rbaz: qux"},1733 {"fo\ro": "bar"},1734 {"fo\r\no": "bar"},1735 {"fo\n\ro": "bar"},1736 {"fo\no": "bar"},1737 ),1738 )1739 def test_header_no_return_chars(self, httpbin, invalid_header):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1740–1741why, one step back1740 """Ensure that a header containing return character sequences raise an1741 exception. Otherwise, multiple headers are created from single string.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1742–1743why, one step back1742 """1743 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1744why, one step back1744 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1745why, one step back1745Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1746–1758why, one step back1746 @pytest.mark.parametrize(1747 "invalid_header",1748 (1749 {" foo": "bar"},1750 {"\tfoo": "bar"},1751 {" foo": "bar"},1752 {"foo": " bar"},1753 {"foo": " bar"},1754 {"foo": "\tbar"},1755 {" ": "bar"},1756 ),1757 )1758 def test_header_no_leading_space(self, httpbin, invalid_header):Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1759–1760why, one step back1759 """Ensure headers containing leading whitespace raise1760 InvalidHeader Error before sending.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1761–1762why, one step back1761 """1762 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1763why, one step back1763 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1764why, one step back1764Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7
lines 1765–1789why, one step back1765 def test_header_with_subclass_types(self, httpbin):1766 """If the subclasses does not behave *exactly* like1767 the base bytes/str classes, this is not supported.1768 This test is for backwards compatibility.1769 """17701771 class MyString(str):1772 pass17731774 class MyBytes(bytes):1775 pass17761777 r_str = requests.get(httpbin("get"), headers={MyString("x-custom"): "myheader"})1778 assert r_str.request.headers["x-custom"] == "myheader"17791780 r_bytes = requests.get(1781 httpbin("get"), headers={MyBytes(b"x-custom"): b"myheader"}1782 )1783 assert r_bytes.request.headers["x-custom"] == b"myheader"17841785 r_mixed = requests.get(1786 httpbin("get"), headers={MyString("x-custom"): MyBytes(b"myheader")}1787 )1788 assert r_mixed.request.headers["x-custom"] == b"myheader"1789Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1790why, one step back1790 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1791why, one step back1791 def test_can_send_objects_with_files(self, httpbin, files):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1792–1797why, one step back1792 data = {"a": "this is a string"}1793 files = {"b": files}1794 r = requests.Request("POST", httpbin("post"), data=data, files=files)1795 p = r.prepare()1796 assert "multipart/form-data" in p.headers["Content-Type"]1797Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1798–1800why, one step back1798 def test_can_send_file_object_with_non_string_filename(self, httpbin):1799 f = io.BytesIO()1800 f.name = 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1801–1805why, one step back1801 r = requests.Request("POST", httpbin("post"), files={"f": f})1802 p = r.prepare()18031804 assert "multipart/form-data" in p.headers["Content-Type"]1805Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1806why, one step back1806 def test_autoset_header_values_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1807–1809why, one step back1807 data = "this is a string"1808 length = "16"1809 req = requests.Request("POST", httpbin("post"), data=data)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1810why, one step back1810 p = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1811–1813why, one step back18111812 assert p.headers["Content-Length"] == length1813Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1814–1815why, one step back1814 def test_nonhttp_schemes_dont_check_URLs(self):1815 test_urls = (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1816–1819why, one step back1816 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",1817 "file:///etc/passwd",1818 "magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431",1819 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1820why, one step back1820 for test_url in test_urls:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1821why, one step back1821 req = requests.Request("GET", test_url)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1822–1823why, one step back1822 preq = req.prepare()1823 assert test_url == preq.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1824–1836why, one step back18241825 def test_auth_is_stripped_on_http_downgrade(1826 self, httpbin, httpbin_secure, httpbin_ca_bundle1827 ):1828 r = requests.get(1829 httpbin_secure("redirect-to"),1830 params={"url": httpbin("get")},1831 auth=("user", "pass"),1832 verify=httpbin_ca_bundle,1833 )1834 assert r.history[0].request.headers["Authorization"]1835 assert "Authorization" not in r.request.headers1836Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1837why, one step back1837 def test_auth_is_retained_for_redirect_on_host(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1838–1841why, one step back1838 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))1839 h1 = r.history[0].request.headers["Authorization"]1840 h2 = r.request.headers["Authorization"]1841Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1842why, one step back1842 assert h1 == h2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1843why, one step back1843Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1844why, one step back1844 def test_should_strip_auth_host_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1845–1849why, one step back1845 s = requests.Session()1846 assert s.should_strip_auth(1847 "http://example.com/foo", "http://another.example.com/"1848 )1849Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1850why, one step back1850 def test_should_strip_auth_http_downgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1851–1853why, one step back1851 s = requests.Session()1852 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1853Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1854why, one step back1854 def test_should_strip_auth_https_upgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1855–1864why, one step back1855 s = requests.Session()1856 assert not s.should_strip_auth(1857 "http://example.com/foo", "https://example.com/bar"1858 )1859 assert not s.should_strip_auth(1860 "http://example.com:80/foo", "https://example.com/bar"1861 )1862 assert not s.should_strip_auth(1863 "http://example.com/foo", "https://example.com:443/bar"1864 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1865why, one step back1865 # Non-standard ports should trigger strippingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1866–1872why, one step back1866 assert s.should_strip_auth(1867 "http://example.com:8080/foo", "https://example.com/bar"1868 )1869 assert s.should_strip_auth(1870 "http://example.com/foo", "https://example.com:8443/bar"1871 )1872Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1873why, one step back1873 def test_should_strip_auth_port_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1874–1887why, one step back1874 s = requests.Session()1875 assert s.should_strip_auth(1876 "http://example.com:1234/foo", "https://example.com:4321/bar"1877 )18781879 @pytest.mark.parametrize(1880 "old_uri, new_uri",1881 (1882 ("https://example.com:443/foo", "https://example.com/bar"),1883 ("http://example.com:80/foo", "http://example.com/bar"),1884 ("https://example.com/foo", "https://example.com:443/bar"),1885 ("http://example.com/foo", "http://example.com:80/bar"),1886 ),1887 )Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1888why, one step back1888 def test_should_strip_auth_default_port(self, old_uri, new_uri):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1889why, one step back1889 s = requests.Session()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1890why, one step back1890 assert not s.should_strip_auth(old_uri, new_uri)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1891why, one step back1891Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1892why, one step back1892 def test_manual_redirect_with_partial_body_read(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1893–1894why, one step back1893 s = requests.Session()1894 r1 = s.get(httpbin("redirect/2"), allow_redirects=False, stream=True)Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1895–1896why, one step back1895 assert r1.is_redirect1896 rg = s.resolve_redirects(r1, r1.request, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1897why, one step back1897Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1898why, one step back1898 # read only the first eight bytes of the response body,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1899why, one step back1899 # then follow the redirectMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1900–1902why, one step back1900 r1.iter_content(8)1901 r2 = next(rg)1902 assert r2.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1903why, one step back1903Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1904why, one step back1904 # read all of the response via iter_content,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1905why, one step back1905 # then follow the redirectMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1906why, one step back1906 for _ in r2.iter_content():Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1907why, one step back1907 passMove CI to Github ActionsNate Prewittbefore adoption9cd2d33
lines 1908–1909why, one step back1908 r3 = next(rg)1909 assert not r3.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1910why, one step back1910Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1911why, one step back1911 def test_prepare_body_position_non_stream(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1912–1913why, one step back1912 data = b"the data"1913 prep = requests.Request("GET", "http://example.com", data=data).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1914why, one step back1914 assert prep._body_position is NoneAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1915why, one step back1915Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1916why, one step back1916 def test_rewind_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1917–1928why, one step back1917 data = io.BytesIO(b"the data")1918 prep = requests.Request("GET", "http://example.com", data=data).prepare()1919 assert prep._body_position == 01920 assert prep.body.read() == b"the data"19211922 # the data has all been read1923 assert prep.body.read() == b""19241925 # rewind it back1926 requests.utils.rewind_body(prep)1927 assert prep.body.read() == b"the data"1928Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1929why, one step back1929 def test_rewind_partially_read_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1930why, one step back1930 data = io.BytesIO(b"the data")Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1931why, one step back1931 data.read(4) # read some dataAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1932why, one step back1932 prep = requests.Request("GET", "http://example.com", data=data).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1933why, one step back1933 assert prep._body_position == 4Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1934–1942why, one step back1934 assert prep.body.read() == b"data"19351936 # the data has all been read1937 assert prep.body.read() == b""19381939 # rewind it back1940 requests.utils.rewind_body(prep)1941 assert prep.body.read() == b"data"1942Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1943why, one step back1943 def test_rewind_body_no_seek(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1944–1962why, one step back1944 class BadFileObj:1945 def __init__(self, data):1946 self.data = data19471948 def tell(self):1949 return 019501951 def __iter__(self):1952 return19531954 data = BadFileObj("the data")1955 prep = requests.Request("GET", "http://example.com", data=data).prepare()1956 assert prep._body_position == 019571958 with pytest.raises(UnrewindableBodyError) as e:1959 requests.utils.rewind_body(prep)19601961 assert "Unable to rewind request body" in str(e)1962Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1963why, one step back1963 def test_rewind_body_failed_seek(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1964–1970why, one step back1964 class BadFileObj:1965 def __init__(self, data):1966 self.data = data19671968 def tell(self):1969 return 01970Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1971why, one step back1971 def seek(self, pos, whence=0):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1972–1985why, one step back1972 raise OSError()19731974 def __iter__(self):1975 return19761977 data = BadFileObj("the data")1978 prep = requests.Request("GET", "http://example.com", data=data).prepare()1979 assert prep._body_position == 019801981 with pytest.raises(UnrewindableBodyError) as e:1982 requests.utils.rewind_body(prep)19831984 assert "error occurred when rewinding request body" in str(e)1985Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1986why, one step back1986 def test_rewind_body_failed_tell(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1987–1998why, one step back1987 class BadFileObj:1988 def __init__(self, data):1989 self.data = data19901991 def tell(self):1992 raise OSError()19931994 def __iter__(self):1995 return19961997 data = BadFileObj("the data")1998 prep = requests.Request("GET", "http://example.com", data=data).prepare()Move CI to Github ActionsNate Prewittbefore adoption9cd2d33
line 1999why, one step back1999 assert prep._body_position is not NoneAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 2000–2005why, one step back2000The first 2,000 of 2,983 lines.