test_requests.py
This file
Path
tests/test_requests.py
2,839 lines · 97.3 KiB · Python
Last changed by
Merge pull request #6589 from bruceadams/super_len_str_utf-8Ian Stapleton Cordascobefore adoptionb8be93a
History of this fileTake it
The walk stopped after 200 commits: lines older than 7c71982 point at it.
Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1why, one step back1"""Tests for Requests."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 2why, one step back2Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 3–5why, one step back3import collections4import contextlib5import ioAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 6–10why, one step back6import json7import os8import pickle9import re10import warningsRemove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 11why, one step back11from unittest import mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 12why, one step back12Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 13why, one step back13import pytestWrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 14why, one step back14import urllib3Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 15why, one step back15from urllib3.util import Timeout as Urllib3TimeoutAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 16–51why, one step back1617import requests18from requests.adapters import HTTPAdapter19from requests.auth import HTTPDigestAuth, _basic_auth_str20from requests.compat import (21 JSONDecodeError,22 Morsel,23 MutableMapping,24 builtin_str,25 cookielib,26 getproxies,27 urlparse,28)29from requests.cookies import cookiejar_from_dict, morsel_to_cookie30from requests.exceptions import (31 ChunkedEncodingError,32 ConnectionError,33 ConnectTimeout,34 ContentDecodingError,35 InvalidHeader,36 InvalidProxyURL,37 InvalidSchema,38 InvalidURL,39 MissingSchema,40 ProxyError,41 ReadTimeout,42 RequestException,43 RetryError,44)45from requests.exceptions import SSLError as RequestsSSLError46from requests.exceptions import Timeout, TooManyRedirects, UnrewindableBodyError47from requests.hooks import default_hooks48from requests.models import PreparedRequest, urlencode49from requests.sessions import SessionRedirectMixin50from requests.structures import CaseInsensitiveDict51Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
line 52why, one step back52from . import SNIMissingWarningAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 53–55why, one step back53from .compat import StringIO54from .utils import override_environ55Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 56–57why, one step back56# Requests to this URL should always fail with a connection timeout (nothing57# listening on that port)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 58–59why, one step back58TARPIT = "http://10.255.255.1"59Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 60why, one step back60# This is to avoid waiting the timeout of using TARPITAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 61–63why, one step back61INVALID_PROXY = "http://localhost:1"6263try:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 64why, one step back64 from ssl import SSLContextAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 65why, one step back65Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 66–69why, one step back66 del SSLContext67 HAS_MODERN_SSL = True68except ImportError:69 HAS_MODERN_SSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 70–71why, one step back7071try:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 72–75why, one step back72 requests.pyopenssl73 HAS_PYOPENSSL = True74except AttributeError:75 HAS_PYOPENSSL = FalseAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 76–77why, one step back7677Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 78why, one step back78class TestRequests:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 79–80why, one step back79 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")80Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 81–90why, one step back81 def test_entry_points(self):82 requests.session83 requests.session().get84 requests.session().head85 requests.get86 requests.head87 requests.put88 requests.patch89 requests.post90 # Not really an entry point, but people rely on it.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 91–104why, one step back91 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F4019293 @pytest.mark.parametrize(94 "exception, url",95 (96 (MissingSchema, "hiwpefhipowhefopw"),97 (InvalidSchema, "localhost:3128"),98 (InvalidSchema, "localhost.localdomain:3128/"),99 (InvalidSchema, "10.122.1.1:3128/"),100 (InvalidURL, "http://"),101 (InvalidURL, "http://*example.com"),102 (InvalidURL, "http://.example.com"),103 ),104 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 105why, one step back105 def test_invalid_url(self, exception, url):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 106why, one step back106 with pytest.raises(exception):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 107why, one step back107 requests.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 108why, one step back108Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 109–110why, one step back109 def test_basic_building(self):110 req = requests.Request()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 111–113why, one step back111 req.url = "http://kennethreitz.org/"112 req.data = {"life": "42"}113Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 114–115why, one step back114 pr = req.prepare()115 assert pr.url == req.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 116–118why, one step back116 assert pr.body == "life=42"117118 @pytest.mark.parametrize("method", ("GET", "HEAD"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 119why, one step back119 def test_no_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 120–123why, one step back120 req = requests.Request(method, httpbin(method.lower())).prepare()121 assert "Content-Length" not in req.headers122123 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 124why, one step back124 def test_no_body_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 125–128why, one step back125 req = requests.Request(method, httpbin(method.lower())).prepare()126 assert req.headers["Content-Length"] == "0"127128 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 129why, one step back129 def test_empty_content_length(self, httpbin, method):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 130–132why, one step back130 req = requests.Request(method, httpbin(method.lower()), data="").prepare()131 assert req.headers["Content-Length"] == "0"132Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 133why, one step back133 def test_override_content_length(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 134–138why, one step back134 headers = {"Content-Length": "not zero"}135 r = requests.Request("POST", httpbin("post"), headers=headers).prepare()136 assert "Content-Length" in r.headers137 assert r.headers["Content-Length"] == "not zero"138Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 139why, one step back139 def test_path_is_not_double_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 140–156why, one step back140 request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()141142 assert request.path_url == "/get/test%20case"143144 @pytest.mark.parametrize(145 "url, expected",146 (147 (148 "http://example.com/path#fragment",149 "http://example.com/path?a=b#fragment",150 ),151 (152 "http://example.com/path?key=value#fragment",153 "http://example.com/path?key=value&a=b#fragment",154 ),155 ),156 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 157why, one step back157 def test_params_are_added_before_fragment(self, url, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 158why, one step back158 request = requests.Request("GET", url, params={"a": "b"}).prepare()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 159why, one step back159 assert request.url == expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 160why, one step back160Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 161why, one step back161 def test_params_original_order_is_preserved_by_default(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 162–168why, one step back162 param_ordered_dict = collections.OrderedDict(163 (("z", 1), ("a", 1), ("k", 1), ("d", 1))164 )165 session = requests.Session()166 request = requests.Request(167 "GET", "http://example.com/", params=param_ordered_dict168 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 169why, one step back169 prep = session.prepare_request(request)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 170–171why, one step back170 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"171Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 172why, one step back172 def test_params_bytes_are_encoded(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 173–177why, one step back173 request = requests.Request(174 "GET", "http://example.com", params=b"test=foo"175 ).prepare()176 assert request.url == "http://example.com/?test=foo"177Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 178why, one step back178 def test_binary_put(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 179–181why, one step back179 request = requests.Request(180 "PUT", "http://example.com", data="ööö".encode()181 ).prepare()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 182why, one step back182 assert isinstance(request.body, bytes)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 183why, one step back183Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 184–185why, one step back184 def test_whitespaces_are_removed_from_url(self):185 # Test for issue #3696Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 186–189why, one step back186 request = requests.Request("GET", " http://example.com").prepare()187 assert request.url == "http://example.com/"188189 @pytest.mark.parametrize("scheme", ("http://", "HTTP://", "hTTp://", "HttP://"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 190why, one step back190 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 191–193why, one step back191 s = requests.Session()192 s.proxies = getproxies()193 parts = urlparse(httpbin("get"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 194why, one step back194 url = scheme + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 195–198why, one step back195 r = requests.Request("GET", url)196 r = s.send(r.prepare())197 assert r.status_code == 200, f"failed for scheme {scheme}"198Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 199why, one step back199 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 200–207why, one step back200 r = requests.Request("GET", httpbin("get"))201 s = requests.Session()202 s.proxies = getproxies()203204 r = s.send(r.prepare())205206 assert r.status_code == 200207Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 208why, one step back208 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 209–213why, one step back209 r = requests.get(httpbin("redirect", "1"))210 assert r.status_code == 200211 assert r.history[0].status_code == 302212 assert r.history[0].is_redirect213Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 214why, one step back214 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 215–224why, one step back215 r = requests.post(216 httpbin("redirect-to"),217 data="test",218 params={"url": "post", "status_code": 307},219 )220 assert r.status_code == 200221 assert r.history[0].status_code == 307222 assert r.history[0].is_redirect223 assert r.json()["data"] == "test"224Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 225why, one step back225 def test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 226–236why, one step back226 byte_str = b"test"227 r = requests.post(228 httpbin("redirect-to"),229 data=io.BytesIO(byte_str),230 params={"url": "post", "status_code": 307},231 )232 assert r.status_code == 200233 assert r.history[0].status_code == 307234 assert r.history[0].is_redirect235 assert r.json()["data"] == byte_str.decode("utf-8")236Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 237why, one step back237 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 238–243why, one step back238 try:239 requests.get(httpbin("relative-redirect", "50"))240 except TooManyRedirects as e:241 url = httpbin("relative-redirect", "20")242 assert e.request.url == url243 assert e.response.url == urlMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 244why, one step back244 assert len(e.response.history) == 30Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 245–247why, one step back245 else:246 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")247Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 248why, one step back248 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 249why, one step back249 s = requests.session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 250why, one step back250 s.max_redirects = 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 251–256why, one step back251 try:252 s.get(httpbin("relative-redirect", "50"))253 except TooManyRedirects as e:254 url = httpbin("relative-redirect", "45")255 assert e.request.url == url256 assert e.response.url == urlMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 257why, one step back257 assert len(e.response.history) == 5Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 258–262why, one step back258 else:259 pytest.fail(260 "Expected custom max number of redirects to be respected but was not"261 )262Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 263why, one step back263 def test_http_301_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 264–269why, one step back264 r = requests.post(httpbin("status", "301"))265 assert r.status_code == 200266 assert r.request.method == "GET"267 assert r.history[0].status_code == 301268 assert r.history[0].is_redirect269Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 270why, one step back270 def test_http_301_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 271why, one step back271 r = requests.head(httpbin("status", "301"), allow_redirects=True)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 272why, one step back272 print(r.content)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 273–277why, one step back273 assert r.status_code == 200274 assert r.request.method == "HEAD"275 assert r.history[0].status_code == 301276 assert r.history[0].is_redirect277Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 278why, one step back278 def test_http_302_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 279–284why, one step back279 r = requests.post(httpbin("status", "302"))280 assert r.status_code == 200281 assert r.request.method == "GET"282 assert r.history[0].status_code == 302283 assert r.history[0].is_redirect284Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 285why, one step back285 def test_http_302_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 286–291why, one step back286 r = requests.head(httpbin("status", "302"), allow_redirects=True)287 assert r.status_code == 200288 assert r.request.method == "HEAD"289 assert r.history[0].status_code == 302290 assert r.history[0].is_redirect291Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 292why, one step back292 def test_http_303_changes_post_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 293–298why, one step back293 r = requests.post(httpbin("status", "303"))294 assert r.status_code == 200295 assert r.request.method == "GET"296 assert r.history[0].status_code == 303297 assert r.history[0].is_redirect298Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 299why, one step back299 def test_http_303_doesnt_change_head_to_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 300–305why, one step back300 r = requests.head(httpbin("status", "303"), allow_redirects=True)301 assert r.status_code == 200302 assert r.request.method == "HEAD"303 assert r.history[0].status_code == 303304 assert r.history[0].is_redirect305Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 306why, one step back306 def test_header_and_body_removal_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 307–310why, one step back307 purged_headers = ("Content-Length", "Content-Type")308 ses = requests.Session()309 req = requests.Request("POST", httpbin("post"), data={"test": "data"})310 prep = ses.prepare_request(req)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 311why, one step back311 resp = ses.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 312–316why, one step back312313 # Mimic a redirect response314 resp.status_code = 302315 resp.headers["location"] = "get"316Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 317why, one step back317 # Run request through resolve_redirectsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 318–322why, one step back318 next_resp = next(ses.resolve_redirects(resp, prep))319 assert next_resp.request.body is None320 for header in purged_headers:321 assert header not in next_resp.request.headers322Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 323why, one step back323 def test_transfer_enc_removal_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 324–329why, one step back324 purged_headers = ("Transfer-Encoding", "Content-Type")325 ses = requests.Session()326 req = requests.Request("POST", httpbin("post"), data=(b"x" for x in range(1)))327 prep = ses.prepare_request(req)328 assert "Transfer-Encoding" in prep.headers329Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 330why, one step back330 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 331–332why, one step back331 resp = requests.Response()332 resp.raw = io.BytesIO(b"the content")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 333why, one step back333 resp.request = prepAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 334–339why, one step back334 setattr(resp.raw, "release_conn", lambda *args: args)335336 # Mimic a redirect response337 resp.status_code = 302338 resp.headers["location"] = httpbin("get")339Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 340why, one step back340 # Run request through resolve_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 341–345why, one step back341 next_resp = next(ses.resolve_redirects(resp, prep))342 assert next_resp.request.body is None343 for header in purged_headers:344 assert header not in next_resp.request.headers345Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 346–347why, one step back346 def test_fragment_maintained_on_redirect(self, httpbin):347 fragment = "#view=edit&token=hunter2"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 348–349why, one step back348 r = requests.get(httpbin("redirect-to?url=get") + fragment)349Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 350why, one step back350 assert len(r.history) > 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 351–353why, one step back351 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment352 assert r.url == httpbin("get") + fragment353Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 354why, one step back354 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 355–361why, one step back355 heads = {"User-agent": "Mozilla/5.0"}356357 r = requests.get(httpbin("user-agent"), headers=heads)358359 assert heads["User-agent"] in r.text360 assert r.status_code == 200361Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 362why, one step back362 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 363–369why, one step back363 heads = {"User-agent": "Mozilla/5.0"}364365 r = requests.get(366 httpbin("get") + "?test=true", params={"q": "test"}, headers=heads367 )368 assert r.status_code == 200369Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 370why, one step back370 def test_set_cookie_on_301(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 371–375why, one step back371 s = requests.session()372 url = httpbin("cookies/set?foo=bar")373 s.get(url)374 assert s.cookies["foo"] == "bar"375Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 376why, one step back376 def test_cookie_sent_on_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 377–381why, one step back377 s = requests.session()378 s.get(httpbin("cookies/set?foo=bar"))379 r = s.get(httpbin("redirect/1")) # redirects to httpbin('get')380 assert "Cookie" in r.json()["headers"]381Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 382why, one step back382 def test_cookie_removed_on_expire(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 383–385why, one step back383 s = requests.session()384 s.get(httpbin("cookies/set?foo=bar"))385 assert s.cookies["foo"] == "bar"Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 386why, one step back386 s.get(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 387–391why, one step back387 httpbin("response-headers"),388 params={"Set-Cookie": "foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT"},389 )390 assert "foo" not in s.cookies391Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 392why, one step back392 def test_cookie_quote_wrapped(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 393why, one step back393 s = requests.session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 394why, one step back394 s.get(httpbin('cookies/set?foo="bar:baz"'))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 395–396why, one step back395 assert s.cookies["foo"] == '"bar:baz"'396Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 397why, one step back397 def test_cookie_persists_via_api(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 398–402why, one step back398 s = requests.session()399 r = s.get(httpbin("redirect/1"), cookies={"foo": "bar"})400 assert "foo" in r.request.headers["Cookie"]401 assert "foo" in r.history[0].request.headers["Cookie"]402Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 403why, one step back403 def test_request_cookie_overrides_session_cookie(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 404–407why, one step back404 s = requests.session()405 s.cookies["foo"] = "bar"406 r = s.get(httpbin("cookies"), cookies={"foo": "baz"})407 assert r.json()["cookies"]["foo"] == "baz"Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 408why, one step back408 # Session cookie should not be modifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 409–410why, one step back409 assert s.cookies["foo"] == "bar"410Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 411why, one step back411 def test_request_cookies_not_persisted(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 412–413why, one step back412 s = requests.session()413 s.get(httpbin("cookies"), cookies={"foo": "baz"})Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 414–415why, one step back414 # Sending a request with cookies should not add cookies to the session415 assert not s.cookiesAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 416why, one step back416Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 417why, one step back417 def test_generic_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 418–420why, one step back418 cj = cookielib.CookieJar()419 cookiejar_from_dict({"foo": "bar"}, cj)420 s = requests.session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 421why, one step back421 s.cookies = cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 422–424why, one step back422 r = s.get(httpbin("cookies"))423 # Make sure the cookie was sent424 assert r.json()["cookies"]["foo"] == "bar"Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 425–426why, one step back425 # Make sure the session cj is still the custom one426 assert s.cookies is cjAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 427why, one step back427Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 428why, one step back428 def test_param_cookiejar_works(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 429–435why, one step back429 cj = cookielib.CookieJar()430 cookiejar_from_dict({"foo": "bar"}, cj)431 s = requests.session()432 r = s.get(httpbin("cookies"), cookies=cj)433 # Make sure the cookie was sent434 assert r.json()["cookies"]["foo"] == "bar"435Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 436–438why, one step back436 def test_cookielib_cookiejar_on_redirect(self, httpbin):437 """Tests resolve_redirect doesn't fail when merging cookies438 with non-RequestsCookieJar cookiejar.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 439why, one step back439Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 440why, one step back440 See GH #3579Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 441–445why, one step back441 """442 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())443 s = requests.Session()444 s.cookies = cookiejar_from_dict({"cookie": "tasty"})445Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 446why, one step back446 # Prepare request without using SessionAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 447why, one step back447 req = requests.Request("GET", httpbin("headers"), cookies=cj)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 448why, one step back448 prep_req = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 449why, one step back449Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 450–451why, one step back450 # Send request and simulate redirect451 resp = s.send(prep_req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 452–453why, one step back452 resp.status_code = 302453 resp.headers["location"] = httpbin("get")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 454–455why, one step back454 redirects = s.resolve_redirects(resp, prep_req)455 resp = next(redirects)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 456why, one step back456Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 457–460why, one step back457 # Verify CookieJar isn't being converted to RequestsCookieJar458 assert isinstance(prep_req._cookies, cookielib.CookieJar)459 assert isinstance(resp.request._cookies, cookielib.CookieJar)460 assert not isinstance(resp.request._cookies, requests.cookies.RequestsCookieJar)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 461why, one step back461Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 462–464why, one step back462 cookies = {}463 for c in resp.request._cookies:464 cookies[c.name] = c.valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 465–467why, one step back465 assert cookies["foo"] == "bar"466 assert cookies["cookie"] == "tasty"467Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 468why, one step back468 def test_requests_in_history_are_not_overridden(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 469why, one step back469 resp = requests.get(httpbin("redirect/3"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 470–472why, one step back470 urls = [r.url for r in resp.history]471 req_urls = [r.request.url for r in resp.history]472 assert urls == req_urlsAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 473why, one step back473Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 474–475why, one step back474 def test_history_is_always_a_list(self, httpbin):475 """Show that even with redirects, Response.history is always a list."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 476–479why, one step back476 resp = requests.get(httpbin("get"))477 assert isinstance(resp.history, list)478 resp = requests.get(httpbin("redirect/1"))479 assert isinstance(resp.history, list)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 480why, one step back480 assert not isinstance(resp.history, tuple)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 481why, one step back481Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 482–483why, one step back482 def test_headers_on_session_with_None_are_not_sent(self, httpbin):483 """Do not send headers in Session.headers with None values."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 484–489why, one step back484 ses = requests.Session()485 ses.headers["Accept-Encoding"] = None486 req = requests.Request("GET", httpbin("get"))487 prep = ses.prepare_request(req)488 assert "Accept-Encoding" not in prep.headers489Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 490–491why, one step back490 def test_headers_preserve_order(self, httpbin):491 """Preserve order when headers provided as OrderedDict."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 492why, one step back492 ses = requests.Session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 493why, one step back493 ses.headers = collections.OrderedDict()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 494–501why, one step back494 ses.headers["Accept-Encoding"] = "identity"495 ses.headers["First"] = "1"496 ses.headers["Second"] = "2"497 headers = collections.OrderedDict([("Third", "3"), ("Fourth", "4")])498 headers["Fifth"] = "5"499 headers["Second"] = "222"500 req = requests.Request("GET", httpbin("get"), headers=headers)501 prep = ses.prepare_request(req)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 502why, one step back502 items = list(prep.headers.items())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 503–510why, one step back503 assert items[0] == ("Accept-Encoding", "identity")504 assert items[1] == ("First", "1")505 assert items[2] == ("Second", "222")506 assert items[3] == ("Third", "3")507 assert items[4] == ("Fourth", "4")508 assert items[5] == ("Fifth", "5")509510 @pytest.mark.parametrize("key", ("User-agent", "user-agent"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 511why, one step back511 def test_user_agent_transfers(self, httpbin, key):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 512–514why, one step back512 heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}513514 r = requests.get(httpbin("user-agent"), headers=heads)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 515why, one step back515 assert heads[key] in r.textAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 516why, one step back516Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 517why, one step back517 def test_HTTP_200_OK_HEAD(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 518–520why, one step back518 r = requests.head(httpbin("get"))519 assert r.status_code == 200520Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 521why, one step back521 def test_HTTP_200_OK_PUT(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 522–524why, one step back522 r = requests.put(httpbin("put"))523 assert r.status_code == 200524Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 525why, one step back525 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 526–528why, one step back526 auth = ("user", "pass")527 url = httpbin("basic-auth", "user", "pass")528Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 529why, one step back529 r = requests.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 530–531why, one step back530 assert r.status_code == 200531Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 532–533why, one step back532 r = requests.get(url)533 assert r.status_code == 401Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 534–535why, one step back534535 s = requests.session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 536–537why, one step back536 s.auth = auth537 r = s.get(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 538–544why, one step back538 assert r.status_code == 200539540 @pytest.mark.parametrize(541 "username, password",542 (543 ("user", "pass"),544 ("имя".encode(), "пароль".encode()),Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 545–546why, one step back545 (42, 42),546 (None, None),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 547–548why, one step back547 ),548 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 549–550why, one step back549 def test_set_basicauth(self, httpbin, username, password):550 auth = (username, password)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 551–557why, one step back551 url = httpbin("get")552553 r = requests.Request("GET", url, auth=auth)554 p = r.prepare()555556 assert p.headers["Authorization"] == _basic_auth_str(username, password)557Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 558–560why, one step back558 def test_basicauth_encodes_byte_strings(self):559 """Ensure b'test' formats as the byte string "test" rather560 than the unicode string "b'test'" in Python 3.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 561–570why, one step back561 """562 auth = (b"\xc5\xafsername", b"test\xc6\xb6")563 r = requests.Request("GET", "http://localhost", auth=auth)564 p = r.prepare()565566 assert p.headers["Authorization"] == "Basic xa9zZXJuYW1lOnRlc3TGtg=="567568 @pytest.mark.parametrize(569 "url, exception",570 (Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 571why, one step back571 # Connecting to an unknown domain should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 572why, one step back572 ("http://doesnotexist.google.com", ConnectionError),Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 573why, one step back573 # Connecting to an invalid port should raise a ConnectionErrorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 574why, one step back574 ("http://localhost:1", ConnectionError),Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 575why, one step back575 # Inputing a URL that cannot be parsed should raise an InvalidURL errorAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 576–578why, one step back576 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),577 ),578 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 579why, one step back579 def test_errors(self, url, exception):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 580why, one step back580 with pytest.raises(exception):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 581why, one step back581 requests.get(url, timeout=1)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 582why, one step back582Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 583–585why, one step back583 def test_proxy_error(self):584 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError585 with pytest.raises(ProxyError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 586–589why, one step back586 requests.get(587 "http://localhost:1", proxies={"http": "non-resolvable-address"}588 )589Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 590why, one step back590 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 591–602why, one step back591 with pytest.raises(InvalidProxyURL):592 requests.get(httpbin_secure(), proxies={"https": "http:/badproxyurl:3128"})593594 with pytest.raises(InvalidProxyURL):595 requests.get(httpbin(), proxies={"http": "http://:8080"})596597 with pytest.raises(InvalidProxyURL):598 requests.get(httpbin_secure(), proxies={"https": "https://"})599600 with pytest.raises(InvalidProxyURL):601 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})602Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 603why, one step back603 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 604–609why, one step back604 with override_environ(http_proxy=INVALID_PROXY):605 with pytest.raises(ProxyError):606 session = requests.Session()607 request = requests.Request("GET", httpbin())608 session.send(request.prepare())609Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 610why, one step back610 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 611–614why, one step back611 with override_environ(http_proxy=INVALID_PROXY):612 with pytest.raises(ProxyError):613 session = requests.Session()614 request = requests.Request("GET", httpbin())Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
lines 615–616why, one step back615 prepared = session.prepare_request(request)616 session.send(prepared)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 617why, one step back617Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 618why, one step back618 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 619–622why, one step back619 with override_environ(http_proxy=INVALID_PROXY):620 with pytest.raises(ProxyError):621 session = requests.Session()622 url = httpbin("redirect/1")Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 623why, one step back623 print(url)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 624–626why, one step back624 request = requests.Request("GET", url)625 session.send(request.prepare())626Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 627why, one step back627 def test_respect_proxy_env_on_get(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 628–630why, one step back628 with override_environ(http_proxy=INVALID_PROXY):629 with pytest.raises(ProxyError):630 session = requests.Session()Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 631why, one step back631 session.get(httpbin())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 632why, one step back632Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9
line 633why, one step back633 def test_respect_proxy_env_on_request(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 634–638why, one step back634 with override_environ(http_proxy=INVALID_PROXY):635 with pytest.raises(ProxyError):636 session = requests.Session()637 session.request(method="GET", url=httpbin())638Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
lines 639–640why, one step back639 def test_proxy_authorization_preserved_on_request(self, httpbin):640 proxy_auth_value = "Bearer XXX"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 641why, one step back641 session = requests.Session()Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
line 642why, one step back642 session.headers.update({"Proxy-Authorization": proxy_auth_value})Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 643–645why, one step back643 resp = session.request(method="GET", url=httpbin("get"))644 sent_headers = resp.json().get("headers", {})645Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49
line 646why, one step back646 assert sent_headers.get("Proxy-Authorization") == proxy_auth_valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 647why, one step back647Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 648–650why, one step back648 @pytest.mark.parametrize(649 "url,has_proxy_auth",650 (Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 651–652why, one step back651 ("http://example.com", True),652 ("https://example.com", False),Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 653–654why, one step back653 ),654 )Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 655–657why, one step back655 def test_proxy_authorization_not_appended_to_https_request(656 self, url, has_proxy_auth657 ):Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 658–659why, one step back658 session = requests.Session()659 proxies = {Fix linting issuesNate Prewittbefore adoption6e5b15d
lines 660–661why, one step back660 "http": "http://test:pass@localhost:8080",661 "https": "http://test:pass@localhost:8090",Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
line 662why, one step back662 }Fix linting issuesNate Prewittbefore adoption6e5b15d
line 663why, one step back663 req = requests.Request("GET", url)Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
lines 664–666why, one step back664 prep = req.prepare()665 session.rebuild_proxies(prep, proxies)666Fix linting issuesNate Prewittbefore adoption6e5b15d
line 667why, one step back667 assert ("Proxy-Authorization" in prep.headers) is has_proxy_authMerge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf
line 668why, one step back668Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 669why, one step back669 def test_basicauth_with_netrc(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 670–673why, one step back670 auth = ("user", "pass")671 wrong_auth = ("wronguser", "wrongpass")672 url = httpbin("basic-auth", "user", "pass")673Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 674why, one step back674 old_auth = requests.sessions.get_netrc_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 675–677why, one step back675676 try:677Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 678–679why, one step back678 def get_netrc_auth_mock(url):679 return authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 680why, one step back680Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 681why, one step back681 requests.sessions.get_netrc_auth = get_netrc_auth_mockAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 682–687why, one step back682683 # Should use netrc and work.684 r = requests.get(url)685 assert r.status_code == 200686687 # Given auth should override and fail.Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 688why, one step back688 r = requests.get(url, auth=wrong_auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 689–697why, one step back689 assert r.status_code == 401690691 s = requests.session()692693 # Should use netrc and work.694 r = s.get(url)695 assert r.status_code == 200696697 # Given auth should override and fail.Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 698why, one step back698 s.auth = wrong_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 699–700why, one step back699 r = s.get(url)700 assert r.status_code == 401Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 701–702why, one step back701 finally:702 requests.sessions.get_netrc_auth = old_authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 703why, one step back703Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 704why, one step back704 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 705–720why, one step back705 for authtype in self.digest_auth_algo:706 auth = HTTPDigestAuth("user", "pass")707 url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")708709 r = requests.get(url, auth=auth)710 assert r.status_code == 200711712 r = requests.get(url)713 assert r.status_code == 401714 print(r.headers["WWW-Authenticate"])715716 s = requests.session()717 s.auth = HTTPDigestAuth("user", "pass")718 r = s.get(url)719 assert r.status_code == 200720Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 721why, one step back721 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 722–730why, one step back722 for authtype in self.digest_auth_algo:723 url = httpbin("digest-auth", "auth", "user", "pass", authtype)724 auth = HTTPDigestAuth("user", "pass")725 r = requests.get(url)726 assert r.cookies["fake"] == "fake_value"727728 r = requests.get(url, auth=auth)729 assert r.status_code == 200730Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 731why, one step back731 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 732–734why, one step back732 for authtype in self.digest_auth_algo:733 url = httpbin("digest-auth", "auth", "user", "pass", authtype)734 auth = HTTPDigestAuth("user", "pass")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 735–736why, one step back735 s = requests.Session()736 s.get(url, auth=auth)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 737–738why, one step back737 assert s.cookies["fake"] == "fake_value"738Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 739why, one step back739 def test_DIGEST_STREAM(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 740–743why, one step back740 for authtype in self.digest_auth_algo:741 auth = HTTPDigestAuth("user", "pass")742 url = httpbin("digest-auth", "auth", "user", "pass", authtype)743Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 744why, one step back744 r = requests.get(url, auth=auth, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 745–746why, one step back745 assert r.raw.read() != b""746Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 747why, one step back747 r = requests.get(url, auth=auth, stream=False)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 748–749why, one step back748 assert r.raw.read() == b""749Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 750why, one step back750 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 751–761why, one step back751 for authtype in self.digest_auth_algo:752 auth = HTTPDigestAuth("user", "wrongpass")753 url = httpbin("digest-auth", "auth", "user", "pass", authtype)754755 r = requests.get(url, auth=auth)756 assert r.status_code == 401757758 r = requests.get(url)759 assert r.status_code == 401760761 s = requests.session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 762why, one step back762 s.auth = authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 763–765why, one step back763 r = s.get(url)764 assert r.status_code == 401765Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 766why, one step back766 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 767–773why, one step back767 for authtype in self.digest_auth_algo:768 auth = HTTPDigestAuth("user", "pass")769 url = httpbin("digest-auth", "auth", "user", "pass", authtype)770771 r = requests.get(url, auth=auth)772 assert '"auth"' in r.request.headers["Authorization"]773Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 774why, one step back774 def test_POSTBIN_GET_POST_FILES(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 775–790why, one step back775 url = httpbin("post")776 requests.post(url).raise_for_status()777778 post1 = requests.post(url, data={"some": "data"})779 assert post1.status_code == 200780781 with open("requirements-dev.txt") as f:782 post2 = requests.post(url, files={"some": f})783 assert post2.status_code == 200784785 post4 = requests.post(url, data='[{"some": "json"}]')786 assert post4.status_code == 200787788 with pytest.raises(ValueError):789 requests.post(url, files=["bad file data"])790Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 791why, one step back791 def test_invalid_files_input(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 792–793why, one step back792 url = httpbin("post")793 post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 794–795why, one step back794 assert b'name="random-file-1"' not in post.request.body795 assert b'name="random-file-2"' in post.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 796why, one step back796Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 797why, one step back797 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 798–799why, one step back798 class TestStream:799 def __init__(self, data):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 800–802why, one step back800 self.data = data.encode()801 self.length = len(self.data)802 self.index = 0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 803–804why, one step back803804 def __len__(self):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 805why, one step back805 return self.lengthAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 806why, one step back806Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 807–808why, one step back807 def read(self, size=None):808 if size:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 809why, one step back809 ret = self.data[self.index : self.index + size]Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 810–811why, one step back810 self.index += size811 else:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 812why, one step back812 ret = self.data[self.index :]Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 813–814why, one step back813 self.index = self.length814 return retAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 815–816why, one step back815816 def tell(self):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 817why, one step back817 return self.indexAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 818why, one step back818Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 819–825why, one step back819 def seek(self, offset, where=0):820 if where == 0:821 self.index = offset822 elif where == 1:823 self.index += offset824 elif where == 2:825 self.index = self.length + offsetAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 826–832why, one step back826827 test = TestStream("test")828 post1 = requests.post(httpbin("post"), data=test)829 assert post1.status_code == 200830 assert post1.json()["data"] == "test"831832 test = TestStream("test")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 833why, one step back833 test.seek(2)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 834–837why, one step back834 post2 = requests.post(httpbin("post"), data=test)835 assert post2.status_code == 200836 assert post2.json()["data"] == "st"837Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 838why, one step back838 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 839–854why, one step back839 url = httpbin("post")840 requests.post(url).raise_for_status()841842 post1 = requests.post(url, data={"some": "data"})843 assert post1.status_code == 200844845 with open("requirements-dev.txt") as f:846 post2 = requests.post(url, data={"some": "data"}, files={"some": f})847 assert post2.status_code == 200848849 post4 = requests.post(url, data='[{"some": "json"}]')850 assert post4.status_code == 200851852 with pytest.raises(ValueError):853 requests.post(url, files=["bad file data"])854Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 855–858why, one step back855 def test_post_with_custom_mapping(self, httpbin):856 class CustomMapping(MutableMapping):857 def __init__(self, *args, **kwargs):858 self.data = dict(*args, **kwargs)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 859why, one step back859Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 860–861why, one step back860 def __delitem__(self, key):861 del self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 862why, one step back862Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 863–864why, one step back863 def __getitem__(self, key):864 return self.data[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 865why, one step back865Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 866–867why, one step back866 def __setitem__(self, key, value):867 self.data[key] = valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 868–869why, one step back868869 def __iter__(self):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 870why, one step back870 return iter(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 871–872why, one step back871872 def __len__(self):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 873why, one step back873 return len(self.data)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 874–879why, one step back874875 data = CustomMapping({"some": "data"})876 url = httpbin("post")877 found_json = requests.post(url, data=data).json().get("form")878 assert found_json == {"some": "data"}879Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 880why, one step back880 def test_conflicting_post_params(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 881–882why, one step back881 url = httpbin("post")882 with open("requirements-dev.txt") as f:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 883why, one step back883 with pytest.raises(ValueError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 884–885why, one step back884 requests.post(url, data='[{"some": "data"}]', files={"some": f})885Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 886why, one step back886 def test_request_ok_set(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 887–889why, one step back887 r = requests.get(httpbin("status", "404"))888 assert not r.ok889Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 890why, one step back890 def test_status_raising(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 891why, one step back891 r = requests.get(httpbin("status", "404"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 892why, one step back892 with pytest.raises(requests.exceptions.HTTPError):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 893–897why, one step back893 r.raise_for_status()894895 r = requests.get(httpbin("status", "500"))896 assert not r.ok897Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 898why, one step back898 def test_decompress_gzip(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 899–911why, one step back899 r = requests.get(httpbin("gzip"))900 r.content.decode("ascii")901902 @pytest.mark.parametrize(903 "url, params",904 (905 ("/get", {"foo": "føø"}),906 ("/get", {"føø": "føø"}),907 ("/get", {"føø": "føø"}),908 ("/get", {"foo": "foo"}),909 ("ø", {"foo": "foo"}),910 ),911 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 912–913why, one step back912 def test_unicode_get(self, httpbin, url, params):913 requests.get(httpbin(url), params=params)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 914why, one step back914Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 915–916why, one step back915 def test_unicode_header_name(self, httpbin):916 requests.put(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 917–921why, one step back917 httpbin("put"),918 headers={"Content-Type": "application/octet-stream"},919 data="\xff",920 ) # compat.str is unicode.921Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 922why, one step back922 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 923–924why, one step back923 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)924Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 925why, one step back925 def test_invalid_ca_certificate_path(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 926–927why, one step back926 INVALID_PATH = "/garbage"927 with pytest.raises(IOError) as e:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 928why, one step back928 requests.get(httpbin_secure(), verify=INVALID_PATH)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 929–934why, one step back929 assert str(930 e.value931 ) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format(932 INVALID_PATH933 )934Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 935why, one step back935 def test_invalid_ssl_certificate_files(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 936–937why, one step back936 INVALID_PATH = "/garbage"937 with pytest.raises(IOError) as e:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 938why, one step back938 requests.get(httpbin_secure(), cert=INVALID_PATH)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 939–953why, one step back939 assert str(940 e.value941 ) == "Could not find the TLS certificate file, invalid path: {}".format(942 INVALID_PATH943 )944945 with pytest.raises(IOError) as e:946 requests.get(httpbin_secure(), cert=(".", INVALID_PATH))947 assert str(e.value) == (948 f"Could not find the TLS key file, invalid path: {INVALID_PATH}"949 )950951 @pytest.mark.parametrize(952 "env, expected",953 (Merge pull request #6074 from nateprewitt/curl_ca_bundleIan Stapleton Cordascobefore adoption79f6027
line 954why, one step back954 ({}, True),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 955–975why, one step back955 ({"REQUESTS_CA_BUNDLE": "/some/path"}, "/some/path"),956 ({"REQUESTS_CA_BUNDLE": ""}, True),957 ({"CURL_CA_BUNDLE": "/some/path"}, "/some/path"),958 ({"CURL_CA_BUNDLE": ""}, True),959 ({"REQUESTS_CA_BUNDLE": "", "CURL_CA_BUNDLE": ""}, True),960 (961 {962 "REQUESTS_CA_BUNDLE": "/some/path",963 "CURL_CA_BUNDLE": "/curl/path",964 },965 "/some/path",966 ),967 (968 {969 "REQUESTS_CA_BUNDLE": "",970 "CURL_CA_BUNDLE": "/curl/path",971 },972 "/curl/path",973 ),974 ),975 )Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 976why, one step back976 def test_env_cert_bundles(self, httpbin, env, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 977why, one step back977 s = requests.Session()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
lines 978–981why, one step back978 with mock.patch("os.environ", env):979 settings = s.merge_environment_settings(980 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None981 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 982–983why, one step back982 assert settings["verify"] == expected983Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 984why, one step back984 def test_http_with_certificate(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 985–987why, one step back985 r = requests.get(httpbin(), cert=".")986 assert r.status_code == 200987Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590
lines 988–991why, one step back988 @pytest.mark.skipif(989 SNIMissingWarning is None,990 reason="urllib3 2.0 removed that warning and errors out instead",991 )Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba
line 992why, one step back992 def test_https_warnings(self, nosan_server):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 993why, one step back993 """warnings are emitted with requests.get"""Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba
line 994why, one step back994 host, port, ca_bundle = nosan_serverMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 995why, one step back995 if HAS_MODERN_SSL or HAS_PYOPENSSL:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 996–1003why, one step back996 warnings_expected = ("SubjectAltNameWarning",)997 else:998 warnings_expected = (999 "SNIMissingWarning",1000 "InsecurePlatformWarning",1001 "SubjectAltNameWarning",1002 )1003Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1004why, one step back1004 with pytest.warns(None) as warning_records:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1005–1014why, one step back1005 warnings.simplefilter("always")1006 requests.get(f"https://localhost:{port}/", verify=ca_bundle)10071008 warning_records = [1009 item1010 for item in warning_records1011 if item.category.__name__ != "ResourceWarning"1012 ]10131014 warnings_category = tuple(item.category.__name__ for item in warning_records)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1015why, one step back1015 assert warnings_category == warnings_expectedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1016why, one step back1016Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1017why, one step back1017 def test_certificate_failure(self, httpbin_secure):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1018why, one step back1018 """Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1019why, one step back1019 When underlying SSL problems occur, an SSLError is raised.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1020why, one step back1020 """Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1021why, one step back1021 with pytest.raises(RequestsSSLError):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1022–1023why, one step back1022 # Our local httpbin does not have a trusted CA, so this call will1023 # fail if we use our default trust bundle.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1024–1025why, one step back1024 requests.get(httpbin_secure("status", "200"))1025Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1026why, one step back1026 def test_urlencoded_get_query_multivalued_param(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1027–1030why, one step back1027 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})1028 assert r.status_code == 2001029 assert r.url == httpbin("get?test=foo&test=baz")1030Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1031why, one step back1031 def test_form_encoded_post_query_multivalued_element(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1032–1037why, one step back1032 r = requests.Request(1033 method="POST", url=httpbin("post"), data=dict(test=["foo", "baz"])1034 )1035 prep = r.prepare()1036 assert prep.body == "test=foo&test=baz"1037Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1038why, one step back1038 def test_different_encodings_dont_break_post(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1039–1045why, one step back1039 with open(__file__, "rb") as f:1040 r = requests.post(1041 httpbin("post"),1042 data={"stuff": json.dumps({"a": 123})},1043 params={"blah": "asdf1234"},1044 files={"file": ("test_requests.py", f)},1045 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1046–1056why, one step back1046 assert r.status_code == 20010471048 @pytest.mark.parametrize(1049 "data",1050 (1051 {"stuff": "ëlïxr"},1052 {"stuff": "ëlïxr".encode()},1053 {"stuff": "elixr"},1054 {"stuff": b"elixr"},1055 ),1056 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1057why, one step back1057 def test_unicode_multipart_post(self, httpbin, data):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1058–1063why, one step back1058 with open(__file__, "rb") as f:1059 r = requests.post(1060 httpbin("post"),1061 data=data,1062 files={"file": ("test_requests.py", f)},1063 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1064–1065why, one step back1064 assert r.status_code == 2001065Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1066why, one step back1066 def test_unicode_multipart_post_fieldnames(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1067why, one step back1067 filename = os.path.splitext(__file__)[0] + ".py"Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1068–1076why, one step back1068 with open(filename, "rb") as f:1069 r = requests.Request(1070 method="POST",1071 url=httpbin("post"),1072 data={b"stuff": "elixr"},1073 files={"file": ("test_requests.py", f)},1074 )1075 prep = r.prepare()1076Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1077why, one step back1077 assert b'name="stuff"' in prep.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1078–1079why, one step back1078 assert b"name=\"b'stuff'\"" not in prep.body1079Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1080why, one step back1080 def test_unicode_method_name(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1081–1087why, one step back1081 with open(__file__, "rb") as f:1082 files = {"file": f}1083 r = requests.request(1084 method="POST",1085 url=httpbin("post"),1086 files=files,1087 )Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1088–1089why, one step back1088 assert r.status_code == 2001089Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1090why, one step back1090 def test_unicode_method_name_with_request_object(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1091why, one step back1091 s = requests.Session()Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1092–1095why, one step back1092 with open(__file__, "rb") as f:1093 files = {"file": f}1094 req = requests.Request("POST", httpbin("post"), files=files)1095 prep = s.prepare_request(req)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1096why, one step back1096 assert isinstance(prep.method, builtin_str)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1097–1101why, one step back1097 assert prep.method == "POST"10981099 resp = s.send(prep)1100 assert resp.status_code == 2001101Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1102why, one step back1102 def test_non_prepared_request_error(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1103–1106why, one step back1103 s = requests.Session()1104 req = requests.Request("POST", "/")11051106 with pytest.raises(ValueError) as e:Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1107why, one step back1107 s.send(req)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1108–1109why, one step back1108 assert str(e.value) == "You can only send PreparedRequests."1109Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1110why, one step back1110 def test_custom_content_type(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1111–1112why, one step back1111 with open(__file__, "rb") as f1:1112 with open(__file__, "rb") as f2:Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1113why, one step back1113 data = {"stuff": json.dumps({"a": 123})}Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1114–1118why, one step back1114 files = {1115 "file1": ("test_requests.py", f1),1116 "file2": ("test_requests", f2, "text/py-content-type"),1117 }1118 r = requests.post(httpbin("post"), data=data, files=files)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1119why, one step back1119 assert r.status_code == 200Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1120why, one step back1120 assert b"text/py-content-type" in r.request.bodyAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1121why, one step back1121Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1122why, one step back1122 def test_hook_receives_request_arguments(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1123why, one step back1123 def hook(resp, **kwargs):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1124–1125why, one step back1124 assert resp is not None1125 assert kwargs != {}Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1126–1129why, one step back11261127 s = requests.Session()1128 r = requests.Request("GET", httpbin(), hooks={"response": hook})1129 prep = s.prepare_request(r)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1130why, one step back1130 s.send(prep)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1131why, one step back1131Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1132why, one step back1132 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1133–1142why, one step back1133 def hook(*args, **kwargs):1134 pass11351136 s = requests.Session()1137 s.hooks["response"].append(hook)1138 r = requests.Request("GET", httpbin())1139 prep = s.prepare_request(r)1140 assert prep.hooks["response"] != []1141 assert prep.hooks["response"] == [hook]1142Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1143why, one step back1143 def test_session_hooks_are_overridden_by_request_hooks(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1144–1149why, one step back1144 def hook1(*args, **kwargs):1145 pass11461147 def hook2(*args, **kwargs):1148 pass1149Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1150why, one step back1150 assert hook1 is not hook2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1151–1156why, one step back1151 s = requests.Session()1152 s.hooks["response"].append(hook2)1153 r = requests.Request("GET", httpbin(), hooks={"response": [hook1]})1154 prep = s.prepare_request(r)1155 assert prep.hooks["response"] == [hook1]1156Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1157why, one step back1157 def test_prepared_request_hook(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1158why, one step back1158 def hook(resp, **kwargs):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1159why, one step back1159 resp.hook_working = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1160–1162why, one step back1160 return resp11611162 req = requests.Request("GET", httpbin(), hooks={"response": hook})Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1163why, one step back1163 prep = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1164–1170why, one step back11641165 s = requests.Session()1166 s.proxies = getproxies()1167 resp = s.send(prep)11681169 assert hasattr(resp, "hook_working")1170Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1171–1173why, one step back1171 def test_prepared_from_session(self, httpbin):1172 class DummyAuth(requests.auth.AuthBase):1173 def __call__(self, r):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1174why, one step back1174 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1175why, one step back1175 return rAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1176–1177why, one step back11761177 req = requests.Request("GET", httpbin("headers"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1178why, one step back1178 assert not req.authAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1179–1180why, one step back11791180 s = requests.Session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1181why, one step back1181 s.auth = DummyAuth()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1182–1187why, one step back11821183 prep = s.prepare_request(req)1184 resp = s.send(prep)11851186 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1187Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1188why, one step back1188 def test_prepare_request_with_bytestring_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1189–1191why, one step back1189 req = requests.Request("GET", b"https://httpbin.org/")1190 s = requests.Session()1191 prep = s.prepare_request(req)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1192why, one step back1192 assert prep.url == "https://httpbin.org/"Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1193why, one step back1193Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1194why, one step back1194 def test_request_with_bytestring_host(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1195why, one step back1195 s = requests.Session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1196why, one step back1196 resp = s.request(Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1197–1198why, one step back1197 "GET",1198 httpbin("cookies/set?cookie=value"),Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1199why, one step back1199 allow_redirects=False,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1200–1203why, one step back1200 headers={"Host": b"httpbin.org"},1201 )1202 assert resp.cookies.get("cookie") == "value"1203Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1204why, one step back1204 def test_links(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1205why, one step back1205 r = requests.Response()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1206why, one step back1206 r.headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1207–1229why, one step back1207 "cache-control": "public, max-age=60, s-maxage=60",1208 "connection": "keep-alive",1209 "content-encoding": "gzip",1210 "content-type": "application/json; charset=utf-8",1211 "date": "Sat, 26 Jan 2013 16:47:56 GMT",1212 "etag": '"6ff6a73c0e446c1f61614769e3ceb778"',1213 "last-modified": "Sat, 26 Jan 2013 16:22:39 GMT",1214 "link": (1215 "<https://api.github.com/users/kennethreitz/repos?"1216 'page=2&per_page=10>; rel="next", <https://api.github.'1217 "com/users/kennethreitz/repos?page=7&per_page=10>; "1218 ' rel="last"'1219 ),1220 "server": "GitHub.com",1221 "status": "200 OK",1222 "vary": "Accept",1223 "x-content-type-options": "nosniff",1224 "x-github-media-type": "github.beta",1225 "x-ratelimit-limit": "60",1226 "x-ratelimit-remaining": "57",1227 }1228 assert r.links["next"]["rel"] == "next"1229Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1230why, one step back1230 def test_cookie_parameters(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1231–1232why, one step back1231 key = "some_cookie"1232 value = "some_value"Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1233why, one step back1233 secure = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1234–1237why, one step back1234 domain = "test.com"1235 rest = {"HttpOnly": True}12361237 jar = requests.cookies.RequestsCookieJar()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1238why, one step back1238 jar.set(key, value, secure=secure, domain=domain, rest=rest)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1239why, one step back1239Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1240why, one step back1240 assert len(jar) == 1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1241–1242why, one step back1241 assert "some_cookie" in jar1242Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1243–1245why, one step back1243 cookie = list(jar)[0]1244 assert cookie.secure == secure1245 assert cookie.domain == domainAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1246–1247why, one step back1246 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]1247Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1248why, one step back1248 def test_cookie_as_dict_keeps_len(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1249–1262why, one step back1249 key = "some_cookie"1250 value = "some_value"12511252 key1 = "some_cookie1"1253 value1 = "some_value1"12541255 jar = requests.cookies.RequestsCookieJar()1256 jar.set(key, value)1257 jar.set(key1, value1)12581259 d1 = dict(jar)1260 d2 = dict(jar.iteritems())1261 d3 = dict(jar.items())1262Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1263–1266why, one step back1263 assert len(jar) == 21264 assert len(d1) == 21265 assert len(d2) == 21266 assert len(d3) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1267why, one step back1267Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1268why, one step back1268 def test_cookie_as_dict_keeps_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1269–1286why, one step back1269 key = "some_cookie"1270 value = "some_value"12711272 key1 = "some_cookie1"1273 value1 = "some_value1"12741275 jar = requests.cookies.RequestsCookieJar()1276 jar.set(key, value)1277 jar.set(key1, value1)12781279 d1 = dict(jar)1280 d2 = dict(jar.iteritems())1281 d3 = dict(jar.items())12821283 assert d1["some_cookie"] == "some_value"1284 assert d2["some_cookie"] == "some_value"1285 assert d3["some_cookie1"] == "some_value1"1286Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1287why, one step back1287 def test_cookie_as_dict_keys(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1288–1297why, one step back1288 key = "some_cookie"1289 value = "some_value"12901291 key1 = "some_cookie1"1292 value1 = "some_value1"12931294 jar = requests.cookies.RequestsCookieJar()1295 jar.set(key, value)1296 jar.set(key1, value1)1297Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1298–1301why, one step back1298 keys = jar.keys()1299 assert keys == list(keys)1300 # make sure one can use keys multiple times1301 assert list(keys) == list(keys)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1302why, one step back1302Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1303why, one step back1303 def test_cookie_as_dict_values(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1304–1313why, one step back1304 key = "some_cookie"1305 value = "some_value"13061307 key1 = "some_cookie1"1308 value1 = "some_value1"13091310 jar = requests.cookies.RequestsCookieJar()1311 jar.set(key, value)1312 jar.set(key1, value1)1313Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1314–1317why, one step back1314 values = jar.values()1315 assert values == list(values)1316 # make sure one can use values multiple times1317 assert list(values) == list(values)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1318why, one step back1318Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1319why, one step back1319 def test_cookie_as_dict_items(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1320–1330why, one step back1320 key = "some_cookie"1321 value = "some_value"13221323 key1 = "some_cookie1"1324 value1 = "some_value1"13251326 jar = requests.cookies.RequestsCookieJar()1327 jar.set(key, value)1328 jar.set(key1, value1)13291330 items = jar.items()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1331–1333why, one step back1331 assert items == list(items)1332 # make sure one can use items multiple times1333 assert list(items) == list(items)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1334why, one step back1334Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1335why, one step back1335 def test_cookie_duplicate_names_different_domains(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1336–1341why, one step back1336 key = "some_cookie"1337 value = "some_value"1338 domain1 = "test1.com"1339 domain2 = "test2.com"13401341 jar = requests.cookies.RequestsCookieJar()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1342–1344why, one step back1342 jar.set(key, value, domain=domain1)1343 jar.set(key, value, domain=domain2)1344 assert key in jarAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1345why, one step back1345 items = jar.items()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1346why, one step back1346 assert len(items) == 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1347why, one step back1347Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1348why, one step back1348 # Verify that CookieConflictError is raised if domain is not specifiedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1349–1351why, one step back1349 with pytest.raises(requests.cookies.CookieConflictError):1350 jar.get(key)1351Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1352–1354why, one step back1352 # Verify that CookieConflictError is not raised if domain is specified1353 cookie = jar.get(key, domain=domain1)1354 assert cookie == valueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1355why, one step back1355Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1356why, one step back1356 def test_cookie_duplicate_names_raises_cookie_conflict_error(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1357–1361why, one step back1357 key = "some_cookie"1358 value = "some_value"1359 path = "some_path"13601361 jar = requests.cookies.RequestsCookieJar()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1362why, one step back1362 jar.set(key, value, path=path)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1363–1366why, one step back1363 jar.set(key, value)1364 with pytest.raises(requests.cookies.CookieConflictError):1365 jar.get(key)1366Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1367–1368why, one step back1367 def test_cookie_policy_copy(self):1368 class MyCookiePolicy(cookielib.DefaultCookiePolicy):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1369–1371why, one step back1369 pass13701371 jar = requests.cookies.RequestsCookieJar()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1372–1373why, one step back1372 jar.set_policy(MyCookiePolicy())1373 assert isinstance(jar.copy().get_policy(), MyCookiePolicy)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1374why, one step back1374Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1375why, one step back1375 def test_time_elapsed_blank(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1376why, one step back1376 r = requests.get(httpbin("get"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1377why, one step back1377 td = r.elapsedAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1378–1380why, one step back1378 total_seconds = (1379 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61380 ) / 10**6Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1381why, one step back1381 assert total_seconds > 0.0Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1382why, one step back1382Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1383why, one step back1383 def test_empty_response_has_content_none(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1384–1386why, one step back1384 r = requests.Response()1385 assert r.content is None1386Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1387why, one step back1387 def test_response_is_iterable(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1388–1389why, one step back1388 r = requests.Response()1389 io = StringIO.StringIO("abc")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1390why, one step back1390 read_ = io.readAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1391why, one step back1391Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1392–1393why, one step back1392 def read_mock(amt, decode_content=None):1393 return read_(amt)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1394–1395why, one step back13941395 setattr(io, "read", read_mock)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1396–1398why, one step back1396 r.raw = io1397 assert next(iter(r))1398 io.close()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1399why, one step back1399Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1400–1402why, one step back1400 def test_response_decode_unicode(self):1401 """When called with decode_unicode, Response.iter_content should always1402 return unicode.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1403–1404why, one step back1403 """1404 r = requests.Response()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1405why, one step back1405 r._content_consumed = TrueAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1406–1411why, one step back1406 r._content = b"the content"1407 r.encoding = "ascii"14081409 chunks = r.iter_content(decode_unicode=True)1410 assert all(isinstance(chunk, str) for chunk in chunks)1411Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1412why, one step back1412 # also for streamingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1413–1418why, one step back1413 r = requests.Response()1414 r.raw = io.BytesIO(b"the content")1415 r.encoding = "ascii"1416 chunks = r.iter_content(decode_unicode=True)1417 assert all(isinstance(chunk, str) for chunk in chunks)1418Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1419–1420why, one step back1419 def test_response_reason_unicode(self):1420 # check for unicode HTTP statusAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1421–1423why, one step back1421 r = requests.Response()1422 r.url = "unicode URL"1423 r.reason = "Komponenttia ei löydy".encode()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1424why, one step back1424 r.status_code = 404Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1425why, one step back1425 r.encoding = NoneMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1426why, one step back1426 assert not r.ok # old behaviour - crashes hereAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1427why, one step back1427Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1428–1429why, one step back1428 def test_response_reason_unicode_fallback(self):1429 # check raise_status falls back to ISO-8859-1Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1430–1433why, one step back1430 r = requests.Response()1431 r.url = "some url"1432 reason = "Komponenttia ei löydy"1433 r.reason = reason.encode("latin-1")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1434why, one step back1434 r.status_code = 500Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1435why, one step back1435 r.encoding = NoneMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1436why, one step back1436 with pytest.raises(requests.exceptions.HTTPError) as e:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1437why, one step back1437 r.raise_for_status()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1438why, one step back1438 assert reason in e.value.args[0]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1439why, one step back1439Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1440–1442why, one step back1440 def test_response_chunk_size_type(self):1441 """Ensure that chunk_size is passed as None or an integer, otherwise1442 raise a TypeError.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1443–1445why, one step back1443 """1444 r = requests.Response()1445 r.raw = io.BytesIO(b"the content")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1446–1447why, one step back1446 chunks = r.iter_content(1)1447 assert all(len(chunk) == 1 for chunk in chunks)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1448–1450why, one step back14481449 r = requests.Response()1450 r.raw = io.BytesIO(b"the content")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1451why, one step back1451 chunks = r.iter_content(None)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1452–1456why, one step back1452 assert list(chunks) == [b"the content"]14531454 r = requests.Response()1455 r.raw = io.BytesIO(b"the content")1456 with pytest.raises(TypeError):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1457why, one step back1457 chunks = r.iter_content("1024")Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1458–1461why, one step back14581459 @pytest.mark.parametrize(1460 "exception, args, expected",1461 (Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1462–1463why, one step back1462 (urllib3.exceptions.ProtocolError, tuple(), ChunkedEncodingError),1463 (urllib3.exceptions.DecodeError, tuple(), ContentDecodingError),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1464why, one step back1464 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
line 1465why, one step back1465 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1466–1467why, one step back1466 ),1467 )Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1468why, one step back1468 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1469why, one step back1469 r = requests.Response()Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d
line 1470why, one step back1470 r.raw = mock.Mock()Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1471–1473why, one step back1471 # ReadTimeoutError can't be initialized by mock1472 # so we'll manually create the instance with args1473 r.raw.stream.side_effect = exception(*args)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1474why, one step back1474Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567
lines 1475–1476why, one step back1475 with pytest.raises(expected):1476 next(r.iter_content(1024))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1477why, one step back1477Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1478why, one step back1478 def test_request_and_response_are_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1479–1480why, one step back1479 r = requests.get(httpbin("get"))1480Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1481–1482why, one step back1481 # verify we can pickle the original request1482 assert pickle.loads(pickle.dumps(r.request))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1483why, one step back1483Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1484–1488why, one step back1484 # verify we can pickle the response and that we have access to1485 # the original request.1486 pr = pickle.loads(pickle.dumps(r))1487 assert r.request.url == pr.request.url1488 assert r.request.headers == pr.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1489why, one step back1489Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1490why, one step back1490 def test_prepared_request_is_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1491–1503why, one step back1491 p = requests.Request("GET", httpbin("get")).prepare()14921493 # Verify PreparedRequest can be pickled and unpickled1494 r = pickle.loads(pickle.dumps(p))1495 assert r.url == p.url1496 assert r.headers == p.headers1497 assert r.body == p.body14981499 # Verify unpickled PreparedRequest sends properly1500 s = requests.Session()1501 resp = s.send(r)1502 assert resp.status_code == 2001503Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1504why, one step back1504 def test_prepared_request_with_file_is_pickleable(self, httpbin):Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1
lines 1505–1507why, one step back1505 with open(__file__, "rb") as f:1506 r = requests.Request("POST", httpbin("post"), files={"file": f})1507 p = r.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1508–1519why, one step back15081509 # Verify PreparedRequest can be pickled and unpickled1510 r = pickle.loads(pickle.dumps(p))1511 assert r.url == p.url1512 assert r.headers == p.headers1513 assert r.body == p.body15141515 # Verify unpickled PreparedRequest sends properly1516 s = requests.Session()1517 resp = s.send(r)1518 assert resp.status_code == 2001519Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1520why, one step back1520 def test_prepared_request_with_hook_is_pickleable(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1521–1523why, one step back1521 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())1522 p = r.prepare()1523Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1524why, one step back1524 # Verify PreparedRequest can be pickledAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1525–1528why, one step back1525 r = pickle.loads(pickle.dumps(p))1526 assert r.url == p.url1527 assert r.headers == p.headers1528 assert r.body == p.bodyMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1529why, one step back1529 assert r.hooks == p.hooksAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1530–1535why, one step back15301531 # Verify unpickled PreparedRequest sends properly1532 s = requests.Session()1533 resp = s.send(r)1534 assert resp.status_code == 2001535Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1536–1537why, one step back1536 def test_cannot_send_unprepared_requests(self, httpbin):1537 r = requests.Request(url=httpbin())Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1538why, one step back1538 with pytest.raises(ValueError):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1539why, one step back1539 requests.Session().send(r)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1540why, one step back1540Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1541–1545why, one step back1541 def test_http_error(self):1542 error = requests.exceptions.HTTPError()1543 assert not error.response1544 response = requests.Response()1545 error = requests.exceptions.HTTPError(response=response)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1546–1550why, one step back1546 assert error.response == response1547 error = requests.exceptions.HTTPError("message", response=response)1548 assert str(error) == "message"1549 assert error.response == response1550Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1551why, one step back1551 def test_session_pickling(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1552–1554why, one step back1552 r = requests.Request("GET", httpbin("get"))1553 s = requests.Session()1554Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1555why, one step back1555 s = pickle.loads(pickle.dumps(s))Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1556–1560why, one step back1556 s.proxies = getproxies()15571558 r = s.send(r.prepare())1559 assert r.status_code == 2001560Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1561–1562why, one step back1561 def test_fixes_1329(self, httpbin):1562 """Ensure that header updates are done case-insensitively."""Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1563–1566why, one step back1563 s = requests.Session()1564 s.headers.update({"ACCEPT": "BOGUS"})1565 s.headers.update({"accept": "application/json"})1566 r = s.get(httpbin("get"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1567why, one step back1567 headers = r.request.headersAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1568–1571why, one step back1568 assert headers["accept"] == "application/json"1569 assert headers["Accept"] == "application/json"1570 assert headers["ACCEPT"] == "application/json"1571Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1572why, one step back1572 def test_uppercase_scheme_redirect(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1573why, one step back1573 parts = urlparse(httpbin("html"))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1574why, one step back1574 url = "HTTP://" + parts.netloc + parts.pathAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1575–1576why, one step back1575 r = requests.get(httpbin("redirect-to"), params={"url": url})1576 assert r.status_code == 200Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1577why, one step back1577 assert r.url.lower() == url.lower()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1578why, one step back1578Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1579why, one step back1579 def test_transport_adapter_ordering(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1580–1610why, one step back1580 s = requests.Session()1581 order = ["https://", "http://"]1582 assert order == list(s.adapters)1583 s.mount("http://git", HTTPAdapter())1584 s.mount("http://github", HTTPAdapter())1585 s.mount("http://github.com", HTTPAdapter())1586 s.mount("http://github.com/about/", HTTPAdapter())1587 order = [1588 "http://github.com/about/",1589 "http://github.com",1590 "http://github",1591 "http://git",1592 "https://",1593 "http://",1594 ]1595 assert order == list(s.adapters)1596 s.mount("http://gittip", HTTPAdapter())1597 s.mount("http://gittip.com", HTTPAdapter())1598 s.mount("http://gittip.com/about/", HTTPAdapter())1599 order = [1600 "http://github.com/about/",1601 "http://gittip.com/about/",1602 "http://github.com",1603 "http://gittip.com",1604 "http://github",1605 "http://gittip",1606 "http://git",1607 "https://",1608 "http://",1609 ]1610 assert order == list(s.adapters)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1611why, one step back1611 s2 = requests.Session()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1612–1616why, one step back1612 s2.adapters = {"http://": HTTPAdapter()}1613 s2.mount("https://", HTTPAdapter())1614 assert "http://" in s2.adapters1615 assert "https://" in s2.adapters1616Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1617why, one step back1617 def test_session_get_adapter_prefix_matching(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1618–1625why, one step back1618 prefix = "https://example.com"1619 more_specific_prefix = prefix + "/some/path"16201621 url_matching_only_prefix = prefix + "/another/path"1622 url_matching_more_specific_prefix = more_specific_prefix + "/longer/path"1623 url_not_matching_prefix = "https://another.example.com/"16241625 s = requests.Session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1626–1629why, one step back1626 prefix_adapter = HTTPAdapter()1627 more_specific_prefix_adapter = HTTPAdapter()1628 s.mount(prefix, prefix_adapter)1629 s.mount(more_specific_prefix, more_specific_prefix_adapter)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1630why, one step back1630Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1631why, one step back1631 assert s.get_adapter(url_matching_only_prefix) is prefix_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1632–1640why, one step back1632 assert (1633 s.get_adapter(url_matching_more_specific_prefix)1634 is more_specific_prefix_adapter1635 )1636 assert s.get_adapter(url_not_matching_prefix) not in (1637 prefix_adapter,1638 more_specific_prefix_adapter,1639 )1640Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1641why, one step back1641 def test_session_get_adapter_prefix_matching_mixed_case(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1642–1648why, one step back1642 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"1643 url_matching_prefix = mixed_case_prefix + "/full_url"16441645 s = requests.Session()1646 my_adapter = HTTPAdapter()1647 s.mount(mixed_case_prefix, my_adapter)1648Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1649why, one step back1649 assert s.get_adapter(url_matching_prefix) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1650why, one step back1650Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1651why, one step back1651 def test_session_get_adapter_prefix_matching_is_case_insensitive(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1652–1660why, one step back1652 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"1653 url_matching_prefix_with_different_case = (1654 "HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url"1655 )16561657 s = requests.Session()1658 my_adapter = HTTPAdapter()1659 s.mount(mixed_case_prefix, my_adapter)1660Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1661why, one step back1661 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapterAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1662why, one step back1662Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1663–1664why, one step back1663 def test_header_remove_is_case_insensitive(self, httpbin):1664 # From issue #1321Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1665–1669why, one step back1665 s = requests.Session()1666 s.headers["foo"] = "bar"1667 r = s.get(httpbin("get"), headers={"FOO": None})1668 assert "foo" not in r.request.headers1669Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1670why, one step back1670 def test_params_are_merged_case_sensitive(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1671–1675why, one step back1671 s = requests.Session()1672 s.params["foo"] = "bar"1673 r = s.get(httpbin("get"), params={"FOO": "bar"})1674 assert r.json()["args"] == {"foo": "bar", "FOO": "bar"}1675Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1676why, one step back1676 def test_long_authinfo_in_url(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1677–1682why, one step back1677 url = "http://{}:{}@{}:9000/path?query#frag".format(1678 "E8A3BE87-9E3F-4620-8858-95478E385B5B",1679 "EA770032-DA4D-4D84-8CE9-29C6D910BF1E",1680 "exactly-------------sixty-----------three------------characters",1681 )1682 r = requests.Request("GET", url).prepare()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1683why, one step back1683 assert r.url == urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1684why, one step back1684Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1685why, one step back1685 def test_header_keys_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1686–1689why, one step back1686 headers = {"unicode": "blah", b"byte": "blah"}1687 r = requests.Request("GET", httpbin("get"), headers=headers)1688 p = r.prepare()1689Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1690–1691why, one step back1690 # This is testing that they are builtin strings. A bit weird, but there1691 # we go.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1692–1694why, one step back1692 assert "unicode" in p.headers.keys()1693 assert "byte" in p.headers.keys()1694Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1695–1696why, one step back1695 def test_header_validation(self, httpbin):1696 """Ensure prepare_headers regex isn't flagging valid header contents."""Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1697why, one step back1697 valid_headers = {Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1698–1702why, one step back1698 "foo": "bar baz qux",1699 "bar": b"fbbq",1700 "baz": "",1701 "qux": "1",1702 }Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1703–1704why, one step back1703 r = requests.get(httpbin("get"), headers=valid_headers)1704 for key in valid_headers.keys():Merge pull request #6552 from swims-hjkl/issue/test_header_validationNate Prewittbefore adoption839a8ed
line 1705why, one step back1705 assert valid_headers[key] == r.request.headers[key]Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1706why, one step back1706Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1707–1715why, one step back1707 @pytest.mark.parametrize(1708 "invalid_header, key",1709 (1710 ({"foo": 3}, "foo"),1711 ({"bar": {"foo": "bar"}}, "bar"),1712 ({"baz": ["foo", "bar"]}, "baz"),1713 ),1714 )1715 def test_header_value_not_str(self, httpbin, invalid_header, key):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1716–1717why, one step back1716 """Ensure the header value is of type string or bytes as1717 per discussion in GH issue #3386Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1718–1719why, one step back1718 """1719 with pytest.raises(InvalidHeader) as excinfo:Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1720–1721why, one step back1720 requests.get(httpbin("get"), headers=invalid_header)1721 assert key in str(excinfo.value)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1722why, one step back1722Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1723–1736why, one step back1723 @pytest.mark.parametrize(1724 "invalid_header",1725 (1726 {"foo": "bar\r\nbaz: qux"},1727 {"foo": "bar\n\rbaz: qux"},1728 {"foo": "bar\nbaz: qux"},1729 {"foo": "bar\rbaz: qux"},1730 {"fo\ro": "bar"},1731 {"fo\r\no": "bar"},1732 {"fo\n\ro": "bar"},1733 {"fo\no": "bar"},1734 ),1735 )1736 def test_header_no_return_chars(self, httpbin, invalid_header):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1737–1738why, one step back1737 """Ensure that a header containing return character sequences raise an1738 exception. Otherwise, multiple headers are created from single string.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1739–1740why, one step back1739 """1740 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1741why, one step back1741 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1742why, one step back1742Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
lines 1743–1755why, one step back1743 @pytest.mark.parametrize(1744 "invalid_header",1745 (1746 {" foo": "bar"},1747 {"\tfoo": "bar"},1748 {" foo": "bar"},1749 {"foo": " bar"},1750 {"foo": " bar"},1751 {"foo": "\tbar"},1752 {" ": "bar"},1753 ),1754 )1755 def test_header_no_leading_space(self, httpbin, invalid_header):Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1756–1757why, one step back1756 """Ensure headers containing leading whitespace raise1757 InvalidHeader Error before sending.Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1758–1759why, one step back1758 """1759 with pytest.raises(InvalidHeader):Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345
line 1760why, one step back1760 requests.get(httpbin("get"), headers=invalid_header)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1761why, one step back1761Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7
lines 1762–1786why, one step back1762 def test_header_with_subclass_types(self, httpbin):1763 """If the subclasses does not behave *exactly* like1764 the base bytes/str classes, this is not supported.1765 This test is for backwards compatibility.1766 """17671768 class MyString(str):1769 pass17701771 class MyBytes(bytes):1772 pass17731774 r_str = requests.get(httpbin("get"), headers={MyString("x-custom"): "myheader"})1775 assert r_str.request.headers["x-custom"] == "myheader"17761777 r_bytes = requests.get(1778 httpbin("get"), headers={MyBytes(b"x-custom"): b"myheader"}1779 )1780 assert r_bytes.request.headers["x-custom"] == b"myheader"17811782 r_mixed = requests.get(1783 httpbin("get"), headers={MyString("x-custom"): MyBytes(b"myheader")}1784 )1785 assert r_mixed.request.headers["x-custom"] == b"myheader"1786Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1787why, one step back1787 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1788why, one step back1788 def test_can_send_objects_with_files(self, httpbin, files):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1789–1794why, one step back1789 data = {"a": "this is a string"}1790 files = {"b": files}1791 r = requests.Request("POST", httpbin("post"), data=data, files=files)1792 p = r.prepare()1793 assert "multipart/form-data" in p.headers["Content-Type"]1794Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1795–1797why, one step back1795 def test_can_send_file_object_with_non_string_filename(self, httpbin):1796 f = io.BytesIO()1797 f.name = 2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1798–1802why, one step back1798 r = requests.Request("POST", httpbin("post"), files={"f": f})1799 p = r.prepare()18001801 assert "multipart/form-data" in p.headers["Content-Type"]1802Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1803why, one step back1803 def test_autoset_header_values_are_native(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1804–1806why, one step back1804 data = "this is a string"1805 length = "16"1806 req = requests.Request("POST", httpbin("post"), data=data)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1807why, one step back1807 p = req.prepare()Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1808–1810why, one step back18081809 assert p.headers["Content-Length"] == length1810Merge pull request #6589 from bruceadams/super_len_str_utf-8Ian Stapleton Cordascobefore adoptionb8be93a
lines 1811–1827why, one step back1811 def test_content_length_for_bytes_data(self, httpbin):1812 data = "This is a string containing multi-byte UTF-8 ☃️"1813 encoded_data = data.encode("utf-8")1814 length = str(len(encoded_data))1815 req = requests.Request("POST", httpbin("post"), data=encoded_data)1816 p = req.prepare()18171818 assert p.headers["Content-Length"] == length18191820 def test_content_length_for_string_data_counts_bytes(self, httpbin):1821 data = "This is a string containing multi-byte UTF-8 ☃️"1822 length = str(len(data.encode("utf-8")))1823 req = requests.Request("POST", httpbin("post"), data=data)1824 p = req.prepare()18251826 assert p.headers["Content-Length"] == length1827Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1828–1829why, one step back1828 def test_nonhttp_schemes_dont_check_URLs(self):1829 test_urls = (Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1830–1833why, one step back1830 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",1831 "file:///etc/passwd",1832 "magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431",1833 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1834why, one step back1834 for test_url in test_urls:Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1835why, one step back1835 req = requests.Request("GET", test_url)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1836–1837why, one step back1836 preq = req.prepare()1837 assert test_url == preq.urlAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1838–1850why, one step back18381839 def test_auth_is_stripped_on_http_downgrade(1840 self, httpbin, httpbin_secure, httpbin_ca_bundle1841 ):1842 r = requests.get(1843 httpbin_secure("redirect-to"),1844 params={"url": httpbin("get")},1845 auth=("user", "pass"),1846 verify=httpbin_ca_bundle,1847 )1848 assert r.history[0].request.headers["Authorization"]1849 assert "Authorization" not in r.request.headers1850Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1851why, one step back1851 def test_auth_is_retained_for_redirect_on_host(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1852–1855why, one step back1852 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))1853 h1 = r.history[0].request.headers["Authorization"]1854 h2 = r.request.headers["Authorization"]1855Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1856why, one step back1856 assert h1 == h2Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1857why, one step back1857Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1858why, one step back1858 def test_should_strip_auth_host_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1859–1863why, one step back1859 s = requests.Session()1860 assert s.should_strip_auth(1861 "http://example.com/foo", "http://another.example.com/"1862 )1863Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1864why, one step back1864 def test_should_strip_auth_http_downgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1865–1867why, one step back1865 s = requests.Session()1866 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1867Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1868why, one step back1868 def test_should_strip_auth_https_upgrade(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1869–1878why, one step back1869 s = requests.Session()1870 assert not s.should_strip_auth(1871 "http://example.com/foo", "https://example.com/bar"1872 )1873 assert not s.should_strip_auth(1874 "http://example.com:80/foo", "https://example.com/bar"1875 )1876 assert not s.should_strip_auth(1877 "http://example.com/foo", "https://example.com:443/bar"1878 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1879why, one step back1879 # Non-standard ports should trigger strippingAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1880–1886why, one step back1880 assert s.should_strip_auth(1881 "http://example.com:8080/foo", "https://example.com/bar"1882 )1883 assert s.should_strip_auth(1884 "http://example.com/foo", "https://example.com:8443/bar"1885 )1886Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1887why, one step back1887 def test_should_strip_auth_port_change(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1888–1901why, one step back1888 s = requests.Session()1889 assert s.should_strip_auth(1890 "http://example.com:1234/foo", "https://example.com:4321/bar"1891 )18921893 @pytest.mark.parametrize(1894 "old_uri, new_uri",1895 (1896 ("https://example.com:443/foo", "https://example.com/bar"),1897 ("http://example.com:80/foo", "http://example.com/bar"),1898 ("https://example.com/foo", "https://example.com:443/bar"),1899 ("http://example.com/foo", "http://example.com:80/bar"),1900 ),1901 )Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1902why, one step back1902 def test_should_strip_auth_default_port(self, old_uri, new_uri):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1903why, one step back1903 s = requests.Session()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1904why, one step back1904 assert not s.should_strip_auth(old_uri, new_uri)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1905why, one step back1905Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1906why, one step back1906 def test_manual_redirect_with_partial_body_read(self, httpbin):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1907–1908why, one step back1907 s = requests.Session()1908 r1 = s.get(httpbin("redirect/2"), allow_redirects=False, stream=True)Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1909–1910why, one step back1909 assert r1.is_redirect1910 rg = s.resolve_redirects(r1, r1.request, stream=True)Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1911why, one step back1911Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1912why, one step back1912 # read only the first eight bytes of the response body,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1913why, one step back1913 # then follow the redirectMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1914–1916why, one step back1914 r1.iter_content(8)1915 r2 = next(rg)1916 assert r2.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1917why, one step back1917Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1918why, one step back1918 # read all of the response via iter_content,Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1919why, one step back1919 # then follow the redirectMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1920why, one step back1920 for _ in r2.iter_content():Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1921why, one step back1921 passMerge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
lines 1922–1923why, one step back1922 r3 = next(rg)1923 assert not r3.is_redirectAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1924why, one step back1924Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1925why, one step back1925 def test_prepare_body_position_non_stream(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1926–1927why, one step back1926 data = b"the data"1927 prep = requests.Request("GET", "http://example.com", data=data).prepare()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1928why, one step back1928 assert prep._body_position is NoneAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1929why, one step back1929Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1930why, one step back1930 def test_rewind_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1931–1942why, one step back1931 data = io.BytesIO(b"the data")1932 prep = requests.Request("GET", "http://example.com", data=data).prepare()1933 assert prep._body_position == 01934 assert prep.body.read() == b"the 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"the data"1942Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1943why, one step back1943 def test_rewind_partially_read_body(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1944why, one step back1944 data = io.BytesIO(b"the data")Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1945why, one step back1945 data.read(4) # read some dataAdd automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
line 1946why, one step back1946 prep = requests.Request("GET", "http://example.com", data=data).prepare()Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1947why, one step back1947 assert prep._body_position == 4Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1948–1956why, one step back1948 assert prep.body.read() == b"data"19491950 # the data has all been read1951 assert prep.body.read() == b""19521953 # rewind it back1954 requests.utils.rewind_body(prep)1955 assert prep.body.read() == b"data"1956Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1957why, one step back1957 def test_rewind_body_no_seek(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1958–1976why, one step back1958 class BadFileObj:1959 def __init__(self, data):1960 self.data = data19611962 def tell(self):1963 return 019641965 def __iter__(self):1966 return19671968 data = BadFileObj("the data")1969 prep = requests.Request("GET", "http://example.com", data=data).prepare()1970 assert prep._body_position == 019711972 with pytest.raises(UnrewindableBodyError) as e:1973 requests.utils.rewind_body(prep)19741975 assert "Unable to rewind request body" in str(e)1976Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1977why, one step back1977 def test_rewind_body_failed_seek(self):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1978–1984why, one step back1978 class BadFileObj:1979 def __init__(self, data):1980 self.data = data19811982 def tell(self):1983 return 01984Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 1985why, one step back1985 def seek(self, pos, whence=0):Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290
lines 1986–1999why, one step back1986 raise OSError()19871988 def __iter__(self):1989 return19901991 data = BadFileObj("the data")1992 prep = requests.Request("GET", "http://example.com", data=data).prepare()1993 assert prep._body_position == 019941995 with pytest.raises(UnrewindableBodyError) as e:1996 requests.utils.rewind_body(prep)19971998 assert "error occurred when rewinding request body" in str(e)1999Merge pull request #5496 from dbaxa/optimise-prepare-bodyNate Prewittbefore adoption7c71982
line 2000why, one step back2000 def test_rewind_body_failed_tell(self):The first 2,000 of 2,839 lines.