Skip to content
Myr

test_requests.py

This file

Path

tests/test_requests.py

2,983 lines · 102.1 KiB · Python

Last changed by

Merge pull request #6757 from nateprewitt/urllib-1.x-testsNate Prewittbefore adoption79b74ef

History of this file

Take it

The walk stopped after 200 commits: lines older than 9cd2d33 point at it.

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1why, one step back
1"""Tests for Requests."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 2why, one step back
2

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 3–5why, one step back
3import collections
4import contextlib5import io

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 6–9why, one step back
6import json
7import os8import pickle9import re

Merge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a

line 10why, one step back
10import threading

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 11why, one step back
11import warnings

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 12why, one step back
12from unittest import mock

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 13why, one step back
13

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 14why, one step back
14import pytest

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 15why, one step back
15import urllib3

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 16why, one step back
16from urllib3.util import Timeout as Urllib3Timeout

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 17–27why, one step back
17
18import requests19from requests.adapters import HTTPAdapter20from requests.auth import HTTPDigestAuth, _basic_auth_str21from requests.compat import (22 JSONDecodeError,23 Morsel,24 MutableMapping,25 builtin_str,26 cookielib,27 getproxies,

Merge pull request #6757 from nateprewitt/urllib-1.x-testsNate Prewittbefore adoption79b74ef

line 28why, one step back
28 is_urllib3_1,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 29–53why, one step back
29 urlparse,
30)31from requests.cookies import cookiejar_from_dict, morsel_to_cookie32from requests.exceptions import (33 ChunkedEncodingError,34 ConnectionError,35 ConnectTimeout,36 ContentDecodingError,37 InvalidHeader,38 InvalidProxyURL,39 InvalidSchema,40 InvalidURL,41 MissingSchema,42 ProxyError,43 ReadTimeout,44 RequestException,45 RetryError,46)47from requests.exceptions import SSLError as RequestsSSLError48from requests.exceptions import Timeout, TooManyRedirects, UnrewindableBodyError49from requests.hooks import default_hooks50from requests.models import PreparedRequest, urlencode51from requests.sessions import SessionRedirectMixin52from requests.structures import CaseInsensitiveDict53

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

line 54why, one step back
54from . import SNIMissingWarning

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 55why, one step back
55from .compat import StringIO

Merge pull request #6662 from sigmavirus24/fix-tls-floppyIan Stapleton Cordascobefore adoptioneeafb6a

line 56why, one step back
56from .testserver.server import TLSServer, consume_socket_content

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 57–58why, one step back
57from .utils import override_environ
58

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 59–60why, one step back
59# Requests to this URL should always fail with a connection timeout (nothing
60# listening on that port)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 61–62why, one step back
61TARPIT = "http://10.255.255.1"
62

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 63why, one step back
63# This is to avoid waiting the timeout of using TARPIT

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 64–66why, one step back
64INVALID_PROXY = "http://localhost:1"
6566try:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 67why, one step back
67 from ssl import SSLContext

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 68why, one step back
68

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 69–72why, one step back
69 del SSLContext
70 HAS_MODERN_SSL = True71except ImportError:72 HAS_MODERN_SSL = False

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 73–74why, one step back
73
74try:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 75–78why, one step back
75 requests.pyopenssl
76 HAS_PYOPENSSL = True77except AttributeError:78 HAS_PYOPENSSL = False

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 79–80why, one step back
79
80

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 81why, one step back
81class TestRequests:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 82–83why, one step back
82 digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
83

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 84–93why, one step back
84 def test_entry_points(self):
85 requests.session86 requests.session().get87 requests.session().head88 requests.get89 requests.head90 requests.put91 requests.patch92 requests.post93 # Not really an entry point, but people rely on it.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 94–107why, one step back
94 from requests.packages.urllib3.poolmanager import PoolManager # noqa:F401
9596 @pytest.mark.parametrize(97 "exception, url",98 (99 (MissingSchema, "hiwpefhipowhefopw"),100 (InvalidSchema, "localhost:3128"),101 (InvalidSchema, "localhost.localdomain:3128/"),102 (InvalidSchema, "10.122.1.1:3128/"),103 (InvalidURL, "http://"),104 (InvalidURL, "http://*example.com"),105 (InvalidURL, "http://.example.com"),106 ),107 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 108why, one step back
108 def test_invalid_url(self, exception, url):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 109why, one step back
109 with pytest.raises(exception):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 110why, one step back
110 requests.get(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 111why, one step back
111

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 112–113why, one step back
112 def test_basic_building(self):
113 req = requests.Request()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 114–116why, one step back
114 req.url = "http://kennethreitz.org/"
115 req.data = {"life": "42"}116

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 117–118why, one step back
117 pr = req.prepare()
118 assert pr.url == req.url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 119–121why, one step back
119 assert pr.body == "life=42"
120121 @pytest.mark.parametrize("method", ("GET", "HEAD"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 122why, one step back
122 def test_no_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 123–126why, one step back
123 req = requests.Request(method, httpbin(method.lower())).prepare()
124 assert "Content-Length" not in req.headers125126 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 127why, one step back
127 def test_no_body_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 128–131why, one step back
128 req = requests.Request(method, httpbin(method.lower())).prepare()
129 assert req.headers["Content-Length"] == "0"130131 @pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 132why, one step back
132 def test_empty_content_length(self, httpbin, method):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 133–135why, one step back
133 req = requests.Request(method, httpbin(method.lower()), data="").prepare()
134 assert req.headers["Content-Length"] == "0"135

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 136why, one step back
136 def test_override_content_length(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 137–141why, one step back
137 headers = {"Content-Length": "not zero"}
138 r = requests.Request("POST", httpbin("post"), headers=headers).prepare()139 assert "Content-Length" in r.headers140 assert r.headers["Content-Length"] == "not zero"141

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 142why, one step back
142 def test_path_is_not_double_encoded(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 143–159why, one step back
143 request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()
144145 assert request.path_url == "/get/test%20case"146147 @pytest.mark.parametrize(148 "url, expected",149 (150 (151 "http://example.com/path#fragment",152 "http://example.com/path?a=b#fragment",153 ),154 (155 "http://example.com/path?key=value#fragment",156 "http://example.com/path?key=value&a=b#fragment",157 ),158 ),159 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 160why, one step back
160 def test_params_are_added_before_fragment(self, url, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 161why, one step back
161 request = requests.Request("GET", url, params={"a": "b"}).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 162why, one step back
162 assert request.url == expected

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 163why, one step back
163

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 164why, one step back
164 def test_params_original_order_is_preserved_by_default(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 165–171why, one step back
165 param_ordered_dict = collections.OrderedDict(
166 (("z", 1), ("a", 1), ("k", 1), ("d", 1))167 )168 session = requests.Session()169 request = requests.Request(170 "GET", "http://example.com/", params=param_ordered_dict171 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 172why, one step back
172 prep = session.prepare_request(request)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 173–174why, one step back
173 assert prep.url == "http://example.com/?z=1&a=1&k=1&d=1"
174

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 175why, one step back
175 def test_params_bytes_are_encoded(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 176–180why, one step back
176 request = requests.Request(
177 "GET", "http://example.com", params=b"test=foo"178 ).prepare()179 assert request.url == "http://example.com/?test=foo"180

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 181why, one step back
181 def test_binary_put(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 182–184why, one step back
182 request = requests.Request(
183 "PUT", "http://example.com", data="ööö".encode()184 ).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 185why, one step back
185 assert isinstance(request.body, bytes)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 186why, one step back
186

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 187–188why, one step back
187 def test_whitespaces_are_removed_from_url(self):
188 # Test for issue #3696

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 189–192why, one step back
189 request = requests.Request("GET", " http://example.com").prepare()
190 assert request.url == "http://example.com/"191192 @pytest.mark.parametrize("scheme", ("http://", "HTTP://", "hTTp://", "HttP://"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 193why, one step back
193 def test_mixed_case_scheme_acceptable(self, httpbin, scheme):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 194–196why, one step back
194 s = requests.Session()
195 s.proxies = getproxies()196 parts = urlparse(httpbin("get"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 197why, one step back
197 url = scheme + parts.netloc + parts.path

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 198–201why, one step back
198 r = requests.Request("GET", url)
199 r = s.send(r.prepare())200 assert r.status_code == 200, f"failed for scheme {scheme}"201

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 202why, one step back
202 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 203–210why, one step back
203 r = requests.Request("GET", httpbin("get"))
204 s = requests.Session()205 s.proxies = getproxies()206207 r = s.send(r.prepare())208209 assert r.status_code == 200210

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 211why, one step back
211 def test_HTTP_302_ALLOW_REDIRECT_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 212–216why, one step back
212 r = requests.get(httpbin("redirect", "1"))
213 assert r.status_code == 200214 assert r.history[0].status_code == 302215 assert r.history[0].is_redirect216

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 217why, one step back
217 def test_HTTP_307_ALLOW_REDIRECT_POST(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 218–227why, one step back
218 r = requests.post(
219 httpbin("redirect-to"),220 data="test",221 params={"url": "post", "status_code": 307},222 )223 assert r.status_code == 200224 assert r.history[0].status_code == 307225 assert r.history[0].is_redirect226 assert r.json()["data"] == "test"227

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 228why, one step back
228 def test_HTTP_307_ALLOW_REDIRECT_POST_WITH_SEEKABLE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 229–239why, one step back
229 byte_str = b"test"
230 r = requests.post(231 httpbin("redirect-to"),232 data=io.BytesIO(byte_str),233 params={"url": "post", "status_code": 307},234 )235 assert r.status_code == 200236 assert r.history[0].status_code == 307237 assert r.history[0].is_redirect238 assert r.json()["data"] == byte_str.decode("utf-8")239

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 240why, one step back
240 def test_HTTP_302_TOO_MANY_REDIRECTS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 241–246why, one step back
241 try:
242 requests.get(httpbin("relative-redirect", "50"))243 except TooManyRedirects as e:244 url = httpbin("relative-redirect", "20")245 assert e.request.url == url246 assert e.response.url == url

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 247why, one step back
247 assert len(e.response.history) == 30

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 248–250why, one step back
248 else:
249 pytest.fail("Expected redirect to raise TooManyRedirects but it did not")250

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 251why, one step back
251 def test_HTTP_302_TOO_MANY_REDIRECTS_WITH_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 252why, one step back
252 s = requests.session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 253why, one step back
253 s.max_redirects = 5

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 254–259why, one step back
254 try:
255 s.get(httpbin("relative-redirect", "50"))256 except TooManyRedirects as e:257 url = httpbin("relative-redirect", "45")258 assert e.request.url == url259 assert e.response.url == url

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 260why, one step back
260 assert len(e.response.history) == 5

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 261–265why, one step back
261 else:
262 pytest.fail(263 "Expected custom max number of redirects to be respected but was not"264 )265

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 266why, one step back
266 def test_http_301_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 267–272why, one step back
267 r = requests.post(httpbin("status", "301"))
268 assert r.status_code == 200269 assert r.request.method == "GET"270 assert r.history[0].status_code == 301271 assert r.history[0].is_redirect272

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 273why, one step back
273 def test_http_301_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 274why, one step back
274 r = requests.head(httpbin("status", "301"), allow_redirects=True)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 275why, one step back
275 print(r.content)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 276–280why, one step back
276 assert r.status_code == 200
277 assert r.request.method == "HEAD"278 assert r.history[0].status_code == 301279 assert r.history[0].is_redirect280

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 281why, one step back
281 def test_http_302_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 282–287why, one step back
282 r = requests.post(httpbin("status", "302"))
283 assert r.status_code == 200284 assert r.request.method == "GET"285 assert r.history[0].status_code == 302286 assert r.history[0].is_redirect287

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 288why, one step back
288 def test_http_302_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 289–294why, one step back
289 r = requests.head(httpbin("status", "302"), allow_redirects=True)
290 assert r.status_code == 200291 assert r.request.method == "HEAD"292 assert r.history[0].status_code == 302293 assert r.history[0].is_redirect294

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 295why, one step back
295 def test_http_303_changes_post_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 296–301why, one step back
296 r = requests.post(httpbin("status", "303"))
297 assert r.status_code == 200298 assert r.request.method == "GET"299 assert r.history[0].status_code == 303300 assert r.history[0].is_redirect301

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 302why, one step back
302 def test_http_303_doesnt_change_head_to_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 303–308why, one step back
303 r = requests.head(httpbin("status", "303"), allow_redirects=True)
304 assert r.status_code == 200305 assert r.request.method == "HEAD"306 assert r.history[0].status_code == 303307 assert r.history[0].is_redirect308

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 309why, one step back
309 def test_header_and_body_removal_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 310–313why, one step back
310 purged_headers = ("Content-Length", "Content-Type")
311 ses = requests.Session()312 req = requests.Request("POST", httpbin("post"), data={"test": "data"})313 prep = ses.prepare_request(req)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 314why, one step back
314 resp = ses.send(prep)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 315–319why, one step back
315
316 # Mimic a redirect response317 resp.status_code = 302318 resp.headers["location"] = "get"319

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 320why, one step back
320 # Run request through resolve_redirects

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 321–325why, one step back
321 next_resp = next(ses.resolve_redirects(resp, prep))
322 assert next_resp.request.body is None323 for header in purged_headers:324 assert header not in next_resp.request.headers325

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 326why, one step back
326 def test_transfer_enc_removal_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 327–332why, one step back
327 purged_headers = ("Transfer-Encoding", "Content-Type")
328 ses = requests.Session()329 req = requests.Request("POST", httpbin("post"), data=(b"x" for x in range(1)))330 prep = ses.prepare_request(req)331 assert "Transfer-Encoding" in prep.headers332

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 333why, one step back
333 # Create Response to avoid https://github.com/kevin1024/pytest-httpbin/issues/33

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 334–335why, one step back
334 resp = requests.Response()
335 resp.raw = io.BytesIO(b"the content")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 336why, one step back
336 resp.request = prep

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 337–342why, one step back
337 setattr(resp.raw, "release_conn", lambda *args: args)
338339 # Mimic a redirect response340 resp.status_code = 302341 resp.headers["location"] = httpbin("get")342

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 343why, one step back
343 # Run request through resolve_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 344–348why, one step back
344 next_resp = next(ses.resolve_redirects(resp, prep))
345 assert next_resp.request.body is None346 for header in purged_headers:347 assert header not in next_resp.request.headers348

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 349–350why, one step back
349 def test_fragment_maintained_on_redirect(self, httpbin):
350 fragment = "#view=edit&token=hunter2"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 351–352why, one step back
351 r = requests.get(httpbin("redirect-to?url=get") + fragment)
352

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 353why, one step back
353 assert len(r.history) > 0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 354–356why, one step back
354 assert r.history[0].request.url == httpbin("redirect-to?url=get") + fragment
355 assert r.url == httpbin("get") + fragment356

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 357why, one step back
357 def test_HTTP_200_OK_GET_WITH_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 358–364why, one step back
358 heads = {"User-agent": "Mozilla/5.0"}
359360 r = requests.get(httpbin("user-agent"), headers=heads)361362 assert heads["User-agent"] in r.text363 assert r.status_code == 200364

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 365why, one step back
365 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 366–372why, one step back
366 heads = {"User-agent": "Mozilla/5.0"}
367368 r = requests.get(369 httpbin("get") + "?test=true", params={"q": "test"}, headers=heads370 )371 assert r.status_code == 200372

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 373why, one step back
373 def test_set_cookie_on_301(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 374–378why, one step back
374 s = requests.session()
375 url = httpbin("cookies/set?foo=bar")376 s.get(url)377 assert s.cookies["foo"] == "bar"378

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 379why, one step back
379 def test_cookie_sent_on_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 380–384why, one step back
380 s = requests.session()
381 s.get(httpbin("cookies/set?foo=bar"))382 r = s.get(httpbin("redirect/1")) # redirects to httpbin('get')383 assert "Cookie" in r.json()["headers"]384

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 385why, one step back
385 def test_cookie_removed_on_expire(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 386–388why, one step back
386 s = requests.session()
387 s.get(httpbin("cookies/set?foo=bar"))388 assert s.cookies["foo"] == "bar"

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 389why, one step back
389 s.get(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 390–394why, one step back
390 httpbin("response-headers"),
391 params={"Set-Cookie": "foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT"},392 )393 assert "foo" not in s.cookies394

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 395why, one step back
395 def test_cookie_quote_wrapped(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 396why, one step back
396 s = requests.session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 397why, one step back
397 s.get(httpbin('cookies/set?foo="bar:baz"'))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 398–399why, one step back
398 assert s.cookies["foo"] == '"bar:baz"'
399

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 400why, one step back
400 def test_cookie_persists_via_api(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 401–405why, one step back
401 s = requests.session()
402 r = s.get(httpbin("redirect/1"), cookies={"foo": "bar"})403 assert "foo" in r.request.headers["Cookie"]404 assert "foo" in r.history[0].request.headers["Cookie"]405

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 406why, one step back
406 def test_request_cookie_overrides_session_cookie(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 407–410why, one step back
407 s = requests.session()
408 s.cookies["foo"] = "bar"409 r = s.get(httpbin("cookies"), cookies={"foo": "baz"})410 assert r.json()["cookies"]["foo"] == "baz"

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 411why, one step back
411 # Session cookie should not be modified

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 412–413why, one step back
412 assert s.cookies["foo"] == "bar"
413

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 414why, one step back
414 def test_request_cookies_not_persisted(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 415–416why, one step back
415 s = requests.session()
416 s.get(httpbin("cookies"), cookies={"foo": "baz"})

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 417–418why, one step back
417 # Sending a request with cookies should not add cookies to the session
418 assert not s.cookies

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 419why, one step back
419

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 420why, one step back
420 def test_generic_cookiejar_works(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 421–423why, one step back
421 cj = cookielib.CookieJar()
422 cookiejar_from_dict({"foo": "bar"}, cj)423 s = requests.session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 424why, one step back
424 s.cookies = cj

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 425–427why, one step back
425 r = s.get(httpbin("cookies"))
426 # Make sure the cookie was sent427 assert r.json()["cookies"]["foo"] == "bar"

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 428–429why, one step back
428 # Make sure the session cj is still the custom one
429 assert s.cookies is cj

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 430why, one step back
430

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 431why, one step back
431 def test_param_cookiejar_works(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 432–438why, one step back
432 cj = cookielib.CookieJar()
433 cookiejar_from_dict({"foo": "bar"}, cj)434 s = requests.session()435 r = s.get(httpbin("cookies"), cookies=cj)436 # Make sure the cookie was sent437 assert r.json()["cookies"]["foo"] == "bar"438

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 439–441why, one step back
439 def test_cookielib_cookiejar_on_redirect(self, httpbin):
440 """Tests resolve_redirect doesn't fail when merging cookies441 with non-RequestsCookieJar cookiejar.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 442why, one step back
442

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 443why, one step back
443 See GH #3579

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 444–448why, one step back
444 """
445 cj = cookiejar_from_dict({"foo": "bar"}, cookielib.CookieJar())446 s = requests.Session()447 s.cookies = cookiejar_from_dict({"cookie": "tasty"})448

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 449why, one step back
449 # Prepare request without using Session

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 450why, one step back
450 req = requests.Request("GET", httpbin("headers"), cookies=cj)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 451why, one step back
451 prep_req = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 452why, one step back
452

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 453–454why, one step back
453 # Send request and simulate redirect
454 resp = s.send(prep_req)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 455–456why, one step back
455 resp.status_code = 302
456 resp.headers["location"] = httpbin("get")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 457–458why, one step back
457 redirects = s.resolve_redirects(resp, prep_req)
458 resp = next(redirects)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 459why, one step back
459

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 460–463why, one step back
460 # Verify CookieJar isn't being converted to RequestsCookieJar
461 assert isinstance(prep_req._cookies, cookielib.CookieJar)462 assert isinstance(resp.request._cookies, cookielib.CookieJar)463 assert not isinstance(resp.request._cookies, requests.cookies.RequestsCookieJar)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 464why, one step back
464

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 465–467why, one step back
465 cookies = {}
466 for c in resp.request._cookies:467 cookies[c.name] = c.value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 468–470why, one step back
468 assert cookies["foo"] == "bar"
469 assert cookies["cookie"] == "tasty"470

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 471why, one step back
471 def test_requests_in_history_are_not_overridden(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 472why, one step back
472 resp = requests.get(httpbin("redirect/3"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 473–475why, one step back
473 urls = [r.url for r in resp.history]
474 req_urls = [r.request.url for r in resp.history]475 assert urls == req_urls

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 476why, one step back
476

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 477–478why, one step back
477 def test_history_is_always_a_list(self, httpbin):
478 """Show that even with redirects, Response.history is always a list."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 479–482why, one step back
479 resp = requests.get(httpbin("get"))
480 assert isinstance(resp.history, list)481 resp = requests.get(httpbin("redirect/1"))482 assert isinstance(resp.history, list)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 483why, one step back
483 assert not isinstance(resp.history, tuple)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 484why, one step back
484

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 485–486why, one step back
485 def test_headers_on_session_with_None_are_not_sent(self, httpbin):
486 """Do not send headers in Session.headers with None values."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 487–492why, one step back
487 ses = requests.Session()
488 ses.headers["Accept-Encoding"] = None489 req = requests.Request("GET", httpbin("get"))490 prep = ses.prepare_request(req)491 assert "Accept-Encoding" not in prep.headers492

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 493–494why, one step back
493 def test_headers_preserve_order(self, httpbin):
494 """Preserve order when headers provided as OrderedDict."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 495why, one step back
495 ses = requests.Session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 496why, one step back
496 ses.headers = collections.OrderedDict()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 497–504why, one step back
497 ses.headers["Accept-Encoding"] = "identity"
498 ses.headers["First"] = "1"499 ses.headers["Second"] = "2"500 headers = collections.OrderedDict([("Third", "3"), ("Fourth", "4")])501 headers["Fifth"] = "5"502 headers["Second"] = "222"503 req = requests.Request("GET", httpbin("get"), headers=headers)504 prep = ses.prepare_request(req)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 505why, one step back
505 items = list(prep.headers.items())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 506–513why, one step back
506 assert items[0] == ("Accept-Encoding", "identity")
507 assert items[1] == ("First", "1")508 assert items[2] == ("Second", "222")509 assert items[3] == ("Third", "3")510 assert items[4] == ("Fourth", "4")511 assert items[5] == ("Fifth", "5")512513 @pytest.mark.parametrize("key", ("User-agent", "user-agent"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 514why, one step back
514 def test_user_agent_transfers(self, httpbin, key):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 515–517why, one step back
515 heads = {key: "Mozilla/5.0 (github.com/psf/requests)"}
516517 r = requests.get(httpbin("user-agent"), headers=heads)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 518why, one step back
518 assert heads[key] in r.text

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 519why, one step back
519

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 520why, one step back
520 def test_HTTP_200_OK_HEAD(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 521–523why, one step back
521 r = requests.head(httpbin("get"))
522 assert r.status_code == 200523

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 524why, one step back
524 def test_HTTP_200_OK_PUT(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 525–527why, one step back
525 r = requests.put(httpbin("put"))
526 assert r.status_code == 200527

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 528why, one step back
528 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 529–531why, one step back
529 auth = ("user", "pass")
530 url = httpbin("basic-auth", "user", "pass")531

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 532why, one step back
532 r = requests.get(url, auth=auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 533–534why, one step back
533 assert r.status_code == 200
534

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 535–536why, one step back
535 r = requests.get(url)
536 assert r.status_code == 401

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 537–538why, one step back
537
538 s = requests.session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 539–540why, one step back
539 s.auth = auth
540 r = s.get(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 541–547why, one step back
541 assert r.status_code == 200
542543 @pytest.mark.parametrize(544 "username, password",545 (546 ("user", "pass"),547 ("имя".encode(), "пароль".encode()),

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 548–549why, one step back
548 (42, 42),
549 (None, None),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 550–551why, one step back
550 ),
551 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 552–553why, one step back
552 def test_set_basicauth(self, httpbin, username, password):
553 auth = (username, password)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 554–560why, one step back
554 url = httpbin("get")
555556 r = requests.Request("GET", url, auth=auth)557 p = r.prepare()558559 assert p.headers["Authorization"] == _basic_auth_str(username, password)560

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 561–563why, one step back
561 def test_basicauth_encodes_byte_strings(self):
562 """Ensure b'test' formats as the byte string "test" rather563 than the unicode string "b'test'" in Python 3.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 564–573why, one step back
564 """
565 auth = (b"\xc5\xafsername", b"test\xc6\xb6")566 r = requests.Request("GET", "http://localhost", auth=auth)567 p = r.prepare()568569 assert p.headers["Authorization"] == "Basic xa9zZXJuYW1lOnRlc3TGtg=="570571 @pytest.mark.parametrize(572 "url, exception",573 (

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 574why, one step back
574 # Connecting to an unknown domain should raise a ConnectionError

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 575why, one step back
575 ("http://doesnotexist.google.com", ConnectionError),

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 576why, one step back
576 # Connecting to an invalid port should raise a ConnectionError

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 577why, one step back
577 ("http://localhost:1", ConnectionError),

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 578why, one step back
578 # Inputing a URL that cannot be parsed should raise an InvalidURL error

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 579–581why, one step back
579 ("http://fe80::5054:ff:fe5a:fc0", InvalidURL),
580 ),581 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 582why, one step back
582 def test_errors(self, url, exception):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 583why, one step back
583 with pytest.raises(exception):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 584why, one step back
584 requests.get(url, timeout=1)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 585why, one step back
585

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 586–588why, one step back
586 def test_proxy_error(self):
587 # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError588 with pytest.raises(ProxyError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 589–592why, one step back
589 requests.get(
590 "http://localhost:1", proxies={"http": "non-resolvable-address"}591 )592

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 593why, one step back
593 def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 594–605why, one step back
594 with pytest.raises(InvalidProxyURL):
595 requests.get(httpbin_secure(), proxies={"https": "http:/badproxyurl:3128"})596597 with pytest.raises(InvalidProxyURL):598 requests.get(httpbin(), proxies={"http": "http://:8080"})599600 with pytest.raises(InvalidProxyURL):601 requests.get(httpbin_secure(), proxies={"https": "https://"})602603 with pytest.raises(InvalidProxyURL):604 requests.get(httpbin(), proxies={"http": "http:///example.com:8080"})605

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 606why, one step back
606 def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 607–612why, one step back
607 with override_environ(http_proxy=INVALID_PROXY):
608 with pytest.raises(ProxyError):609 session = requests.Session()610 request = requests.Request("GET", httpbin())611 session.send(request.prepare())612

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 613why, one step back
613 def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 614–617why, one step back
614 with override_environ(http_proxy=INVALID_PROXY):
615 with pytest.raises(ProxyError):616 session = requests.Session()617 request = requests.Request("GET", httpbin())

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

lines 618–619why, one step back
618 prepared = session.prepare_request(request)
619 session.send(prepared)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 620why, one step back
620

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 621why, one step back
621 def test_respect_proxy_env_on_send_with_redirects(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 622–625why, one step back
622 with override_environ(http_proxy=INVALID_PROXY):
623 with pytest.raises(ProxyError):624 session = requests.Session()625 url = httpbin("redirect/1")

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 626why, one step back
626 print(url)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 627–629why, one step back
627 request = requests.Request("GET", url)
628 session.send(request.prepare())629

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 630why, one step back
630 def test_respect_proxy_env_on_get(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 631–633why, one step back
631 with override_environ(http_proxy=INVALID_PROXY):
632 with pytest.raises(ProxyError):633 session = requests.Session()

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 634why, one step back
634 session.get(httpbin())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 635why, one step back
635

Merge pull request #5681 from mateusduboli/5677Ian Stapleton Cordascobefore adoption8c211a9

line 636why, one step back
636 def test_respect_proxy_env_on_request(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 637–641why, one step back
637 with override_environ(http_proxy=INVALID_PROXY):
638 with pytest.raises(ProxyError):639 session = requests.Session()640 session.request(method="GET", url=httpbin())641

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

lines 642–643why, one step back
642 def test_proxy_authorization_preserved_on_request(self, httpbin):
643 proxy_auth_value = "Bearer XXX"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 644why, one step back
644 session = requests.Session()

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

line 645why, one step back
645 session.headers.update({"Proxy-Authorization": proxy_auth_value})

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 646–648why, one step back
646 resp = session.request(method="GET", url=httpbin("get"))
647 sent_headers = resp.json().get("headers", {})648

Refactor rebuild_proxies to allow proxy resolution (#5924)Nate Prewittbefore adoption99b3b49

line 649why, one step back
649 assert sent_headers.get("Proxy-Authorization") == proxy_auth_value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 650why, one step back
650

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 651–653why, one step back
651 @pytest.mark.parametrize(
652 "url,has_proxy_auth",653 (

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 654–655why, one step back
654 ("http://example.com", True),
655 ("https://example.com", False),

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 656–657why, one step back
656 ),
657 )

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 658–660why, one step back
658 def test_proxy_authorization_not_appended_to_https_request(
659 self, url, has_proxy_auth660 ):

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 661–662why, one step back
661 session = requests.Session()
662 proxies = {

Fix linting issuesNate Prewittbefore adoption6e5b15d

lines 663–664why, one step back
663 "http": "http://test:pass@localhost:8080",
664 "https": "http://test:pass@localhost:8090",

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 665why, one step back
665 }

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 666why, one step back
666 req = requests.Request("GET", url)

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

lines 667–669why, one step back
667 prep = req.prepare()
668 session.rebuild_proxies(prep, proxies)669

Fix linting issuesNate Prewittbefore adoption6e5b15d

line 670why, one step back
670 assert ("Proxy-Authorization" in prep.headers) is has_proxy_auth

Merge pull request from GHSA-j8r2-6x86-q33qNate Prewittbefore adoption74ea7cf

line 671why, one step back
671

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 672why, one step back
672 def test_basicauth_with_netrc(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 673–676why, one step back
673 auth = ("user", "pass")
674 wrong_auth = ("wronguser", "wrongpass")675 url = httpbin("basic-auth", "user", "pass")676

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 677why, one step back
677 old_auth = requests.sessions.get_netrc_auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 678–680why, one step back
678
679 try:680

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 681–682why, one step back
681 def get_netrc_auth_mock(url):
682 return auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 683why, one step back
683

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 684why, one step back
684 requests.sessions.get_netrc_auth = get_netrc_auth_mock

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 685–690why, one step back
685
686 # Should use netrc and work.687 r = requests.get(url)688 assert r.status_code == 200689690 # Given auth should override and fail.

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 691why, one step back
691 r = requests.get(url, auth=wrong_auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 692–700why, one step back
692 assert r.status_code == 401
693694 s = requests.session()695696 # Should use netrc and work.697 r = s.get(url)698 assert r.status_code == 200699700 # Given auth should override and fail.

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 701why, one step back
701 s.auth = wrong_auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 702–703why, one step back
702 r = s.get(url)
703 assert r.status_code == 401

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 704–705why, one step back
704 finally:
705 requests.sessions.get_netrc_auth = old_auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 706why, one step back
706

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 707why, one step back
707 def test_DIGEST_HTTP_200_OK_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 708–723why, one step back
708 for authtype in self.digest_auth_algo:
709 auth = HTTPDigestAuth("user", "pass")710 url = httpbin("digest-auth", "auth", "user", "pass", authtype, "never")711712 r = requests.get(url, auth=auth)713 assert r.status_code == 200714715 r = requests.get(url)716 assert r.status_code == 401717 print(r.headers["WWW-Authenticate"])718719 s = requests.session()720 s.auth = HTTPDigestAuth("user", "pass")721 r = s.get(url)722 assert r.status_code == 200723

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 724why, one step back
724 def test_DIGEST_AUTH_RETURNS_COOKIE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 725–733why, one step back
725 for authtype in self.digest_auth_algo:
726 url = httpbin("digest-auth", "auth", "user", "pass", authtype)727 auth = HTTPDigestAuth("user", "pass")728 r = requests.get(url)729 assert r.cookies["fake"] == "fake_value"730731 r = requests.get(url, auth=auth)732 assert r.status_code == 200733

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 734why, one step back
734 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 735–737why, one step back
735 for authtype in self.digest_auth_algo:
736 url = httpbin("digest-auth", "auth", "user", "pass", authtype)737 auth = HTTPDigestAuth("user", "pass")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 738–739why, one step back
738 s = requests.Session()
739 s.get(url, auth=auth)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 740–741why, one step back
740 assert s.cookies["fake"] == "fake_value"
741

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 742why, one step back
742 def test_DIGEST_STREAM(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 743–746why, one step back
743 for authtype in self.digest_auth_algo:
744 auth = HTTPDigestAuth("user", "pass")745 url = httpbin("digest-auth", "auth", "user", "pass", authtype)746

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 747why, one step back
747 r = requests.get(url, auth=auth, stream=True)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 748–749why, one step back
748 assert r.raw.read() != b""
749

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 750why, one step back
750 r = requests.get(url, auth=auth, stream=False)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 751–752why, one step back
751 assert r.raw.read() == b""
752

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 753why, one step back
753 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 754–764why, one step back
754 for authtype in self.digest_auth_algo:
755 auth = HTTPDigestAuth("user", "wrongpass")756 url = httpbin("digest-auth", "auth", "user", "pass", authtype)757758 r = requests.get(url, auth=auth)759 assert r.status_code == 401760761 r = requests.get(url)762 assert r.status_code == 401763764 s = requests.session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 765why, one step back
765 s.auth = auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 766–768why, one step back
766 r = s.get(url)
767 assert r.status_code == 401768

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 769why, one step back
769 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 770–776why, one step back
770 for authtype in self.digest_auth_algo:
771 auth = HTTPDigestAuth("user", "pass")772 url = httpbin("digest-auth", "auth", "user", "pass", authtype)773774 r = requests.get(url, auth=auth)775 assert '"auth"' in r.request.headers["Authorization"]776

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 777why, one step back
777 def test_POSTBIN_GET_POST_FILES(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 778–793why, one step back
778 url = httpbin("post")
779 requests.post(url).raise_for_status()780781 post1 = requests.post(url, data={"some": "data"})782 assert post1.status_code == 200783784 with open("requirements-dev.txt") as f:785 post2 = requests.post(url, files={"some": f})786 assert post2.status_code == 200787788 post4 = requests.post(url, data='[{"some": "json"}]')789 assert post4.status_code == 200790791 with pytest.raises(ValueError):792 requests.post(url, files=["bad file data"])793

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 794why, one step back
794 def test_invalid_files_input(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 795–796why, one step back
795 url = httpbin("post")
796 post = requests.post(url, files={"random-file-1": None, "random-file-2": 1})

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 797–798why, one step back
797 assert b'name="random-file-1"' not in post.request.body
798 assert b'name="random-file-2"' in post.request.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 799why, one step back
799

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 800why, one step back
800 def test_POSTBIN_SEEKED_OBJECT_WITH_NO_ITER(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 801–802why, one step back
801 class TestStream:
802 def __init__(self, data):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 803–805why, one step back
803 self.data = data.encode()
804 self.length = len(self.data)805 self.index = 0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 806–807why, one step back
806
807 def __len__(self):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 808why, one step back
808 return self.length

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 809why, one step back
809

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 810–811why, one step back
810 def read(self, size=None):
811 if size:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 812why, one step back
812 ret = self.data[self.index : self.index + size]

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 813–814why, one step back
813 self.index += size
814 else:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 815why, one step back
815 ret = self.data[self.index :]

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 816–817why, one step back
816 self.index = self.length
817 return ret

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 818–819why, one step back
818
819 def tell(self):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 820why, one step back
820 return self.index

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 821why, one step back
821

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 822–828why, one step back
822 def seek(self, offset, where=0):
823 if where == 0:824 self.index = offset825 elif where == 1:826 self.index += offset827 elif where == 2:828 self.index = self.length + offset

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 829–835why, one step back
829
830 test = TestStream("test")831 post1 = requests.post(httpbin("post"), data=test)832 assert post1.status_code == 200833 assert post1.json()["data"] == "test"834835 test = TestStream("test")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 836why, one step back
836 test.seek(2)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 837–840why, one step back
837 post2 = requests.post(httpbin("post"), data=test)
838 assert post2.status_code == 200839 assert post2.json()["data"] == "st"840

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 841why, one step back
841 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 842–857why, one step back
842 url = httpbin("post")
843 requests.post(url).raise_for_status()844845 post1 = requests.post(url, data={"some": "data"})846 assert post1.status_code == 200847848 with open("requirements-dev.txt") as f:849 post2 = requests.post(url, data={"some": "data"}, files={"some": f})850 assert post2.status_code == 200851852 post4 = requests.post(url, data='[{"some": "json"}]')853 assert post4.status_code == 200854855 with pytest.raises(ValueError):856 requests.post(url, files=["bad file data"])857

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 858–861why, one step back
858 def test_post_with_custom_mapping(self, httpbin):
859 class CustomMapping(MutableMapping):860 def __init__(self, *args, **kwargs):861 self.data = dict(*args, **kwargs)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 862why, one step back
862

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 863–864why, one step back
863 def __delitem__(self, key):
864 del self.data[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 865why, one step back
865

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 866–867why, one step back
866 def __getitem__(self, key):
867 return self.data[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 868why, one step back
868

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 869–870why, one step back
869 def __setitem__(self, key, value):
870 self.data[key] = value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 871–872why, one step back
871
872 def __iter__(self):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 873why, one step back
873 return iter(self.data)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 874–875why, one step back
874
875 def __len__(self):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 876why, one step back
876 return len(self.data)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 877–882why, one step back
877
878 data = CustomMapping({"some": "data"})879 url = httpbin("post")880 found_json = requests.post(url, data=data).json().get("form")881 assert found_json == {"some": "data"}882

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 883why, one step back
883 def test_conflicting_post_params(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 884–885why, one step back
884 url = httpbin("post")
885 with open("requirements-dev.txt") as f:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 886why, one step back
886 with pytest.raises(ValueError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 887–888why, one step back
887 requests.post(url, data='[{"some": "data"}]', files={"some": f})
888

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 889why, one step back
889 def test_request_ok_set(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 890–892why, one step back
890 r = requests.get(httpbin("status", "404"))
891 assert not r.ok892

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 893why, one step back
893 def test_status_raising(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 894why, one step back
894 r = requests.get(httpbin("status", "404"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 895why, one step back
895 with pytest.raises(requests.exceptions.HTTPError):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 896–900why, one step back
896 r.raise_for_status()
897898 r = requests.get(httpbin("status", "500"))899 assert not r.ok900

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 901why, one step back
901 def test_decompress_gzip(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 902–914why, one step back
902 r = requests.get(httpbin("gzip"))
903 r.content.decode("ascii")904905 @pytest.mark.parametrize(906 "url, params",907 (908 ("/get", {"foo": "føø"}),909 ("/get", {"føø": "føø"}),910 ("/get", {"føø": "føø"}),911 ("/get", {"foo": "foo"}),912 ("ø", {"foo": "foo"}),913 ),914 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 915–916why, one step back
915 def test_unicode_get(self, httpbin, url, params):
916 requests.get(httpbin(url), params=params)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 917why, one step back
917

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 918–919why, one step back
918 def test_unicode_header_name(self, httpbin):
919 requests.put(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 920–924why, one step back
920 httpbin("put"),
921 headers={"Content-Type": "application/octet-stream"},922 data="\xff",923 ) # compat.str is unicode.924

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 925why, one step back
925 def test_pyopenssl_redirect(self, httpbin_secure, httpbin_ca_bundle):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 926–927why, one step back
926 requests.get(httpbin_secure("status", "301"), verify=httpbin_ca_bundle)
927

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 928why, one step back
928 def test_invalid_ca_certificate_path(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 929–930why, one step back
929 INVALID_PATH = "/garbage"
930 with pytest.raises(IOError) as e:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 931why, one step back
931 requests.get(httpbin_secure(), verify=INVALID_PATH)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 932–937why, one step back
932 assert str(
933 e.value934 ) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format(935 INVALID_PATH936 )937

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 938why, one step back
938 def test_invalid_ssl_certificate_files(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 939–940why, one step back
939 INVALID_PATH = "/garbage"
940 with pytest.raises(IOError) as e:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 941why, one step back
941 requests.get(httpbin_secure(), cert=INVALID_PATH)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 942–956why, one step back
942 assert str(
943 e.value944 ) == "Could not find the TLS certificate file, invalid path: {}".format(945 INVALID_PATH946 )947948 with pytest.raises(IOError) as e:949 requests.get(httpbin_secure(), cert=(".", INVALID_PATH))950 assert str(e.value) == (951 f"Could not find the TLS key file, invalid path: {INVALID_PATH}"952 )953954 @pytest.mark.parametrize(955 "env, expected",956 (

Merge pull request #6074 from nateprewitt/curl_ca_bundleIan Stapleton Cordascobefore adoption79f6027

line 957why, one step back
957 ({}, True),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 958–978why, one step back
958 ({"REQUESTS_CA_BUNDLE": "/some/path"}, "/some/path"),
959 ({"REQUESTS_CA_BUNDLE": ""}, True),960 ({"CURL_CA_BUNDLE": "/some/path"}, "/some/path"),961 ({"CURL_CA_BUNDLE": ""}, True),962 ({"REQUESTS_CA_BUNDLE": "", "CURL_CA_BUNDLE": ""}, True),963 (964 {965 "REQUESTS_CA_BUNDLE": "/some/path",966 "CURL_CA_BUNDLE": "/curl/path",967 },968 "/some/path",969 ),970 (971 {972 "REQUESTS_CA_BUNDLE": "",973 "CURL_CA_BUNDLE": "/curl/path",974 },975 "/curl/path",976 ),977 ),978 )

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 979why, one step back
979 def test_env_cert_bundles(self, httpbin, env, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 980why, one step back
980 s = requests.Session()

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

lines 981–984why, one step back
981 with mock.patch("os.environ", env):
982 settings = s.merge_environment_settings(983 url=httpbin("get"), proxies={}, stream=False, verify=True, cert=None984 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 985–986why, one step back
985 assert settings["verify"] == expected
986

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 987why, one step back
987 def test_http_with_certificate(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 988–990why, one step back
988 r = requests.get(httpbin(), cert=".")
989 assert r.status_code == 200990

Support missing SNIMissingWarning in tests (#6336)Quentin Pradetbefore adoption1558590

lines 991–994why, one step back
991 @pytest.mark.skipif(
992 SNIMissingWarning is None,993 reason="urllib3 2.0 removed that warning and errors out instead",994 )

Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba

line 995why, one step back
995 def test_https_warnings(self, nosan_server):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 996why, one step back
996 """warnings are emitted with requests.get"""

Stop abusing pytest-httpbin to test commonName supportQuentin Pradetbefore adoptione253eba

line 997why, one step back
997 host, port, ca_bundle = nosan_server

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 998why, one step back
998 if HAS_MODERN_SSL or HAS_PYOPENSSL:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 999–1006why, one step back
999 warnings_expected = ("SubjectAltNameWarning",)
1000 else:1001 warnings_expected = (1002 "SNIMissingWarning",1003 "InsecurePlatformWarning",1004 "SubjectAltNameWarning",1005 )1006

Merge pull request #6682 from frenzymadness/pytest8Ian Stapleton Cordascobefore adoption31ebb81

line 1007why, one step back
1007 with pytest.warns() as warning_records:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1008–1017why, one step back
1008 warnings.simplefilter("always")
1009 requests.get(f"https://localhost:{port}/", verify=ca_bundle)10101011 warning_records = [1012 item1013 for item in warning_records1014 if item.category.__name__ != "ResourceWarning"1015 ]10161017 warnings_category = tuple(item.category.__name__ for item in warning_records)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1018why, one step back
1018 assert warnings_category == warnings_expected

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1019why, one step back
1019

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1020why, one step back
1020 def test_certificate_failure(self, httpbin_secure):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1021why, one step back
1021 """

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1022why, one step back
1022 When underlying SSL problems occur, an SSLError is raised.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1023why, one step back
1023 """

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1024why, one step back
1024 with pytest.raises(RequestsSSLError):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1025–1026why, one step back
1025 # Our local httpbin does not have a trusted CA, so this call will
1026 # fail if we use our default trust bundle.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1027–1028why, one step back
1027 requests.get(httpbin_secure("status", "200"))
1028

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1029why, one step back
1029 def test_urlencoded_get_query_multivalued_param(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1030–1033why, one step back
1030 r = requests.get(httpbin("get"), params={"test": ["foo", "baz"]})
1031 assert r.status_code == 2001032 assert r.url == httpbin("get?test=foo&test=baz")1033

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1034why, one step back
1034 def test_form_encoded_post_query_multivalued_element(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1035–1040why, one step back
1035 r = requests.Request(
1036 method="POST", url=httpbin("post"), data=dict(test=["foo", "baz"])1037 )1038 prep = r.prepare()1039 assert prep.body == "test=foo&test=baz"1040

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1041why, one step back
1041 def test_different_encodings_dont_break_post(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1042–1048why, one step back
1042 with open(__file__, "rb") as f:
1043 r = requests.post(1044 httpbin("post"),1045 data={"stuff": json.dumps({"a": 123})},1046 params={"blah": "asdf1234"},1047 files={"file": ("test_requests.py", f)},1048 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1049–1059why, one step back
1049 assert r.status_code == 200
10501051 @pytest.mark.parametrize(1052 "data",1053 (1054 {"stuff": "ëlïxr"},1055 {"stuff": "ëlïxr".encode()},1056 {"stuff": "elixr"},1057 {"stuff": b"elixr"},1058 ),1059 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1060why, one step back
1060 def test_unicode_multipart_post(self, httpbin, data):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1061–1066why, one step back
1061 with open(__file__, "rb") as f:
1062 r = requests.post(1063 httpbin("post"),1064 data=data,1065 files={"file": ("test_requests.py", f)},1066 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1067–1068why, one step back
1067 assert r.status_code == 200
1068

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1069why, one step back
1069 def test_unicode_multipart_post_fieldnames(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1070why, one step back
1070 filename = os.path.splitext(__file__)[0] + ".py"

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1071–1079why, one step back
1071 with open(filename, "rb") as f:
1072 r = requests.Request(1073 method="POST",1074 url=httpbin("post"),1075 data={b"stuff": "elixr"},1076 files={"file": ("test_requests.py", f)},1077 )1078 prep = r.prepare()1079

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1080why, one step back
1080 assert b'name="stuff"' in prep.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1081–1082why, one step back
1081 assert b"name=\"b'stuff'\"" not in prep.body
1082

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1083why, one step back
1083 def test_unicode_method_name(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1084–1090why, one step back
1084 with open(__file__, "rb") as f:
1085 files = {"file": f}1086 r = requests.request(1087 method="POST",1088 url=httpbin("post"),1089 files=files,1090 )

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1091–1092why, one step back
1091 assert r.status_code == 200
1092

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1093why, one step back
1093 def test_unicode_method_name_with_request_object(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1094why, one step back
1094 s = requests.Session()

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1095–1098why, one step back
1095 with open(__file__, "rb") as f:
1096 files = {"file": f}1097 req = requests.Request("POST", httpbin("post"), files=files)1098 prep = s.prepare_request(req)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1099why, one step back
1099 assert isinstance(prep.method, builtin_str)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1100–1104why, one step back
1100 assert prep.method == "POST"
11011102 resp = s.send(prep)1103 assert resp.status_code == 2001104

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1105why, one step back
1105 def test_non_prepared_request_error(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1106–1109why, one step back
1106 s = requests.Session()
1107 req = requests.Request("POST", "/")11081109 with pytest.raises(ValueError) as e:

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1110why, one step back
1110 s.send(req)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1111–1112why, one step back
1111 assert str(e.value) == "You can only send PreparedRequests."
1112

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1113why, one step back
1113 def test_custom_content_type(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1114–1115why, one step back
1114 with open(__file__, "rb") as f1:
1115 with open(__file__, "rb") as f2:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1116why, one step back
1116 data = {"stuff": json.dumps({"a": 123})}

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1117–1121why, one step back
1117 files = {
1118 "file1": ("test_requests.py", f1),1119 "file2": ("test_requests", f2, "text/py-content-type"),1120 }1121 r = requests.post(httpbin("post"), data=data, files=files)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1122why, one step back
1122 assert r.status_code == 200

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1123why, one step back
1123 assert b"text/py-content-type" in r.request.body

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1124why, one step back
1124

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1125why, one step back
1125 def test_hook_receives_request_arguments(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1126why, one step back
1126 def hook(resp, **kwargs):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1127–1128why, one step back
1127 assert resp is not None
1128 assert kwargs != {}

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1129–1132why, one step back
1129
1130 s = requests.Session()1131 r = requests.Request("GET", httpbin(), hooks={"response": hook})1132 prep = s.prepare_request(r)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1133why, one step back
1133 s.send(prep)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1134why, one step back
1134

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1135why, one step back
1135 def test_session_hooks_are_used_with_no_request_hooks(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1136–1145why, one step back
1136 def hook(*args, **kwargs):
1137 pass11381139 s = requests.Session()1140 s.hooks["response"].append(hook)1141 r = requests.Request("GET", httpbin())1142 prep = s.prepare_request(r)1143 assert prep.hooks["response"] != []1144 assert prep.hooks["response"] == [hook]1145

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1146why, one step back
1146 def test_session_hooks_are_overridden_by_request_hooks(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1147–1152why, one step back
1147 def hook1(*args, **kwargs):
1148 pass11491150 def hook2(*args, **kwargs):1151 pass1152

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1153why, one step back
1153 assert hook1 is not hook2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1154–1159why, one step back
1154 s = requests.Session()
1155 s.hooks["response"].append(hook2)1156 r = requests.Request("GET", httpbin(), hooks={"response": [hook1]})1157 prep = s.prepare_request(r)1158 assert prep.hooks["response"] == [hook1]1159

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1160why, one step back
1160 def test_prepared_request_hook(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1161why, one step back
1161 def hook(resp, **kwargs):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1162why, one step back
1162 resp.hook_working = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1163–1165why, one step back
1163 return resp
11641165 req = requests.Request("GET", httpbin(), hooks={"response": hook})

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1166why, one step back
1166 prep = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1167–1173why, one step back
1167
1168 s = requests.Session()1169 s.proxies = getproxies()1170 resp = s.send(prep)11711172 assert hasattr(resp, "hook_working")1173

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1174–1176why, one step back
1174 def test_prepared_from_session(self, httpbin):
1175 class DummyAuth(requests.auth.AuthBase):1176 def __call__(self, r):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1177why, one step back
1177 r.headers["Dummy-Auth-Test"] = "dummy-auth-test-ok"

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1178why, one step back
1178 return r

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1179–1180why, one step back
1179
1180 req = requests.Request("GET", httpbin("headers"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1181why, one step back
1181 assert not req.auth

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1182–1183why, one step back
1182
1183 s = requests.Session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1184why, one step back
1184 s.auth = DummyAuth()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1185–1190why, one step back
1185
1186 prep = s.prepare_request(req)1187 resp = s.send(prep)11881189 assert resp.json()["headers"]["Dummy-Auth-Test"] == "dummy-auth-test-ok"1190

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1191why, one step back
1191 def test_prepare_request_with_bytestring_url(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1192–1194why, one step back
1192 req = requests.Request("GET", b"https://httpbin.org/")
1193 s = requests.Session()1194 prep = s.prepare_request(req)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1195why, one step back
1195 assert prep.url == "https://httpbin.org/"

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1196why, one step back
1196

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1197why, one step back
1197 def test_request_with_bytestring_host(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1198why, one step back
1198 s = requests.Session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1199why, one step back
1199 resp = s.request(

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1200–1201why, one step back
1200 "GET",
1201 httpbin("cookies/set?cookie=value"),

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1202why, one step back
1202 allow_redirects=False,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1203–1206why, one step back
1203 headers={"Host": b"httpbin.org"},
1204 )1205 assert resp.cookies.get("cookie") == "value"1206

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1207why, one step back
1207 def test_links(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1208why, one step back
1208 r = requests.Response()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1209why, one step back
1209 r.headers = {

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1210–1232why, one step back
1210 "cache-control": "public, max-age=60, s-maxage=60",
1211 "connection": "keep-alive",1212 "content-encoding": "gzip",1213 "content-type": "application/json; charset=utf-8",1214 "date": "Sat, 26 Jan 2013 16:47:56 GMT",1215 "etag": '"6ff6a73c0e446c1f61614769e3ceb778"',1216 "last-modified": "Sat, 26 Jan 2013 16:22:39 GMT",1217 "link": (1218 "<https://api.github.com/users/kennethreitz/repos?"1219 'page=2&per_page=10>; rel="next", <https://api.github.'1220 "com/users/kennethreitz/repos?page=7&per_page=10>; "1221 ' rel="last"'1222 ),1223 "server": "GitHub.com",1224 "status": "200 OK",1225 "vary": "Accept",1226 "x-content-type-options": "nosniff",1227 "x-github-media-type": "github.beta",1228 "x-ratelimit-limit": "60",1229 "x-ratelimit-remaining": "57",1230 }1231 assert r.links["next"]["rel"] == "next"1232

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1233why, one step back
1233 def test_cookie_parameters(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1234–1235why, one step back
1234 key = "some_cookie"
1235 value = "some_value"

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1236why, one step back
1236 secure = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1237–1240why, one step back
1237 domain = "test.com"
1238 rest = {"HttpOnly": True}12391240 jar = requests.cookies.RequestsCookieJar()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1241why, one step back
1241 jar.set(key, value, secure=secure, domain=domain, rest=rest)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1242why, one step back
1242

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1243why, one step back
1243 assert len(jar) == 1

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1244–1245why, one step back
1244 assert "some_cookie" in jar
1245

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1246–1248why, one step back
1246 cookie = list(jar)[0]
1247 assert cookie.secure == secure1248 assert cookie.domain == domain

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1249–1250why, one step back
1249 assert cookie._rest["HttpOnly"] == rest["HttpOnly"]
1250

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1251why, one step back
1251 def test_cookie_as_dict_keeps_len(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1252–1265why, one step back
1252 key = "some_cookie"
1253 value = "some_value"12541255 key1 = "some_cookie1"1256 value1 = "some_value1"12571258 jar = requests.cookies.RequestsCookieJar()1259 jar.set(key, value)1260 jar.set(key1, value1)12611262 d1 = dict(jar)1263 d2 = dict(jar.iteritems())1264 d3 = dict(jar.items())1265

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1266–1269why, one step back
1266 assert len(jar) == 2
1267 assert len(d1) == 21268 assert len(d2) == 21269 assert len(d3) == 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1270why, one step back
1270

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1271why, one step back
1271 def test_cookie_as_dict_keeps_items(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1272–1289why, one step back
1272 key = "some_cookie"
1273 value = "some_value"12741275 key1 = "some_cookie1"1276 value1 = "some_value1"12771278 jar = requests.cookies.RequestsCookieJar()1279 jar.set(key, value)1280 jar.set(key1, value1)12811282 d1 = dict(jar)1283 d2 = dict(jar.iteritems())1284 d3 = dict(jar.items())12851286 assert d1["some_cookie"] == "some_value"1287 assert d2["some_cookie"] == "some_value"1288 assert d3["some_cookie1"] == "some_value1"1289

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1290why, one step back
1290 def test_cookie_as_dict_keys(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1291–1300why, one step back
1291 key = "some_cookie"
1292 value = "some_value"12931294 key1 = "some_cookie1"1295 value1 = "some_value1"12961297 jar = requests.cookies.RequestsCookieJar()1298 jar.set(key, value)1299 jar.set(key1, value1)1300

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1301–1304why, one step back
1301 keys = jar.keys()
1302 assert keys == list(keys)1303 # make sure one can use keys multiple times1304 assert list(keys) == list(keys)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1305why, one step back
1305

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1306why, one step back
1306 def test_cookie_as_dict_values(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1307–1316why, one step back
1307 key = "some_cookie"
1308 value = "some_value"13091310 key1 = "some_cookie1"1311 value1 = "some_value1"13121313 jar = requests.cookies.RequestsCookieJar()1314 jar.set(key, value)1315 jar.set(key1, value1)1316

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1317–1320why, one step back
1317 values = jar.values()
1318 assert values == list(values)1319 # make sure one can use values multiple times1320 assert list(values) == list(values)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1321why, one step back
1321

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1322why, one step back
1322 def test_cookie_as_dict_items(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1323–1333why, one step back
1323 key = "some_cookie"
1324 value = "some_value"13251326 key1 = "some_cookie1"1327 value1 = "some_value1"13281329 jar = requests.cookies.RequestsCookieJar()1330 jar.set(key, value)1331 jar.set(key1, value1)13321333 items = jar.items()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1334–1336why, one step back
1334 assert items == list(items)
1335 # make sure one can use items multiple times1336 assert list(items) == list(items)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1337why, one step back
1337

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1338why, one step back
1338 def test_cookie_duplicate_names_different_domains(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1339–1344why, one step back
1339 key = "some_cookie"
1340 value = "some_value"1341 domain1 = "test1.com"1342 domain2 = "test2.com"13431344 jar = requests.cookies.RequestsCookieJar()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1345–1347why, one step back
1345 jar.set(key, value, domain=domain1)
1346 jar.set(key, value, domain=domain2)1347 assert key in jar

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1348why, one step back
1348 items = jar.items()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1349why, one step back
1349 assert len(items) == 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1350why, one step back
1350

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1351why, one step back
1351 # Verify that CookieConflictError is raised if domain is not specified

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1352–1354why, one step back
1352 with pytest.raises(requests.cookies.CookieConflictError):
1353 jar.get(key)1354

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1355–1357why, one step back
1355 # Verify that CookieConflictError is not raised if domain is specified
1356 cookie = jar.get(key, domain=domain1)1357 assert cookie == value

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1358why, one step back
1358

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1359why, one step back
1359 def test_cookie_duplicate_names_raises_cookie_conflict_error(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1360–1364why, one step back
1360 key = "some_cookie"
1361 value = "some_value"1362 path = "some_path"13631364 jar = requests.cookies.RequestsCookieJar()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1365why, one step back
1365 jar.set(key, value, path=path)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1366–1369why, one step back
1366 jar.set(key, value)
1367 with pytest.raises(requests.cookies.CookieConflictError):1368 jar.get(key)1369

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1370–1371why, one step back
1370 def test_cookie_policy_copy(self):
1371 class MyCookiePolicy(cookielib.DefaultCookiePolicy):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1372–1374why, one step back
1372 pass
13731374 jar = requests.cookies.RequestsCookieJar()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1375–1376why, one step back
1375 jar.set_policy(MyCookiePolicy())
1376 assert isinstance(jar.copy().get_policy(), MyCookiePolicy)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1377why, one step back
1377

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1378why, one step back
1378 def test_time_elapsed_blank(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1379why, one step back
1379 r = requests.get(httpbin("get"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1380why, one step back
1380 td = r.elapsed

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1381–1383why, one step back
1381 total_seconds = (
1382 td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**61383 ) / 10**6

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1384why, one step back
1384 assert total_seconds > 0.0

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1385why, one step back
1385

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1386why, one step back
1386 def test_empty_response_has_content_none(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1387–1389why, one step back
1387 r = requests.Response()
1388 assert r.content is None1389

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1390why, one step back
1390 def test_response_is_iterable(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1391–1392why, one step back
1391 r = requests.Response()
1392 io = StringIO.StringIO("abc")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1393why, one step back
1393 read_ = io.read

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1394why, one step back
1394

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1395–1396why, one step back
1395 def read_mock(amt, decode_content=None):
1396 return read_(amt)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1397–1398why, one step back
1397
1398 setattr(io, "read", read_mock)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1399–1401why, one step back
1399 r.raw = io
1400 assert next(iter(r))1401 io.close()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1402why, one step back
1402

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1403–1405why, one step back
1403 def test_response_decode_unicode(self):
1404 """When called with decode_unicode, Response.iter_content should always1405 return unicode.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1406–1407why, one step back
1406 """
1407 r = requests.Response()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1408why, one step back
1408 r._content_consumed = True

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1409–1414why, one step back
1409 r._content = b"the content"
1410 r.encoding = "ascii"14111412 chunks = r.iter_content(decode_unicode=True)1413 assert all(isinstance(chunk, str) for chunk in chunks)1414

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1415why, one step back
1415 # also for streaming

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1416–1421why, one step back
1416 r = requests.Response()
1417 r.raw = io.BytesIO(b"the content")1418 r.encoding = "ascii"1419 chunks = r.iter_content(decode_unicode=True)1420 assert all(isinstance(chunk, str) for chunk in chunks)1421

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1422–1423why, one step back
1422 def test_response_reason_unicode(self):
1423 # check for unicode HTTP status

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1424–1426why, one step back
1424 r = requests.Response()
1425 r.url = "unicode URL"1426 r.reason = "Komponenttia ei löydy".encode()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1427why, one step back
1427 r.status_code = 404

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1428why, one step back
1428 r.encoding = None

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1429why, one step back
1429 assert not r.ok # old behaviour - crashes here

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1430why, one step back
1430

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1431–1432why, one step back
1431 def test_response_reason_unicode_fallback(self):
1432 # check raise_status falls back to ISO-8859-1

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1433–1436why, one step back
1433 r = requests.Response()
1434 r.url = "some url"1435 reason = "Komponenttia ei löydy"1436 r.reason = reason.encode("latin-1")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1437why, one step back
1437 r.status_code = 500

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1438why, one step back
1438 r.encoding = None

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1439why, one step back
1439 with pytest.raises(requests.exceptions.HTTPError) as e:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1440why, one step back
1440 r.raise_for_status()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1441why, one step back
1441 assert reason in e.value.args[0]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1442why, one step back
1442

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1443–1445why, one step back
1443 def test_response_chunk_size_type(self):
1444 """Ensure that chunk_size is passed as None or an integer, otherwise1445 raise a TypeError.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1446–1448why, one step back
1446 """
1447 r = requests.Response()1448 r.raw = io.BytesIO(b"the content")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1449–1450why, one step back
1449 chunks = r.iter_content(1)
1450 assert all(len(chunk) == 1 for chunk in chunks)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1451–1453why, one step back
1451
1452 r = requests.Response()1453 r.raw = io.BytesIO(b"the content")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1454why, one step back
1454 chunks = r.iter_content(None)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1455–1459why, one step back
1455 assert list(chunks) == [b"the content"]
14561457 r = requests.Response()1458 r.raw = io.BytesIO(b"the content")1459 with pytest.raises(TypeError):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1460why, one step back
1460 chunks = r.iter_content("1024")

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1461–1464why, one step back
1461
1462 @pytest.mark.parametrize(1463 "exception, args, expected",1464 (

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1465–1466why, one step back
1465 (urllib3.exceptions.ProtocolError, tuple(), ChunkedEncodingError),
1466 (urllib3.exceptions.DecodeError, tuple(), ContentDecodingError),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1467why, one step back
1467 (urllib3.exceptions.ReadTimeoutError, (None, "", ""), ConnectionError),

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

line 1468why, one step back
1468 (urllib3.exceptions.SSLError, tuple(), RequestsSSLError),

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1469–1470why, one step back
1469 ),
1470 )

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 1471why, one step back
1471 def test_iter_content_wraps_exceptions(self, httpbin, exception, args, expected):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1472why, one step back
1472 r = requests.Response()

Remove pytest-mock requirement (#6505)Nate Prewittbefore adoption005571d

line 1473why, one step back
1473 r.raw = mock.Mock()

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1474–1476why, one step back
1474 # ReadTimeoutError can't be initialized by mock
1475 # so we'll manually create the instance with args1476 r.raw.stream.side_effect = exception(*args)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1477why, one step back
1477

Wrap urllib3's SSLError as requests' SSLError (#6057)Nate Prewittbefore adoption95f4567

lines 1478–1479why, one step back
1478 with pytest.raises(expected):
1479 next(r.iter_content(1024))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1480why, one step back
1480

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1481why, one step back
1481 def test_request_and_response_are_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1482–1483why, one step back
1482 r = requests.get(httpbin("get"))
1483

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1484–1485why, one step back
1484 # verify we can pickle the original request
1485 assert pickle.loads(pickle.dumps(r.request))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1486why, one step back
1486

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1487–1491why, one step back
1487 # verify we can pickle the response and that we have access to
1488 # the original request.1489 pr = pickle.loads(pickle.dumps(r))1490 assert r.request.url == pr.request.url1491 assert r.request.headers == pr.request.headers

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1492why, one step back
1492

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1493why, one step back
1493 def test_prepared_request_is_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1494–1506why, one step back
1494 p = requests.Request("GET", httpbin("get")).prepare()
14951496 # Verify PreparedRequest can be pickled and unpickled1497 r = pickle.loads(pickle.dumps(p))1498 assert r.url == p.url1499 assert r.headers == p.headers1500 assert r.body == p.body15011502 # Verify unpickled PreparedRequest sends properly1503 s = requests.Session()1504 resp = s.send(r)1505 assert resp.status_code == 2001506

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1507why, one step back
1507 def test_prepared_request_with_file_is_pickleable(self, httpbin):

Fix several ResourceWarnings in test_requests.py (#4766)Mickaël Schoentgenbefore adoptioncb233a1

lines 1508–1510why, one step back
1508 with open(__file__, "rb") as f:
1509 r = requests.Request("POST", httpbin("post"), files={"file": f})1510 p = r.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1511–1522why, one step back
1511
1512 # Verify PreparedRequest can be pickled and unpickled1513 r = pickle.loads(pickle.dumps(p))1514 assert r.url == p.url1515 assert r.headers == p.headers1516 assert r.body == p.body15171518 # Verify unpickled PreparedRequest sends properly1519 s = requests.Session()1520 resp = s.send(r)1521 assert resp.status_code == 2001522

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1523why, one step back
1523 def test_prepared_request_with_hook_is_pickleable(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1524–1526why, one step back
1524 r = requests.Request("GET", httpbin("get"), hooks=default_hooks())
1525 p = r.prepare()1526

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1527why, one step back
1527 # Verify PreparedRequest can be pickled

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1528–1531why, one step back
1528 r = pickle.loads(pickle.dumps(p))
1529 assert r.url == p.url1530 assert r.headers == p.headers1531 assert r.body == p.body

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1532why, one step back
1532 assert r.hooks == p.hooks

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1533–1538why, one step back
1533
1534 # Verify unpickled PreparedRequest sends properly1535 s = requests.Session()1536 resp = s.send(r)1537 assert resp.status_code == 2001538

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1539–1540why, one step back
1539 def test_cannot_send_unprepared_requests(self, httpbin):
1540 r = requests.Request(url=httpbin())

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1541why, one step back
1541 with pytest.raises(ValueError):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1542why, one step back
1542 requests.Session().send(r)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1543why, one step back
1543

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1544–1548why, one step back
1544 def test_http_error(self):
1545 error = requests.exceptions.HTTPError()1546 assert not error.response1547 response = requests.Response()1548 error = requests.exceptions.HTTPError(response=response)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1549–1553why, one step back
1549 assert error.response == response
1550 error = requests.exceptions.HTTPError("message", response=response)1551 assert str(error) == "message"1552 assert error.response == response1553

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1554why, one step back
1554 def test_session_pickling(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1555–1557why, one step back
1555 r = requests.Request("GET", httpbin("get"))
1556 s = requests.Session()1557

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1558why, one step back
1558 s = pickle.loads(pickle.dumps(s))

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1559–1563why, one step back
1559 s.proxies = getproxies()
15601561 r = s.send(r.prepare())1562 assert r.status_code == 2001563

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1564–1565why, one step back
1564 def test_fixes_1329(self, httpbin):
1565 """Ensure that header updates are done case-insensitively."""

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1566–1569why, one step back
1566 s = requests.Session()
1567 s.headers.update({"ACCEPT": "BOGUS"})1568 s.headers.update({"accept": "application/json"})1569 r = s.get(httpbin("get"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1570why, one step back
1570 headers = r.request.headers

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1571–1574why, one step back
1571 assert headers["accept"] == "application/json"
1572 assert headers["Accept"] == "application/json"1573 assert headers["ACCEPT"] == "application/json"1574

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1575why, one step back
1575 def test_uppercase_scheme_redirect(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1576why, one step back
1576 parts = urlparse(httpbin("html"))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1577why, one step back
1577 url = "HTTP://" + parts.netloc + parts.path

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1578–1579why, one step back
1578 r = requests.get(httpbin("redirect-to"), params={"url": url})
1579 assert r.status_code == 200

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1580why, one step back
1580 assert r.url.lower() == url.lower()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1581why, one step back
1581

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1582why, one step back
1582 def test_transport_adapter_ordering(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1583–1613why, one step back
1583 s = requests.Session()
1584 order = ["https://", "http://"]1585 assert order == list(s.adapters)1586 s.mount("http://git", HTTPAdapter())1587 s.mount("http://github", HTTPAdapter())1588 s.mount("http://github.com", HTTPAdapter())1589 s.mount("http://github.com/about/", HTTPAdapter())1590 order = [1591 "http://github.com/about/",1592 "http://github.com",1593 "http://github",1594 "http://git",1595 "https://",1596 "http://",1597 ]1598 assert order == list(s.adapters)1599 s.mount("http://gittip", HTTPAdapter())1600 s.mount("http://gittip.com", HTTPAdapter())1601 s.mount("http://gittip.com/about/", HTTPAdapter())1602 order = [1603 "http://github.com/about/",1604 "http://gittip.com/about/",1605 "http://github.com",1606 "http://gittip.com",1607 "http://github",1608 "http://gittip",1609 "http://git",1610 "https://",1611 "http://",1612 ]1613 assert order == list(s.adapters)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1614why, one step back
1614 s2 = requests.Session()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1615–1619why, one step back
1615 s2.adapters = {"http://": HTTPAdapter()}
1616 s2.mount("https://", HTTPAdapter())1617 assert "http://" in s2.adapters1618 assert "https://" in s2.adapters1619

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1620why, one step back
1620 def test_session_get_adapter_prefix_matching(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1621–1628why, one step back
1621 prefix = "https://example.com"
1622 more_specific_prefix = prefix + "/some/path"16231624 url_matching_only_prefix = prefix + "/another/path"1625 url_matching_more_specific_prefix = more_specific_prefix + "/longer/path"1626 url_not_matching_prefix = "https://another.example.com/"16271628 s = requests.Session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1629–1632why, one step back
1629 prefix_adapter = HTTPAdapter()
1630 more_specific_prefix_adapter = HTTPAdapter()1631 s.mount(prefix, prefix_adapter)1632 s.mount(more_specific_prefix, more_specific_prefix_adapter)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1633why, one step back
1633

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1634why, one step back
1634 assert s.get_adapter(url_matching_only_prefix) is prefix_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1635–1643why, one step back
1635 assert (
1636 s.get_adapter(url_matching_more_specific_prefix)1637 is more_specific_prefix_adapter1638 )1639 assert s.get_adapter(url_not_matching_prefix) not in (1640 prefix_adapter,1641 more_specific_prefix_adapter,1642 )1643

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1644why, one step back
1644 def test_session_get_adapter_prefix_matching_mixed_case(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1645–1651why, one step back
1645 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1646 url_matching_prefix = mixed_case_prefix + "/full_url"16471648 s = requests.Session()1649 my_adapter = HTTPAdapter()1650 s.mount(mixed_case_prefix, my_adapter)1651

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1652why, one step back
1652 assert s.get_adapter(url_matching_prefix) is my_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1653why, one step back
1653

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1654why, one step back
1654 def test_session_get_adapter_prefix_matching_is_case_insensitive(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1655–1663why, one step back
1655 mixed_case_prefix = "hTtPs://eXamPle.CoM/MixEd_CAse_PREfix"
1656 url_matching_prefix_with_different_case = (1657 "HtTpS://exaMPLe.cOm/MiXeD_caSE_preFIX/another_url"1658 )16591660 s = requests.Session()1661 my_adapter = HTTPAdapter()1662 s.mount(mixed_case_prefix, my_adapter)1663

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1664why, one step back
1664 assert s.get_adapter(url_matching_prefix_with_different_case) is my_adapter

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1665why, one step back
1665

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1666–1667why, one step back
1666 def test_header_remove_is_case_insensitive(self, httpbin):
1667 # From issue #1321

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1668–1672why, one step back
1668 s = requests.Session()
1669 s.headers["foo"] = "bar"1670 r = s.get(httpbin("get"), headers={"FOO": None})1671 assert "foo" not in r.request.headers1672

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1673why, one step back
1673 def test_params_are_merged_case_sensitive(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1674–1678why, one step back
1674 s = requests.Session()
1675 s.params["foo"] = "bar"1676 r = s.get(httpbin("get"), params={"FOO": "bar"})1677 assert r.json()["args"] == {"foo": "bar", "FOO": "bar"}1678

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1679why, one step back
1679 def test_long_authinfo_in_url(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1680–1685why, one step back
1680 url = "http://{}:{}@{}:9000/path?query#frag".format(
1681 "E8A3BE87-9E3F-4620-8858-95478E385B5B",1682 "EA770032-DA4D-4D84-8CE9-29C6D910BF1E",1683 "exactly-------------sixty-----------three------------characters",1684 )1685 r = requests.Request("GET", url).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1686why, one step back
1686 assert r.url == url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1687why, one step back
1687

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1688why, one step back
1688 def test_header_keys_are_native(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1689–1692why, one step back
1689 headers = {"unicode": "blah", b"byte": "blah"}
1690 r = requests.Request("GET", httpbin("get"), headers=headers)1691 p = r.prepare()1692

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1693–1694why, one step back
1693 # This is testing that they are builtin strings. A bit weird, but there
1694 # we go.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1695–1697why, one step back
1695 assert "unicode" in p.headers.keys()
1696 assert "byte" in p.headers.keys()1697

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1698–1699why, one step back
1698 def test_header_validation(self, httpbin):
1699 """Ensure prepare_headers regex isn't flagging valid header contents."""

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1700why, one step back
1700 valid_headers = {

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1701–1705why, one step back
1701 "foo": "bar baz qux",
1702 "bar": b"fbbq",1703 "baz": "",1704 "qux": "1",1705 }

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1706–1707why, one step back
1706 r = requests.get(httpbin("get"), headers=valid_headers)
1707 for key in valid_headers.keys():

Merge pull request #6552 from swims-hjkl/issue/test_header_validationNate Prewittbefore adoption839a8ed

line 1708why, one step back
1708 assert valid_headers[key] == r.request.headers[key]

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1709why, one step back
1709

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1710–1718why, one step back
1710 @pytest.mark.parametrize(
1711 "invalid_header, key",1712 (1713 ({"foo": 3}, "foo"),1714 ({"bar": {"foo": "bar"}}, "bar"),1715 ({"baz": ["foo", "bar"]}, "baz"),1716 ),1717 )1718 def test_header_value_not_str(self, httpbin, invalid_header, key):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1719–1720why, one step back
1719 """Ensure the header value is of type string or bytes as
1720 per discussion in GH issue #3386

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1721–1722why, one step back
1721 """
1722 with pytest.raises(InvalidHeader) as excinfo:

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1723–1724why, one step back
1723 requests.get(httpbin("get"), headers=invalid_header)
1724 assert key in str(excinfo.value)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1725why, one step back
1725

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1726–1739why, one step back
1726 @pytest.mark.parametrize(
1727 "invalid_header",1728 (1729 {"foo": "bar\r\nbaz: qux"},1730 {"foo": "bar\n\rbaz: qux"},1731 {"foo": "bar\nbaz: qux"},1732 {"foo": "bar\rbaz: qux"},1733 {"fo\ro": "bar"},1734 {"fo\r\no": "bar"},1735 {"fo\n\ro": "bar"},1736 {"fo\no": "bar"},1737 ),1738 )1739 def test_header_no_return_chars(self, httpbin, invalid_header):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1740–1741why, one step back
1740 """Ensure that a header containing return character sequences raise an
1741 exception. Otherwise, multiple headers are created from single string.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1742–1743why, one step back
1742 """
1743 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1744why, one step back
1744 requests.get(httpbin("get"), headers=invalid_header)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1745why, one step back
1745

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

lines 1746–1758why, one step back
1746 @pytest.mark.parametrize(
1747 "invalid_header",1748 (1749 {" foo": "bar"},1750 {"\tfoo": "bar"},1751 {" foo": "bar"},1752 {"foo": " bar"},1753 {"foo": " bar"},1754 {"foo": "\tbar"},1755 {" ": "bar"},1756 ),1757 )1758 def test_header_no_leading_space(self, httpbin, invalid_header):

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1759–1760why, one step back
1759 """Ensure headers containing leading whitespace raise
1760 InvalidHeader Error before sending.

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1761–1762why, one step back
1761 """
1762 with pytest.raises(InvalidHeader):

Add valdation for header name (#6154)Nate Prewittbefore adoptione36f345

line 1763why, one step back
1763 requests.get(httpbin("get"), headers=invalid_header)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1764why, one step back
1764

Allow str/bytes subclasses to be used as header partsSeth Michael Larsonbefore adoption7f694b7

lines 1765–1789why, one step back
1765 def test_header_with_subclass_types(self, httpbin):
1766 """If the subclasses does not behave *exactly* like1767 the base bytes/str classes, this is not supported.1768 This test is for backwards compatibility.1769 """17701771 class MyString(str):1772 pass17731774 class MyBytes(bytes):1775 pass17761777 r_str = requests.get(httpbin("get"), headers={MyString("x-custom"): "myheader"})1778 assert r_str.request.headers["x-custom"] == "myheader"17791780 r_bytes = requests.get(1781 httpbin("get"), headers={MyBytes(b"x-custom"): b"myheader"}1782 )1783 assert r_bytes.request.headers["x-custom"] == b"myheader"17841785 r_mixed = requests.get(1786 httpbin("get"), headers={MyString("x-custom"): MyBytes(b"myheader")}1787 )1788 assert r_mixed.request.headers["x-custom"] == b"myheader"1789

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1790why, one step back
1790 @pytest.mark.parametrize("files", ("foo", b"foo", bytearray(b"foo")))

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1791why, one step back
1791 def test_can_send_objects_with_files(self, httpbin, files):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1792–1797why, one step back
1792 data = {"a": "this is a string"}
1793 files = {"b": files}1794 r = requests.Request("POST", httpbin("post"), data=data, files=files)1795 p = r.prepare()1796 assert "multipart/form-data" in p.headers["Content-Type"]1797

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1798–1800why, one step back
1798 def test_can_send_file_object_with_non_string_filename(self, httpbin):
1799 f = io.BytesIO()1800 f.name = 2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1801–1805why, one step back
1801 r = requests.Request("POST", httpbin("post"), files={"f": f})
1802 p = r.prepare()18031804 assert "multipart/form-data" in p.headers["Content-Type"]1805

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1806why, one step back
1806 def test_autoset_header_values_are_native(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1807–1809why, one step back
1807 data = "this is a string"
1808 length = "16"1809 req = requests.Request("POST", httpbin("post"), data=data)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1810why, one step back
1810 p = req.prepare()

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1811–1813why, one step back
1811
1812 assert p.headers["Content-Length"] == length1813

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1814–1815why, one step back
1814 def test_nonhttp_schemes_dont_check_URLs(self):
1815 test_urls = (

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1816–1819why, one step back
1816 "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
1817 "file:///etc/passwd",1818 "magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431",1819 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1820why, one step back
1820 for test_url in test_urls:

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1821why, one step back
1821 req = requests.Request("GET", test_url)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1822–1823why, one step back
1822 preq = req.prepare()
1823 assert test_url == preq.url

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1824–1836why, one step back
1824
1825 def test_auth_is_stripped_on_http_downgrade(1826 self, httpbin, httpbin_secure, httpbin_ca_bundle1827 ):1828 r = requests.get(1829 httpbin_secure("redirect-to"),1830 params={"url": httpbin("get")},1831 auth=("user", "pass"),1832 verify=httpbin_ca_bundle,1833 )1834 assert r.history[0].request.headers["Authorization"]1835 assert "Authorization" not in r.request.headers1836

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1837why, one step back
1837 def test_auth_is_retained_for_redirect_on_host(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1838–1841why, one step back
1838 r = requests.get(httpbin("redirect/1"), auth=("user", "pass"))
1839 h1 = r.history[0].request.headers["Authorization"]1840 h2 = r.request.headers["Authorization"]1841

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1842why, one step back
1842 assert h1 == h2

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1843why, one step back
1843

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1844why, one step back
1844 def test_should_strip_auth_host_change(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1845–1849why, one step back
1845 s = requests.Session()
1846 assert s.should_strip_auth(1847 "http://example.com/foo", "http://another.example.com/"1848 )1849

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1850why, one step back
1850 def test_should_strip_auth_http_downgrade(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1851–1853why, one step back
1851 s = requests.Session()
1852 assert s.should_strip_auth("https://example.com/foo", "http://example.com/bar")1853

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1854why, one step back
1854 def test_should_strip_auth_https_upgrade(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1855–1864why, one step back
1855 s = requests.Session()
1856 assert not s.should_strip_auth(1857 "http://example.com/foo", "https://example.com/bar"1858 )1859 assert not s.should_strip_auth(1860 "http://example.com:80/foo", "https://example.com/bar"1861 )1862 assert not s.should_strip_auth(1863 "http://example.com/foo", "https://example.com:443/bar"1864 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1865why, one step back
1865 # Non-standard ports should trigger stripping

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1866–1872why, one step back
1866 assert s.should_strip_auth(
1867 "http://example.com:8080/foo", "https://example.com/bar"1868 )1869 assert s.should_strip_auth(1870 "http://example.com/foo", "https://example.com:8443/bar"1871 )1872

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1873why, one step back
1873 def test_should_strip_auth_port_change(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1874–1887why, one step back
1874 s = requests.Session()
1875 assert s.should_strip_auth(1876 "http://example.com:1234/foo", "https://example.com:4321/bar"1877 )18781879 @pytest.mark.parametrize(1880 "old_uri, new_uri",1881 (1882 ("https://example.com:443/foo", "https://example.com/bar"),1883 ("http://example.com:80/foo", "http://example.com/bar"),1884 ("https://example.com/foo", "https://example.com:443/bar"),1885 ("http://example.com/foo", "http://example.com:80/bar"),1886 ),1887 )

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1888why, one step back
1888 def test_should_strip_auth_default_port(self, old_uri, new_uri):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1889why, one step back
1889 s = requests.Session()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1890why, one step back
1890 assert not s.should_strip_auth(old_uri, new_uri)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1891why, one step back
1891

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1892why, one step back
1892 def test_manual_redirect_with_partial_body_read(self, httpbin):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1893–1894why, one step back
1893 s = requests.Session()
1894 r1 = s.get(httpbin("redirect/2"), allow_redirects=False, stream=True)

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1895–1896why, one step back
1895 assert r1.is_redirect
1896 rg = s.resolve_redirects(r1, r1.request, stream=True)

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1897why, one step back
1897

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1898why, one step back
1898 # read only the first eight bytes of the response body,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1899why, one step back
1899 # then follow the redirect

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1900–1902why, one step back
1900 r1.iter_content(8)
1901 r2 = next(rg)1902 assert r2.is_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1903why, one step back
1903

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1904why, one step back
1904 # read all of the response via iter_content,

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1905why, one step back
1905 # then follow the redirect

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1906why, one step back
1906 for _ in r2.iter_content():

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1907why, one step back
1907 pass

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

lines 1908–1909why, one step back
1908 r3 = next(rg)
1909 assert not r3.is_redirect

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1910why, one step back
1910

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1911why, one step back
1911 def test_prepare_body_position_non_stream(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1912–1913why, one step back
1912 data = b"the data"
1913 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1914why, one step back
1914 assert prep._body_position is None

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1915why, one step back
1915

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1916why, one step back
1916 def test_rewind_body(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1917–1928why, one step back
1917 data = io.BytesIO(b"the data")
1918 prep = requests.Request("GET", "http://example.com", data=data).prepare()1919 assert prep._body_position == 01920 assert prep.body.read() == b"the data"19211922 # the data has all been read1923 assert prep.body.read() == b""19241925 # rewind it back1926 requests.utils.rewind_body(prep)1927 assert prep.body.read() == b"the data"1928

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1929why, one step back
1929 def test_rewind_partially_read_body(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1930why, one step back
1930 data = io.BytesIO(b"the data")

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1931why, one step back
1931 data.read(4) # read some data

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

line 1932why, one step back
1932 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1933why, one step back
1933 assert prep._body_position == 4

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1934–1942why, one step back
1934 assert prep.body.read() == b"data"
19351936 # the data has all been read1937 assert prep.body.read() == b""19381939 # rewind it back1940 requests.utils.rewind_body(prep)1941 assert prep.body.read() == b"data"1942

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1943why, one step back
1943 def test_rewind_body_no_seek(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1944–1962why, one step back
1944 class BadFileObj:
1945 def __init__(self, data):1946 self.data = data19471948 def tell(self):1949 return 019501951 def __iter__(self):1952 return19531954 data = BadFileObj("the data")1955 prep = requests.Request("GET", "http://example.com", data=data).prepare()1956 assert prep._body_position == 019571958 with pytest.raises(UnrewindableBodyError) as e:1959 requests.utils.rewind_body(prep)19601961 assert "Unable to rewind request body" in str(e)1962

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1963why, one step back
1963 def test_rewind_body_failed_seek(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1964–1970why, one step back
1964 class BadFileObj:
1965 def __init__(self, data):1966 self.data = data19671968 def tell(self):1969 return 01970

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1971why, one step back
1971 def seek(self, pos, whence=0):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1972–1985why, one step back
1972 raise OSError()
19731974 def __iter__(self):1975 return19761977 data = BadFileObj("the data")1978 prep = requests.Request("GET", "http://example.com", data=data).prepare()1979 assert prep._body_position == 019801981 with pytest.raises(UnrewindableBodyError) as e:1982 requests.utils.rewind_body(prep)19831984 assert "error occurred when rewinding request body" in str(e)1985

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1986why, one step back
1986 def test_rewind_body_failed_tell(self):

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 1987–1998why, one step back
1987 class BadFileObj:
1988 def __init__(self, data):1989 self.data = data19901991 def tell(self):1992 raise OSError()19931994 def __iter__(self):1995 return19961997 data = BadFileObj("the data")1998 prep = requests.Request("GET", "http://example.com", data=data).prepare()

Move CI to Github ActionsNate Prewittbefore adoption9cd2d33

line 1999why, one step back
1999 assert prep._body_position is not None

Add automatic code formatting to Requests (#6095)Nate Prewittbefore adoption2a6f290

lines 2000–2005why, one step back
2000

The first 2,000 of 2,983 lines.