test_requests.py
This file
Path
test_requests.py
1,191 lines · 40.6 KiB · Python
Last changed by
Merge pull request #1935 from cjstapleton/masterKenneth Reitzbefore adoptiond8557a2
History of this fileTake it
The walk stopped after 200 commits: lines older than f2be5fa point at it.
Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 1–8why, one step back1#!/usr/bin/env python2# -*- coding: utf-8 -*-34"""Tests for Requests."""56from __future__ import division7import json8import osMerge pull request #1243 from darjus-amzn/masterKenneth Reitzbefore adoption25ea8cd
line 9why, one step back9import pickleMerge pull request #1772 from mdbecker/make_morsel_to_cookie_more_pythonicKenneth Reitzbefore adoption9fc0701
line 10why, one step back10import unittestMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 11–12why, one step back1112import requestsMerge pull request #1503 from skastel/masterKenneth Reitzbefore adoption23ced52
line 13why, one step back13import pytestMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 14why, one step back14from requests.adapters import HTTPAdapterMerge pull request #1772 from mdbecker/make_morsel_to_cookie_more_pythonicKenneth Reitzbefore adoption9fc0701
lines 15–18why, one step back15from requests.auth import HTTPDigestAuth16from requests.compat import (17 Morsel, cookielib, getproxies, str, urljoin, urlparse)18from requests.cookies import cookiejar_from_dict, morsel_to_cookieMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
line 19why, one step back19from requests.exceptions import InvalidURL, MissingSchemaMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 20why, one step back20from requests.structures import CaseInsensitiveDictMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 21–27why, one step back2122try:23 import StringIO24except ImportError:25 import io as StringIO2627HTTPBIN = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')Merge pull request #1483 from dpursehouse/httpbin-url-without-trailing-slashKenneth Reitzbefore adoption47f5a0d
lines 28–29why, one step back28# Issue #1483: Make sure the URL always has a trailing slash29HTTPBIN = HTTPBIN.rstrip('/') + '/'Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 30–33why, one step back303132def httpbin(*suffix):33 """Returns url for HTTPBIN resource."""Merge pull request #1486 from sigmavirus24/use_urljoinKenneth Reitzbefore adoptionb65b8c5
line 34why, one step back34 return urljoin(HTTPBIN, '/'.join(suffix))Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 35–60why, one step back353637class RequestsTestCase(unittest.TestCase):3839 _multiprocess_can_split_ = True4041 def setUp(self):42 """Create simple data set with headers."""43 pass4445 def tearDown(self):46 """Teardown."""47 pass4849 def test_entry_points(self):5051 requests.session52 requests.session().get53 requests.session().head54 requests.get55 requests.head56 requests.put57 requests.patch58 requests.post5960 def test_invalid_url(self):Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 61–64why, one step back61 with pytest.raises(MissingSchema):62 requests.get('hiwpefhipowhefopw')63 with pytest.raises(InvalidURL):64 requests.get('http://')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 65–76why, one step back6566 def test_basic_building(self):67 req = requests.Request()68 req.url = 'http://kennethreitz.org/'69 req.data = {'life': '42'}7071 pr = req.prepare()72 assert pr.url == req.url73 assert pr.body == 'life=42'7475 def test_no_content_length(self):76 get_req = requests.Request('GET', httpbin('get')).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 77why, one step back77 assert 'Content-Length' not in get_req.headersMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 78why, one step back78 head_req = requests.Request('HEAD', httpbin('head')).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 79why, one step back79 assert 'Content-Length' not in head_req.headersMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 80–83why, one step back8081 def test_path_is_not_double_encoded(self):82 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()83Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 84why, one step back84 assert request.path_url == '/get/test%20case'Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 85–88why, one step back8586 def test_params_are_added_before_fragment(self):87 request = requests.Request('GET',88 "http://example.com/path#fragment", params={"a": "b"}).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 89why, one step back89 assert request.url == "http://example.com/path?a=b#fragment"Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 90–91why, one step back90 request = requests.Request('GET',91 "http://example.com/path?key=value#fragment", params={"a": "b"}).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 92why, one step back92 assert request.url == "http://example.com/path?key=value&a=b#fragment"Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 93why, one step back93Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 94–95why, one step back94 def test_mixed_case_scheme_acceptable(self):95 s = requests.Session()Merge pull request #1487 from dpursehouse/rewrite-test_mixed_case_scheme_acceptableKenneth Reitzbefore adoptiond5fd3d3
lines 96–103why, one step back96 s.proxies = getproxies()97 parts = urlparse(httpbin('get'))98 schemes = ['http://', 'HTTP://', 'hTTp://', 'HttP://',99 'https://', 'HTTPS://', 'hTTps://', 'HttPs://']100 for scheme in schemes:101 url = scheme + parts.netloc + parts.path102 r = requests.Request('GET', url)103 r = s.send(r.prepare())Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 104why, one step back104 assert r.status_code == 200, 'failed for scheme {0}'.format(scheme)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
line 105why, one step back105Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 106–108why, one step back106 def test_HTTP_200_OK_GET_ALTERNATIVE(self):107 r = requests.Request('GET', httpbin('get'))108 s = requests.Session()Merge pull request #1482 from dpursehouse/fix-testcases-with-proxyKenneth Reitzbefore adoptionf71bff1
line 109why, one step back109 s.proxies = getproxies()Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 110–112why, one step back110111 r = s.send(r.prepare())112Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 113why, one step back113 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 114–116why, one step back114115 def test_HTTP_302_ALLOW_REDIRECT_GET(self):116 r = requests.get(httpbin('redirect', '1'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 117why, one step back117 assert r.status_code == 200Merge pull request #1918 from zackw/response-is-redirectKenneth Reitzbefore adoption3c88e52
lines 118–119why, one step back118 assert r.history[0].status_code == 302119 assert r.history[0].is_redirectMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 120–129why, one step back120121 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):122 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})123 # self.assertEqual(r.status_code, 200)124125 def test_HTTP_200_OK_GET_WITH_PARAMS(self):126 heads = {'User-agent': 'Mozilla/5.0'}127128 r = requests.get(httpbin('user-agent'), headers=heads)129Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 130–131why, one step back130 assert heads['User-agent'] in r.text131 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 132–136why, one step back132133 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):134 heads = {'User-agent': 'Mozilla/5.0'}135136 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 137why, one step back137 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 138why, one step back138Merge pull request #1180 from sigmavirus24/masterKenneth Reitzbefore adoption5d9fcc7
lines 139–142why, one step back139 def test_set_cookie_on_301(self):140 s = requests.session()141 url = httpbin('cookies/set?foo=bar')142 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 143why, one step back143 assert s.cookies['foo'] == 'bar'Merge pull request #1180 from sigmavirus24/masterKenneth Reitzbefore adoption5d9fcc7
line 144why, one step back144Merge pull request #1239 from miikka/fix-issue-1228Kenneth Reitzbefore adoptioncb2116d
lines 145–148why, one step back145 def test_cookie_sent_on_redirect(self):146 s = requests.session()147 s.get(httpbin('cookies/set?foo=bar'))148 r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 149why, one step back149 assert 'Cookie' in r.json()['headers']Merge pull request #1239 from miikka/fix-issue-1228Kenneth Reitzbefore adoptioncb2116d
line 150why, one step back150Merge pull request #1290 from gazpachoking/#1287Kenneth Reitzbefore adoption848f2c2
lines 151–153why, one step back151 def test_cookie_removed_on_expire(self):152 s = requests.session()153 s.get(httpbin('cookies/set?foo=bar'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 154why, one step back154 assert s.cookies['foo'] == 'bar'Merge pull request #1290 from gazpachoking/#1287Kenneth Reitzbefore adoption848f2c2
lines 155–162why, one step back155 s.get(156 httpbin('response-headers'),157 params={158 'Set-Cookie':159 'foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT'160 }161 )162 assert 'foo' not in s.cookiesMerge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
line 163why, one step back163Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 164–166why, one step back164 def test_cookie_quote_wrapped(self):165 s = requests.session()166 s.get(httpbin('cookies/set?foo="bar:baz"'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 167why, one step back167 assert s.cookies['foo'] == '"bar:baz"'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
line 168why, one step back168Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
lines 169–170why, one step back169 def test_cookie_persists_via_api(self):170 s = requests.session()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
line 171why, one step back171 r = s.get(httpbin('redirect/1'), cookies={'foo': 'bar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 172–173why, one step back172 assert 'foo' in r.request.headers['Cookie']173 assert 'foo' in r.history[0].request.headers['Cookie']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
line 174why, one step back174Merge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
lines 175–182why, one step back175 def test_request_cookie_overrides_session_cookie(self):176 s = requests.session()177 s.cookies['foo'] = 'bar'178 r = s.get(httpbin('cookies'), cookies={'foo': 'baz'})179 assert r.json()['cookies']['foo'] == 'baz'180 # Session cookie should not be modified181 assert s.cookies['foo'] == 'bar'182Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
lines 183–188why, one step back183 def test_request_cookies_not_persisted(self):184 s = requests.session()185 s.get(httpbin('cookies'), cookies={'foo': 'baz'})186 # Sending a request with cookies should not add cookies to the session187 assert not s.cookies188Merge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
lines 189–198why, one step back189 def test_generic_cookiejar_works(self):190 cj = cookielib.CookieJar()191 cookiejar_from_dict({'foo': 'bar'}, cj)192 s = requests.session()193 s.cookies = cj194 r = s.get(httpbin('cookies'))195 # Make sure the cookie was sent196 assert r.json()['cookies']['foo'] == 'bar'197 # Make sure the session cj is still the custom one198 assert s.cookies is cjMerge pull request #1862 from sybeck2k/masterKenneth Reitzbefore adoption0465d34
line 199why, one step back199Merge pull request #1713 from daftshady/masterKenneth Reitzbefore adoption8b88549
lines 200–206why, one step back200 def test_param_cookiejar_works(self):201 cj = cookielib.CookieJar()202 cookiejar_from_dict({'foo' : 'bar'}, cj)203 s = requests.session()204 r = s.get(httpbin('cookies'), cookies=cj)205 # Make sure the cookie was sent206 assert r.json()['cookies']['foo'] == 'bar'merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 207why, one step back207Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 208–211why, one step back208 def test_requests_in_history_are_not_overridden(self):209 resp = requests.get(httpbin('redirect/3'))210 urls = [r.url for r in resp.history]211 req_urls = [r.request.url for r in resp.history]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 212why, one step back212 assert urls == req_urlsmerge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 213why, one step back213Merge pull request #1921 from sigmavirus24/fix-session-header-noneKenneth Reitzbefore adoption3c4b374
lines 214–221why, one step back214 def test_headers_on_session_with_None_are_not_sent(self):215 """Do not send headers in Session.headers with None values."""216 ses = requests.Session()217 ses.headers['Accept-Encoding'] = None218 req = requests.Request('GET', 'http://httpbin.org/get')219 prep = ses.prepare_request(req)220 assert 'Accept-Encoding' not in prep.headers221Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 222–228why, one step back222 def test_user_agent_transfers(self):223224 heads = {225 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'226 }227228 r = requests.get(httpbin('user-agent'), headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 229why, one step back229 assert heads['User-agent'] in r.textMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 230–235why, one step back230231 heads = {232 'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'233 }234235 r = requests.get(httpbin('user-agent'), headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 236why, one step back236 assert heads['user-agent'] in r.textMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 237–239why, one step back237238 def test_HTTP_200_OK_HEAD(self):239 r = requests.head(httpbin('get'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 240why, one step back240 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 241–243why, one step back241242 def test_HTTP_200_OK_PUT(self):243 r = requests.put(httpbin('put'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 244why, one step back244 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 245–250why, one step back245246 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):247 auth = ('user', 'pass')248 url = httpbin('basic-auth', 'user', 'pass')249250 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 251why, one step back251 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 252–253why, one step back252253 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 254why, one step back254 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 255–258why, one step back255256 s = requests.session()257 s.auth = auth258 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 259why, one step back259 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 260why, one step back260Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 261–271why, one step back261 def test_basicauth_with_netrc(self):262 auth = ('user', 'pass')263 wrong_auth = ('wronguser', 'wrongpass')264 url = httpbin('basic-auth', 'user', 'pass')265266 def get_netrc_auth_mock(url):267 return auth268 requests.sessions.get_netrc_auth = get_netrc_auth_mock269270 # Should use netrc and work.271 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 272why, one step back272 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 273–275why, one step back273274 # Given auth should override and fail.275 r = requests.get(url, auth=wrong_auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 276why, one step back276 assert r.status_code == 401Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 277–278why, one step back277278 s = requests.session()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 279why, one step back279Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 280–281why, one step back280 # Should use netrc and work.281 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 282why, one step back282 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 283–286why, one step back283284 # Given auth should override and fail.285 s.auth = wrong_auth286 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 287why, one step back287 assert r.status_code == 401Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
line 288why, one step back288Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 289–294why, one step back289 def test_DIGEST_HTTP_200_OK_GET(self):290291 auth = HTTPDigestAuth('user', 'pass')292 url = httpbin('digest-auth', 'auth', 'user', 'pass')293294 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 295why, one step back295 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 296–297why, one step back296297 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 298why, one step back298 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 299–300why, one step back299300 s = requests.session()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 301why, one step back301 s.auth = HTTPDigestAuth('user', 'pass')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 302why, one step back302 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 303why, one step back303 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 304why, one step back304merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 305–320why, one step back305 def test_DIGEST_AUTH_RETURNS_COOKIE(self):306 url = httpbin('digest-auth', 'auth', 'user', 'pass')307 auth = HTTPDigestAuth('user', 'pass')308 r = requests.get(url)309 assert r.cookies['fake'] == 'fake_value'310311 r = requests.get(url, auth=auth)312 assert r.status_code == 200313314 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self):315 url = httpbin('digest-auth', 'auth', 'user', 'pass')316 auth = HTTPDigestAuth('user', 'pass')317 s = requests.Session()318 s.get(url, auth=auth)319 assert s.cookies['fake'] == 'fake_value'320Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
lines 321–326why, one step back321 def test_DIGEST_STREAM(self):322323 auth = HTTPDigestAuth('user', 'pass')324 url = httpbin('digest-auth', 'auth', 'user', 'pass')325326 r = requests.get(url, auth=auth, stream=True)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 327why, one step back327 assert r.raw.read() != b''Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
lines 328–329why, one step back328329 r = requests.get(url, auth=auth, stream=False)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 330why, one step back330 assert r.raw.read() == b''Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
line 331why, one step back331Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 332–337why, one step back332 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):333334 auth = HTTPDigestAuth('user', 'wrongpass')335 url = httpbin('digest-auth', 'auth', 'user', 'pass')336337 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 338why, one step back338 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 339–340why, one step back339340 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 341why, one step back341 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 342–345why, one step back342343 s = requests.session()344 s.auth = auth345 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 346why, one step back346 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 347why, one step back347Merge pull request #1766 from Lukasa/qopKenneth Reitzbefore adoptiona030a58
lines 348–355why, one step back348 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self):349350 auth = HTTPDigestAuth('user', 'pass')351 url = httpbin('digest-auth', 'auth', 'user', 'pass')352353 r = requests.get(url, auth=auth)354 assert '"auth"' in r.request.headers['Authorization']355Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 356–361why, one step back356 def test_POSTBIN_GET_POST_FILES(self):357358 url = httpbin('post')359 post1 = requests.post(url).raise_for_status()360361 post1 = requests.post(url, data={'some': 'data'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 362why, one step back362 assert post1.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 363–365why, one step back363364 with open('requirements.txt') as f:365 post2 = requests.post(url, files={'some': f})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 366why, one step back366 assert post2.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 367–368why, one step back367368 post4 = requests.post(url, data='[{"some": "json"}]')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 369why, one step back369 assert post4.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 370why, one step back370Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 371–372why, one step back371 with pytest.raises(ValueError):372 requests.post(url, files = ['bad file data'])Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 373–379why, one step back373374 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):375376 url = httpbin('post')377 post1 = requests.post(url).raise_for_status()378379 post1 = requests.post(url, data={'some': 'data'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 380why, one step back380 assert post1.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 381–383why, one step back381382 with open('requirements.txt') as f:383 post2 = requests.post(url, data={'some': 'data'}, files={'some': f})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 384why, one step back384 assert post2.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 385–386why, one step back385386 post4 = requests.post(url, data='[{"some": "json"}]')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 387why, one step back387 assert post4.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 388why, one step back388Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 389–390why, one step back389 with pytest.raises(ValueError):390 requests.post(url, files = ['bad file data'])Merge pull request #1503 from skastel/masterKenneth Reitzbefore adoption23ced52
lines 391–396why, one step back391392 def test_conflicting_post_params(self):393 url = httpbin('post')394 with open('requirements.txt') as f:395 pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")396 pytest.raises(ValueError, "requests.post(url, data=u'[{\"some\": \"data\"}]', files={'some': f})")Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 397–399why, one step back397398 def test_request_ok_set(self):399 r = requests.get(httpbin('status', '404'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 400why, one step back400 assert not r.okMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 401–403why, one step back401402 def test_status_raising(self):403 r = requests.get(httpbin('status', '404'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 404–405why, one step back404 with pytest.raises(requests.exceptions.HTTPError):405 r.raise_for_status()Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 406–407why, one step back406407 r = requests.get(httpbin('status', '500'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 408why, one step back408 assert not r.okMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 409–421why, one step back409410 def test_decompress_gzip(self):411 r = requests.get(httpbin('gzip'))412 r.content.decode('ascii')413414 def test_unicode_get(self):415 url = httpbin('/get')416 requests.get(url, params={'foo': 'føø'})417 requests.get(url, params={'føø': 'føø'})418 requests.get(url, params={'føø': 'føø'})419 requests.get(url, params={'foo': 'foo'})420 requests.get(httpbin('ø'), params={'foo': 'foo'})421Merge pull request #1181 from denis-ryzhkov/masterKenneth Reitzbefore adoptioncdec20a
lines 422–424why, one step back422 def test_unicode_header_name(self):423 requests.put(httpbin('put'), headers={str('Content-Type'): 'application/octet-stream'}, data='\xff') # compat.str is unicode.424Merge pull request #1888 from longaccess/handle301Kenneth Reitzbefore adoptionb1c8fd3
lines 425–427why, one step back425 def test_pyopenssl_redirect(self):426 requests.get('https://httpbin.org/status/301')427Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 428–430why, one step back428 def test_urlencoded_get_query_multivalued_param(self):429430 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 431–432why, one step back431 assert r.status_code == 200432 assert r.url == httpbin('get?test=foo&test=baz')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 433–438why, one step back433434 def test_different_encodings_dont_break_post(self):435 r = requests.post(httpbin('post'),436 data={'stuff': json.dumps({'a': 123})},437 params={'blah': 'asdf1234'},438 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 439why, one step back439 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 440why, one step back440Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 441–444why, one step back441 def test_unicode_multipart_post(self):442 r = requests.post(httpbin('post'),443 data={'stuff': u'ëlïxr'},444 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 445why, one step back445 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 446–449why, one step back446447 r = requests.post(httpbin('post'),448 data={'stuff': u'ëlïxr'.encode('utf-8')},449 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 450why, one step back450 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 451–454why, one step back451452 r = requests.post(httpbin('post'),453 data={'stuff': 'elixr'},454 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 455why, one step back455 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 456–459why, one step back456457 r = requests.post(httpbin('post'),458 data={'stuff': 'elixr'.encode('utf-8')},459 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 460why, one step back460 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
line 461why, one step back461Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
lines 462–469why, one step back462 def test_unicode_multipart_post_fieldnames(self):463 filename = os.path.splitext(__file__)[0] + '.py'464 r = requests.Request(method='POST',465 url=httpbin('post'),466 data={'stuff'.encode('utf-8'): 'elixr'},467 files={'file': ('test_requests.py',468 open(filename, 'rb'))})469 prep = r.prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 470–471why, one step back470 assert b'name="stuff"' in prep.body471 assert b'name="b\'stuff\'"' not in prep.bodyMerge pull request #1733 from ionrock/pickleable-responsesKenneth Reitzbefore adoptionaf921c7
line 472why, one step back472Merge pull request #1724 from daftshady/dev3Kenneth Reitzbefore adoption7ccbcd2
lines 473–476why, one step back473 def test_unicode_method_name(self):474 files = {'file': open('test_requests.py', 'rb')}475 r = requests.request(method=u'POST', url=httpbin('post'), files=files)476 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
line 477why, one step back477Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 478–483why, one step back478 def test_custom_content_type(self):479 r = requests.post(httpbin('post'),480 data={'stuff': json.dumps({'a': 123})},481 files={'file1': ('test_requests.py', open(__file__, 'rb')),482 'file2': ('test_requests', open(__file__, 'rb'),483 'text/py-content-type')})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 484–485why, one step back484 assert r.status_code == 200485 assert b"text/py-content-type" in r.request.bodyMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 486why, one step back486Merge pull request #1267 from sigmavirus24/masterKenneth Reitzbefore adoptionbd6b981
lines 487–493why, one step back487 def test_hook_receives_request_arguments(self):488 def hook(resp, **kwargs):489 assert resp is not None490 assert kwargs != {}491492 requests.Request('GET', HTTPBIN, hooks={'response': hook})493Merge pull request #1657 from sigmavirus24/fix-session-hooksKenneth Reitzbefore adoption5c91545
lines 494–512why, one step back494 def test_session_hooks_are_used_with_no_request_hooks(self):495 hook = lambda x, *args, **kwargs: x496 s = requests.Session()497 s.hooks['response'].append(hook)498 r = requests.Request('GET', HTTPBIN)499 prep = s.prepare_request(r)500 assert prep.hooks['response'] != []501 assert prep.hooks['response'] == [hook]502503 def test_session_hooks_are_overriden_by_request_hooks(self):504 hook1 = lambda x, *args, **kwargs: x505 hook2 = lambda x, *args, **kwargs: x506 assert hook1 is not hook2507 s = requests.Session()508 s.hooks['response'].append(hook2)509 r = requests.Request('GET', HTTPBIN, hooks={'response': [hook1]})510 prep = s.prepare_request(r)511 assert prep.hooks['response'] == [hook1]512Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 513why, one step back513 def test_prepared_request_hook(self):Merge pull request #1267 from sigmavirus24/masterKenneth Reitzbefore adoptionbd6b981
line 514why, one step back514 def hook(resp, **kwargs):Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 515–521why, one step back515 resp.hook_working = True516 return resp517518 req = requests.Request('GET', HTTPBIN, hooks={'response': hook})519 prep = req.prepare()520521 s = requests.Session()Merge pull request #1482 from dpursehouse/fix-testcases-with-proxyKenneth Reitzbefore adoptionf71bff1
line 522why, one step back522 s.proxies = getproxies()Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 523–524why, one step back523 resp = s.send(prep)524Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 525why, one step back525 assert hasattr(resp, 'hook_working')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 526why, one step back526Merge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
lines 527–533why, one step back527 def test_prepared_from_session(self):528 class DummyAuth(requests.auth.AuthBase):529 def __call__(self, r):530 r.headers['Dummy-Auth-Test'] = 'dummy-auth-test-ok'531 return r532533 req = requests.Request('GET', httpbin('headers'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 534why, one step back534 assert not req.authMerge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
lines 535–541why, one step back535536 s = requests.Session()537 s.auth = DummyAuth()538539 prep = s.prepare_request(req)540 resp = s.send(prep)541Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 542why, one step back542 assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'Merge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
line 543why, one step back543Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 544–565why, one step back544 def test_links(self):545 r = requests.Response()546 r.headers = {547 'cache-control': 'public, max-age=60, s-maxage=60',548 'connection': 'keep-alive',549 'content-encoding': 'gzip',550 'content-type': 'application/json; charset=utf-8',551 'date': 'Sat, 26 Jan 2013 16:47:56 GMT',552 'etag': '"6ff6a73c0e446c1f61614769e3ceb778"',553 'last-modified': 'Sat, 26 Jan 2013 16:22:39 GMT',554 'link': ('<https://api.github.com/users/kennethreitz/repos?'555 'page=2&per_page=10>; rel="next", <https://api.github.'556 'com/users/kennethreitz/repos?page=7&per_page=10>; '557 ' rel="last"'),558 'server': 'GitHub.com',559 'status': '200 OK',560 'vary': 'Accept',561 'x-content-type-options': 'nosniff',562 'x-github-media-type': 'github.beta',563 'x-ratelimit-limit': '60',564 'x-ratelimit-remaining': '57'565 }Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 566why, one step back566 assert r.links['next']['rel'] == 'next'Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 567–577why, one step back567568 def test_cookie_parameters(self):569 key = 'some_cookie'570 value = 'some_value'571 secure = True572 domain = 'test.com'573 rest = {'HttpOnly': True}574575 jar = requests.cookies.RequestsCookieJar()576 jar.set(key, value, secure=secure, domain=domain, rest=rest)577Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 578–579why, one step back578 assert len(jar) == 1579 assert 'some_cookie' in jarMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 580–581why, one step back580581 cookie = list(jar)[0]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 582–584why, one step back582 assert cookie.secure == secure583 assert cookie.domain == domain584 assert cookie._rest['HttpOnly'] == rest['HttpOnly']Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 585why, one step back585Merge branch 'master' into fix-pickling-adaptersKenneth Reitzbefore adoptiondf1c233
lines 586–673why, one step back586 def test_cookie_as_dict_keeps_len(self):587 key = 'some_cookie'588 value = 'some_value'589590 key1 = 'some_cookie1'591 value1 = 'some_value1'592593 jar = requests.cookies.RequestsCookieJar()594 jar.set(key, value)595 jar.set(key1, value1)596597 d1 = dict(jar)598 d2 = dict(jar.iteritems())599 d3 = dict(jar.items())600601 assert len(jar) == 2602 assert len(d1) == 2603 assert len(d2) == 2604 assert len(d3) == 2605606 def test_cookie_as_dict_keeps_items(self):607 key = 'some_cookie'608 value = 'some_value'609610 key1 = 'some_cookie1'611 value1 = 'some_value1'612613 jar = requests.cookies.RequestsCookieJar()614 jar.set(key, value)615 jar.set(key1, value1)616617 d1 = dict(jar)618 d2 = dict(jar.iteritems())619 d3 = dict(jar.items())620621 assert d1['some_cookie'] == 'some_value'622 assert d2['some_cookie'] == 'some_value'623 assert d3['some_cookie1'] == 'some_value1'624625 def test_cookie_as_dict_keys(self):626 key = 'some_cookie'627 value = 'some_value'628629 key1 = 'some_cookie1'630 value1 = 'some_value1'631632 jar = requests.cookies.RequestsCookieJar()633 jar.set(key, value)634 jar.set(key1, value1)635636 keys = jar.keys()637 assert keys == list(keys)638 # make sure one can use keys multiple times639 assert list(keys) == list(keys)640641 def test_cookie_as_dict_values(self):642 key = 'some_cookie'643 value = 'some_value'644645 key1 = 'some_cookie1'646 value1 = 'some_value1'647648 jar = requests.cookies.RequestsCookieJar()649 jar.set(key, value)650 jar.set(key1, value1)651652 values = jar.values()653 assert values == list(values)654 # make sure one can use values multiple times655 assert list(values) == list(values)656657 def test_cookie_as_dict_items(self):658 key = 'some_cookie'659 value = 'some_value'660661 key1 = 'some_cookie1'662 value1 = 'some_value1'663664 jar = requests.cookies.RequestsCookieJar()665 jar.set(key, value)666 jar.set(key1, value1)667668 items = jar.items()669 assert items == list(items)670 # make sure one can use items multiple times671 assert list(items) == list(items)672673Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 674–678why, one step back674 def test_time_elapsed_blank(self):675 r = requests.get(httpbin('get'))676 td = r.elapsed677 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)678 * 10**6) / 10**6)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 679why, one step back679 assert total_seconds > 0.0Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 680–683why, one step back680681 def test_response_is_iterable(self):682 r = requests.Response()683 io = StringIO.StringIO('abc')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption636476e
lines 684–688why, one step back684 read_ = io.read685686 def read_mock(amt, decode_content=None):687 return read_(amt)688 setattr(io, 'read', read_mock)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 689why, one step back689 r.raw = ioMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 690why, one step back690 assert next(iter(r))Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 691why, one step back691 io.close()Merge pull request #1733 from ionrock/pickleable-responsesKenneth Reitzbefore adoptionaf921c7
lines 692–703why, one step back692693 def test_request_and_response_are_pickleable(self):694 r = requests.get(httpbin('get'))695696 # verify we can pickle the original request697 assert pickle.loads(pickle.dumps(r.request))698699 # verify we can pickle the response and that we have access to700 # the original request.701 pr = pickle.loads(pickle.dumps(r))702 assert r.request.url == pr.request.url703 assert r.request.headers == pr.request.headersMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 704–706why, one step back704705 def test_get_auth_from_url(self):706 url = 'http://user:pass@complex.url.com/path?query=yes'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 707why, one step back707 assert ('user', 'pass') == requests.utils.get_auth_from_url(url)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 708why, one step back708Merge pull request #1768 from Lukasa/credpctKenneth Reitzbefore adoption4bceb31
lines 709–717why, one step back709 def test_get_auth_from_url_encoded_spaces(self):710 url = 'http://user:pass%20pass@complex.url.com/path?query=yes'711 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)712713 def test_get_auth_from_url_not_encoded_spaces(self):714 url = 'http://user:pass pass@complex.url.com/path?query=yes'715 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)716717 def test_get_auth_from_url_percent_chars(self):Merge pull request #1862 from sybeck2k/masterKenneth Reitzbefore adoption0465d34
line 718why, one step back718 url = 'http://user%25user:pass@complex.url.com/path?query=yes'Merge pull request #1768 from Lukasa/credpctKenneth Reitzbefore adoption4bceb31
lines 719–720why, one step back719 assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url)720Merge pull request #1862 from sybeck2k/masterKenneth Reitzbefore adoption0465d34
lines 721–724why, one step back721 def test_get_auth_from_url_encoded_hashes(self):722 url = 'http://user:pass%23pass@complex.url.com/path?query=yes'723 assert ('user', 'pass#pass') == requests.utils.get_auth_from_url(url)724Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 725–726why, one step back725 def test_cannot_send_unprepared_requests(self):726 r = requests.Request(url=HTTPBIN)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 727–728why, one step back727 with pytest.raises(ValueError):728 requests.Session().send(r)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 729why, one step back729Merge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
lines 730–731why, one step back730 def test_http_error(self):731 error = requests.exceptions.HTTPError()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 732why, one step back732 assert not error.responseMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
lines 733–734why, one step back733 response = requests.Response()734 error = requests.exceptions.HTTPError(response=response)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 735why, one step back735 assert error.response == responseMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 736why, one step back736 error = requests.exceptions.HTTPError('message', response=response)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 737–738why, one step back737 assert str(error) == 'message'738 assert error.response == responseMerge pull request #1243 from darjus-amzn/masterKenneth Reitzbefore adoption25ea8cd
lines 739–744why, one step back739740 def test_session_pickling(self):741 r = requests.Request('GET', httpbin('get'))742 s = requests.Session()743744 s = pickle.loads(pickle.dumps(s))Merge pull request #1482 from dpursehouse/fix-testcases-with-proxyKenneth Reitzbefore adoptionf71bff1
line 745why, one step back745 s.proxies = getproxies()Merge pull request #1243 from darjus-amzn/masterKenneth Reitzbefore adoption25ea8cd
lines 746–747why, one step back746747 r = s.send(r.prepare())Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 748why, one step back748 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 749–758why, one step back749750 def test_fixes_1329(self):751 """752 Ensure that header updates are done case-insensitively.753 """754 s = requests.Session()755 s.headers.update({'ACCEPT': 'BOGUS'})756 s.headers.update({'accept': 'application/json'})757 r = s.get(httpbin('get'))758 headers = r.request.headersMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 759–761why, one step back759 assert headers['accept'] == 'application/json'760 assert headers['Accept'] == 'application/json'761 assert headers['ACCEPT'] == 'application/json'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 762–763why, one step back762763 def test_uppercase_scheme_redirect(self):Merge pull request #1487 from dpursehouse/rewrite-test_mixed_case_scheme_acceptableKenneth Reitzbefore adoptiond5fd3d3
lines 764–766why, one step back764 parts = urlparse(httpbin('html'))765 url = "HTTP://" + parts.netloc + parts.path766 r = requests.get(httpbin('redirect-to'), params={'url': url})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 767–768why, one step back767 assert r.status_code == 200768 assert r.url.lower() == url.lower()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 769–772why, one step back769770 def test_transport_adapter_ordering(self):771 s = requests.Session()772 order = ['https://', 'http://']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 773why, one step back773 assert order == list(s.adapters)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 774–785why, one step back774 s.mount('http://git', HTTPAdapter())775 s.mount('http://github', HTTPAdapter())776 s.mount('http://github.com', HTTPAdapter())777 s.mount('http://github.com/about/', HTTPAdapter())778 order = [779 'http://github.com/about/',780 'http://github.com',781 'http://github',782 'http://git',783 'https://',784 'http://',785 ]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 786why, one step back786 assert order == list(s.adapters)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 787–800why, one step back787 s.mount('http://gittip', HTTPAdapter())788 s.mount('http://gittip.com', HTTPAdapter())789 s.mount('http://gittip.com/about/', HTTPAdapter())790 order = [791 'http://github.com/about/',792 'http://gittip.com/about/',793 'http://github.com',794 'http://gittip.com',795 'http://github',796 'http://gittip',797 'http://git',798 'https://',799 'http://',800 ]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 801why, one step back801 assert order == list(s.adapters)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 802–804why, one step back802 s2 = requests.Session()803 s2.adapters = {'http://': HTTPAdapter()}804 s2.mount('https://', HTTPAdapter())Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 805–806why, one step back805 assert 'http://' in s2.adapters806 assert 'https://' in s2.adaptersMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
lines 807–820why, one step back807808 def test_header_remove_is_case_insensitive(self):809 # From issue #1321810 s = requests.Session()811 s.headers['foo'] = 'bar'812 r = s.get(httpbin('get'), headers={'FOO': None})813 assert 'foo' not in r.request.headers814815 def test_params_are_merged_case_sensitive(self):816 s = requests.Session()817 s.params['foo'] = 'bar'818 r = s.get(httpbin('get'), params={'FOO': 'bar'})819 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}820Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 821–828why, one step back821822 def test_long_authinfo_in_url(self):823 url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(824 'E8A3BE87-9E3F-4620-8858-95478E385B5B',825 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',826 'exactly-------------sixty-----------three------------characters',827 )828 r = requests.Request('GET', url).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 829why, one step back829 assert r.url == urlmerge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 830–837why, one step back830831 def test_header_keys_are_native(self):832 headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}833 r = requests.Request('GET', httpbin('get'), headers=headers)834 p = r.prepare()835836 # This is testing that they are builtin strings. A bit weird, but there837 # we go.Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 838–839why, one step back838 assert 'unicode' in p.headers.keys()839 assert 'byte' in p.headers.keys()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 840–846why, one step back840841 def test_can_send_nonstring_objects_with_files(self):842 data = {'a': 0.0}843 files = {'b': 'foo'}844 r = requests.Request('POST', httpbin('post'), data=data, files=files)845 p = r.prepare()846Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 847why, one step back847 assert 'multipart/form-data' in p.headers['Content-Type']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 848why, one step back848Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7b5c11f
lines 849–854why, one step back849 def test_autoset_header_values_are_native(self):850 data = 'this is a string'851 length = '16'852 req = requests.Request('POST', httpbin('post'), data=data)853 p = req.prepare()854Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 855why, one step back855 assert p.headers['Content-Length'] == lengthMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7b5c11f
line 856why, one step back856Merge pull request #1717 from jvantuyl/masterKenneth Reitzbefore adoptionbcb10af
lines 857–868why, one step back857 def test_oddball_schemes_dont_check_URLs(self):858 test_urls = (859 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==',860 'file:///etc/passwd',861 'magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431',862 )863 for test_url in test_urls:864 req = requests.Request('GET', test_url)865 preq = req.prepare()866 assert test_url == preq.url867868Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 869–872why, one step back869class TestContentEncodingDetection(unittest.TestCase):870871 def test_none(self):872 encodings = requests.utils.get_encodings_from_content('')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 873why, one step back873 assert not len(encodings)Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 874–878why, one step back874875 def test_html_charset(self):876 """HTML5 meta charset attribute"""877 content = '<meta charset="UTF-8">'878 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 879–880why, one step back879 assert len(encodings) == 1880 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 881–885why, one step back881882 def test_html4_pragma(self):883 """HTML4 pragma directive"""884 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">'885 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 886–887why, one step back886 assert len(encodings) == 1887 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 888–892why, one step back888889 def test_xhtml_pragma(self):890 """XHTML 1.x served with text/html MIME type"""891 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />'892 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 893–894why, one step back893 assert len(encodings) == 1894 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 895–899why, one step back895896 def test_xml(self):897 """XHTML 1.x served as XML"""898 content = '<?xml version="1.0" encoding="UTF-8"?>'899 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 900–901why, one step back900 assert len(encodings) == 1901 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 902–909why, one step back902903 def test_precedence(self):904 content = '''905 <?xml version="1.0" encoding="XML"?>906 <meta charset="HTML5">907 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />908 '''.strip()909 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 910why, one step back910 assert encodings == ['HTML5', 'HTML4', 'XML']Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 911–912why, one step back911912Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 913–916why, one step back913class TestCaseInsensitiveDict(unittest.TestCase):914915 def test_mapping_init(self):916 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 917–919why, one step back917 assert len(cid) == 2918 assert 'foo' in cid919 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 920–922why, one step back920921 def test_iterable_init(self):922 cid = CaseInsensitiveDict([('Foo', 'foo'), ('BAr', 'bar')])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 923–925why, one step back923 assert len(cid) == 2924 assert 'foo' in cid925 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 926–928why, one step back926927 def test_kwargs_init(self):928 cid = CaseInsensitiveDict(FOO='foo', BAr='bar')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 929–931why, one step back929 assert len(cid) == 2930 assert 'foo' in cid931 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 932–935why, one step back932933 def test_docstring_example(self):934 cid = CaseInsensitiveDict()935 cid['Accept'] = 'application/json'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 936–937why, one step back936 assert cid['aCCEPT'] == 'application/json'937 assert list(cid) == ['Accept']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 938–941why, one step back938939 def test_len(self):940 cid = CaseInsensitiveDict({'a': 'a', 'b': 'b'})941 cid['A'] = 'a'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 942why, one step back942 assert len(cid) == 2Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 943–945why, one step back943944 def test_getitem(self):945 cid = CaseInsensitiveDict({'Spam': 'blueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 946–947why, one step back946 assert cid['spam'] == 'blueval'947 assert cid['SPAM'] == 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 948–955why, one step back948949 def test_fixes_649(self):950 """__setitem__ should behave case-insensitively."""951 cid = CaseInsensitiveDict()952 cid['spam'] = 'oneval'953 cid['Spam'] = 'twoval'954 cid['sPAM'] = 'redval'955 cid['SPAM'] = 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 956–958why, one step back956 assert cid['spam'] == 'blueval'957 assert cid['SPAM'] == 'blueval'958 assert list(cid.keys()) == ['SPAM']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 959–963why, one step back959960 def test_delitem(self):961 cid = CaseInsensitiveDict()962 cid['Spam'] = 'someval'963 del cid['sPam']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 964–965why, one step back964 assert 'spam' not in cid965 assert len(cid) == 0Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 966–969why, one step back966967 def test_contains(self):968 cid = CaseInsensitiveDict()969 cid['Spam'] = 'someval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 970–974why, one step back970 assert 'Spam' in cid971 assert 'spam' in cid972 assert 'SPAM' in cid973 assert 'sPam' in cid974 assert 'notspam' not in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 975–979why, one step back975976 def test_get(self):977 cid = CaseInsensitiveDict()978 cid['spam'] = 'oneval'979 cid['SPAM'] = 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 980–983why, one step back980 assert cid.get('spam') == 'blueval'981 assert cid.get('SPAM') == 'blueval'982 assert cid.get('sPam') == 'blueval'983 assert cid.get('notspam', 'default') == 'default'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 984–988why, one step back984985 def test_update(self):986 cid = CaseInsensitiveDict()987 cid['spam'] = 'blueval'988 cid.update({'sPam': 'notblueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 989why, one step back989 assert cid['spam'] == 'notblueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 990–991why, one step back990 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})991 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 992–994why, one step back992 assert len(cid) == 2993 assert cid['foo'] == 'anotherfoo'994 assert cid['bar'] == 'anotherbar'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 995–998why, one step back995996 def test_update_retains_unchanged(self):997 cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})998 cid.update({'foo': 'newfoo'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 999why, one step back999 assert cid['bar'] == 'bar'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1000–1003why, one step back10001001 def test_iter(self):1002 cid = CaseInsensitiveDict({'Spam': 'spam', 'Eggs': 'eggs'})1003 keys = frozenset(['Spam', 'Eggs'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1004why, one step back1004 assert frozenset(iter(cid)) == keysMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1005–1008why, one step back10051006 def test_equality(self):1007 cid = CaseInsensitiveDict({'SPAM': 'blueval', 'Eggs': 'redval'})1008 othercid = CaseInsensitiveDict({'spam': 'blueval', 'eggs': 'redval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1009why, one step back1009 assert cid == othercidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 1010why, one step back1010 del othercid['spam']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1011–1012why, one step back1011 assert cid != othercid1012 assert cid == {'spam': 'blueval', 'eggs': 'redval'}Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1013–1015why, one step back10131014 def test_setdefault(self):1015 cid = CaseInsensitiveDict({'Spam': 'blueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1016–1017why, one step back1016 assert cid.setdefault('spam', 'notblueval') == 'blueval'1017 assert cid.setdefault('notspam', 'notblueval') == 'notblueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1018–1025why, one step back10181019 def test_lower_items(self):1020 cid = CaseInsensitiveDict({1021 'Accept': 'application/json',1022 'user-Agent': 'requests',1023 })1024 keyset = frozenset(lowerkey for lowerkey, v in cid.lower_items())1025 lowerkeyset = frozenset(['accept', 'user-agent'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1026why, one step back1026 assert keyset == lowerkeysetMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1027–1033why, one step back10271028 def test_preserve_key_case(self):1029 cid = CaseInsensitiveDict({1030 'Accept': 'application/json',1031 'user-Agent': 'requests',1032 })1033 keyset = frozenset(['Accept', 'user-Agent'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1034–1036why, one step back1034 assert frozenset(i[0] for i in cid.items()) == keyset1035 assert frozenset(cid.keys()) == keyset1036 assert frozenset(cid) == keysetMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1037–1045why, one step back10371038 def test_preserve_last_key_case(self):1039 cid = CaseInsensitiveDict({1040 'Accept': 'application/json',1041 'user-Agent': 'requests',1042 })1043 cid.update({'ACCEPT': 'application/json'})1044 cid['USER-AGENT'] = 'requests'1045 keyset = frozenset(['ACCEPT', 'USER-AGENT'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1046–1048why, one step back1046 assert frozenset(i[0] for i in cid.items()) == keyset1047 assert frozenset(cid.keys()) == keyset1048 assert frozenset(cid) == keysetMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 1049why, one step back1049Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
lines 1050–1058why, one step back10501051class UtilsTestCase(unittest.TestCase):10521053 def test_super_len_io_streams(self):1054 """ Ensures that we properly deal with different kinds of IO streams. """1055 # uses StringIO or io.StringIO (see import above)1056 from io import BytesIO1057 from requests.utils import super_len1058Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1059–1060why, one step back1059 assert super_len(StringIO.StringIO()) == 01060 assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 29Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
line 1061why, one step back1061Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1062–1063why, one step back1062 assert super_len(BytesIO()) == 01063 assert super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 40Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
lines 1064–1069why, one step back10641065 try:1066 import cStringIO1067 except ImportError:1068 pass1069 else:Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1070why, one step back1070 assert super_len(cStringIO.StringIO('but some how, some way...')) == 25Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
lines 1071–1110why, one step back10711072 def test_get_environ_proxies_ip_ranges(self):1073 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1074 from requests.utils import get_environ_proxies1075 os.environ['no_proxy'] = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"1076 assert get_environ_proxies('http://192.168.0.1:5000/') == {}1077 assert get_environ_proxies('http://192.168.0.1/') == {}1078 assert get_environ_proxies('http://172.16.1.1/') == {}1079 assert get_environ_proxies('http://172.16.1.1:5000/') == {}1080 assert get_environ_proxies('http://192.168.1.1:5000/') != {}1081 assert get_environ_proxies('http://192.168.1.1/') != {}10821083 def test_get_environ_proxies(self):1084 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1085 from requests.utils import get_environ_proxies1086 os.environ['no_proxy'] = "127.0.0.1,localhost.localdomain,192.168.0.0/24,172.16.1.1"1087 assert get_environ_proxies('http://localhost.localdomain:5000/v1.0/') == {}1088 assert get_environ_proxies('http://www.requests.com/') != {}10891090 def test_is_ipv4_address(self):1091 from requests.utils import is_ipv4_address1092 assert is_ipv4_address('8.8.8.8')1093 assert not is_ipv4_address('8.8.8.8.8')1094 assert not is_ipv4_address('localhost.localdomain')10951096 def test_is_valid_cidr(self):1097 from requests.utils import is_valid_cidr1098 assert not is_valid_cidr('8.8.8.8')1099 assert is_valid_cidr('192.168.1.0/24')11001101 def test_dotted_netmask(self):1102 from requests.utils import dotted_netmask1103 assert dotted_netmask(8) == '255.0.0.0'1104 assert dotted_netmask(24) == '255.255.255.0'1105 assert dotted_netmask(25) == '255.255.255.128'11061107 def test_address_in_network(self):1108 from requests.utils import address_in_network1109 assert address_in_network('192.168.1.1', '192.168.1.0/24')1110 assert not address_in_network('172.16.0.1', '192.168.1.0/24')Merge pull request #1772 from mdbecker/make_morsel_to_cookie_more_pythonicKenneth Reitzbefore adoption9fc0701
line 1111why, one step back1111Merge pull request #1862 from sybeck2k/masterKenneth Reitzbefore adoption0465d34
lines 1112–1121why, one step back1112 def test_get_auth_from_url(self):1113 """ Ensures that username and password in well-encoded URI as per RFC 3986 are correclty extracted """1114 from requests.utils import get_auth_from_url1115 from requests.compat import quote1116 percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "1117 url_address = "request.com/url.html#test"1118 url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address1119 (username, password) = get_auth_from_url(url)1120 assert username == percent_encoding_test_chars1121 assert password == percent_encoding_test_charsMerge pull request #1772 from mdbecker/make_morsel_to_cookie_more_pythonicKenneth Reitzbefore adoption9fc0701
lines 1122–1179why, one step back112211231124class TestMorselToCookieExpires(unittest.TestCase):11251126 """Tests for morsel_to_cookie when morsel contains expires."""11271128 def test_expires_valid_str(self):1129 """Test case where we convert expires from string time."""11301131 morsel = Morsel()1132 morsel['expires'] = 'Thu, 01-Jan-1970 00:00:01 GMT'1133 cookie = morsel_to_cookie(morsel)1134 assert cookie.expires == 111351136 def test_expires_invalid_int(self):1137 """Test case where an invalid type is passed for expires."""11381139 morsel = Morsel()1140 morsel['expires'] = 1001141 with pytest.raises(TypeError):1142 morsel_to_cookie(morsel)11431144 def test_expires_invalid_str(self):1145 """Test case where an invalid string is input."""11461147 morsel = Morsel()1148 morsel['expires'] = 'woops'1149 with pytest.raises(ValueError):1150 morsel_to_cookie(morsel)11511152 def test_expires_none(self):1153 """Test case where expires is None."""11541155 morsel = Morsel()1156 morsel['expires'] = None1157 cookie = morsel_to_cookie(morsel)1158 assert cookie.expires is None115911601161class TestMorselToCookieMaxAge(unittest.TestCase):11621163 """Tests for morsel_to_cookie when morsel contains max-age."""11641165 def test_max_age_valid_int(self):1166 """Test case where a valid max age in seconds is passed."""11671168 morsel = Morsel()1169 morsel['max-age'] = 601170 cookie = morsel_to_cookie(morsel)1171 assert isinstance(cookie.expires, int)11721173 def test_max_age_invalid_str(self):1174 """Test case where a invalid max age is passed."""11751176 morsel = Morsel()1177 morsel['max-age'] = 'woops'1178 with pytest.raises(TypeError):1179 morsel_to_cookie(morsel)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
line 1180why, one step back1180Merge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 1181why, one step back1181Merge pull request #1935 from cjstapleton/masterKenneth Reitzbefore adoptiond8557a2
lines 1182–1189why, one step back1182class TestTimeout:1183 def test_stream_timeout(self):1184 try:1185 r = requests.get('https://httpbin.org/delay/10', timeout=5.0)1186 except requests.exceptions.Timeout as e:1187 assert 'Read timed out' in e.args[0].args[0]11881189Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 1190–1191why, one step back1190if __name__ == '__main__':1191 unittest.main()