test_requests.py
This file
Path
test_requests.py
1,160 lines · 39.2 KiB · Python
Last changed by
Unquote the auth after splitting the url.Cory Benfieldbefore adoptionca187ab
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 #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 118–127why, one step back118119 # def test_HTTP_302_ALLOW_REDIRECT_POST(self):120 # r = requests.post(httpbin('status', '302'), data={'some': 'data'})121 # self.assertEqual(r.status_code, 200)122123 def test_HTTP_200_OK_GET_WITH_PARAMS(self):124 heads = {'User-agent': 'Mozilla/5.0'}125126 r = requests.get(httpbin('user-agent'), headers=heads)127Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 128–129why, one step back128 assert heads['User-agent'] in r.text129 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 130–134why, one step back130131 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):132 heads = {'User-agent': 'Mozilla/5.0'}133134 r = requests.get(httpbin('get') + '?test=true', params={'q': 'test'}, headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 135why, one step back135 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 136why, one step back136Merge pull request #1180 from sigmavirus24/masterKenneth Reitzbefore adoption5d9fcc7
lines 137–140why, one step back137 def test_set_cookie_on_301(self):138 s = requests.session()139 url = httpbin('cookies/set?foo=bar')140 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 141why, one step back141 assert s.cookies['foo'] == 'bar'Merge pull request #1180 from sigmavirus24/masterKenneth Reitzbefore adoption5d9fcc7
line 142why, one step back142Merge pull request #1239 from miikka/fix-issue-1228Kenneth Reitzbefore adoptioncb2116d
lines 143–146why, one step back143 def test_cookie_sent_on_redirect(self):144 s = requests.session()145 s.get(httpbin('cookies/set?foo=bar'))146 r = s.get(httpbin('redirect/1')) # redirects to httpbin('get')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 147why, one step back147 assert 'Cookie' in r.json()['headers']Merge pull request #1239 from miikka/fix-issue-1228Kenneth Reitzbefore adoptioncb2116d
line 148why, one step back148Merge pull request #1290 from gazpachoking/#1287Kenneth Reitzbefore adoption848f2c2
lines 149–151why, one step back149 def test_cookie_removed_on_expire(self):150 s = requests.session()151 s.get(httpbin('cookies/set?foo=bar'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 152why, one step back152 assert s.cookies['foo'] == 'bar'Merge pull request #1290 from gazpachoking/#1287Kenneth Reitzbefore adoption848f2c2
lines 153–160why, one step back153 s.get(154 httpbin('response-headers'),155 params={156 'Set-Cookie':157 'foo=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT'158 }159 )160 assert 'foo' not in s.cookiesMerge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
line 161why, one step back161Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 162–164why, one step back162 def test_cookie_quote_wrapped(self):163 s = requests.session()164 s.get(httpbin('cookies/set?foo="bar:baz"'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 165why, one step back165 assert s.cookies['foo'] == '"bar:baz"'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
line 166why, one step back166Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
lines 167–168why, one step back167 def test_cookie_persists_via_api(self):168 s = requests.session()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
line 169why, one step back169 r = s.get(httpbin('redirect/1'), cookies={'foo': 'bar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 170–171why, one step back170 assert 'foo' in r.request.headers['Cookie']171 assert 'foo' in r.history[0].request.headers['Cookie']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
line 172why, one step back172Merge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
lines 173–180why, one step back173 def test_request_cookie_overrides_session_cookie(self):174 s = requests.session()175 s.cookies['foo'] = 'bar'176 r = s.get(httpbin('cookies'), cookies={'foo': 'baz'})177 assert r.json()['cookies']['foo'] == 'baz'178 # Session cookie should not be modified179 assert s.cookies['foo'] == 'bar'180Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
lines 181–186why, one step back181 def test_request_cookies_not_persisted(self):182 s = requests.session()183 s.get(httpbin('cookies'), cookies={'foo': 'baz'})184 # Sending a request with cookies should not add cookies to the session185 assert not s.cookies186Merge pull request #1328 from gazpachoking/session_cj_fixKenneth Reitzbefore adoption98dea03
lines 187–196why, one step back187 def test_generic_cookiejar_works(self):188 cj = cookielib.CookieJar()189 cookiejar_from_dict({'foo': 'bar'}, cj)190 s = requests.session()191 s.cookies = cj192 r = s.get(httpbin('cookies'))193 # Make sure the cookie was sent194 assert r.json()['cookies']['foo'] == 'bar'195 # Make sure the session cj is still the custom one196 assert s.cookies is cjUnquote the auth after splitting the url.Cory Benfieldbefore adoptionca187ab
line 197why, one step back197Merge pull request #1713 from daftshady/masterKenneth Reitzbefore adoption8b88549
lines 198–204why, one step back198 def test_param_cookiejar_works(self):199 cj = cookielib.CookieJar()200 cookiejar_from_dict({'foo' : 'bar'}, cj)201 s = requests.session()202 r = s.get(httpbin('cookies'), cookies=cj)203 # Make sure the cookie was sent204 assert r.json()['cookies']['foo'] == 'bar'merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 205why, one step back205Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 206–209why, one step back206 def test_requests_in_history_are_not_overridden(self):207 resp = requests.get(httpbin('redirect/3'))208 urls = [r.url for r in resp.history]209 req_urls = [r.request.url for r in resp.history]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 210why, one step back210 assert urls == req_urlsmerge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 211why, one step back211Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 212–218why, one step back212 def test_user_agent_transfers(self):213214 heads = {215 'User-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'216 }217218 r = requests.get(httpbin('user-agent'), headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 219why, one step back219 assert heads['User-agent'] in r.textMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 220–225why, one step back220221 heads = {222 'user-agent': 'Mozilla/5.0 (github.com/kennethreitz/requests)'223 }224225 r = requests.get(httpbin('user-agent'), headers=heads)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 226why, one step back226 assert heads['user-agent'] in r.textMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 227–229why, one step back227228 def test_HTTP_200_OK_HEAD(self):229 r = requests.head(httpbin('get'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 230why, one step back230 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 231–233why, one step back231232 def test_HTTP_200_OK_PUT(self):233 r = requests.put(httpbin('put'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 234why, one step back234 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 235–240why, one step back235236 def test_BASICAUTH_TUPLE_HTTP_200_OK_GET(self):237 auth = ('user', 'pass')238 url = httpbin('basic-auth', 'user', 'pass')239240 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 241why, one step back241 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 242–243why, one step back242243 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 244why, one step back244 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 245–248why, one step back245246 s = requests.session()247 s.auth = auth248 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 249why, one step back249 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 250why, one step back250Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 251–261why, one step back251 def test_basicauth_with_netrc(self):252 auth = ('user', 'pass')253 wrong_auth = ('wronguser', 'wrongpass')254 url = httpbin('basic-auth', 'user', 'pass')255256 def get_netrc_auth_mock(url):257 return auth258 requests.sessions.get_netrc_auth = get_netrc_auth_mock259260 # Should use netrc and work.261 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 262why, one step back262 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 263–265why, one step back263264 # Given auth should override and fail.265 r = requests.get(url, auth=wrong_auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 266why, one step back266 assert r.status_code == 401Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 267–268why, one step back267268 s = requests.session()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 269why, one step back269Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 270–271why, one step back270 # Should use netrc and work.271 r = s.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–276why, one step back273274 # Given auth should override and fail.275 s.auth = wrong_auth276 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 277why, one step back277 assert r.status_code == 401Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
line 278why, one step back278Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 279–284why, one step back279 def test_DIGEST_HTTP_200_OK_GET(self):280281 auth = HTTPDigestAuth('user', 'pass')282 url = httpbin('digest-auth', 'auth', 'user', 'pass')283284 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 285why, one step back285 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 286–287why, one step back286287 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 288why, one step back288 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 289–290why, one step back289290 s = requests.session()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
line 291why, one step back291 s.auth = HTTPDigestAuth('user', 'pass')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 292why, one step back292 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 293why, one step back293 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 294why, one step back294merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 295–310why, one step back295 def test_DIGEST_AUTH_RETURNS_COOKIE(self):296 url = httpbin('digest-auth', 'auth', 'user', 'pass')297 auth = HTTPDigestAuth('user', 'pass')298 r = requests.get(url)299 assert r.cookies['fake'] == 'fake_value'300301 r = requests.get(url, auth=auth)302 assert r.status_code == 200303304 def test_DIGEST_AUTH_SETS_SESSION_COOKIES(self):305 url = httpbin('digest-auth', 'auth', 'user', 'pass')306 auth = HTTPDigestAuth('user', 'pass')307 s = requests.Session()308 s.get(url, auth=auth)309 assert s.cookies['fake'] == 'fake_value'310Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
lines 311–316why, one step back311 def test_DIGEST_STREAM(self):312313 auth = HTTPDigestAuth('user', 'pass')314 url = httpbin('digest-auth', 'auth', 'user', 'pass')315316 r = requests.get(url, auth=auth, stream=True)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 317why, one step back317 assert r.raw.read() != b''Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
lines 318–319why, one step back318319 r = requests.get(url, auth=auth, stream=False)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 320why, one step back320 assert r.raw.read() == b''Merge pull request #1190 from mkomitee/masterKenneth Reitzbefore adoptiond372a5b
line 321why, one step back321Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 322–327why, one step back322 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):323324 auth = HTTPDigestAuth('user', 'wrongpass')325 url = httpbin('digest-auth', 'auth', 'user', 'pass')326327 r = requests.get(url, auth=auth)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 328why, one step back328 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 329–330why, one step back329330 r = requests.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 331why, one step back331 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 332–335why, one step back332333 s = requests.session()334 s.auth = auth335 r = s.get(url)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 336why, one step back336 assert r.status_code == 401Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 337why, one step back337Merge pull request #1766 from Lukasa/qopKenneth Reitzbefore adoptiona030a58
lines 338–345why, one step back338 def test_DIGESTAUTH_QUOTES_QOP_VALUE(self):339340 auth = HTTPDigestAuth('user', 'pass')341 url = httpbin('digest-auth', 'auth', 'user', 'pass')342343 r = requests.get(url, auth=auth)344 assert '"auth"' in r.request.headers['Authorization']345Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 346–351why, one step back346 def test_POSTBIN_GET_POST_FILES(self):347348 url = httpbin('post')349 post1 = requests.post(url).raise_for_status()350351 post1 = requests.post(url, data={'some': 'data'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 352why, one step back352 assert post1.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 353–355why, one step back353354 with open('requirements.txt') as f:355 post2 = requests.post(url, files={'some': f})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 356why, one step back356 assert post2.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 357–358why, one step back357358 post4 = requests.post(url, data='[{"some": "json"}]')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 359why, one step back359 assert post4.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 360why, one step back360Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 361–362why, one step back361 with pytest.raises(ValueError):362 requests.post(url, files = ['bad file data'])Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 363–369why, one step back363364 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):365366 url = httpbin('post')367 post1 = requests.post(url).raise_for_status()368369 post1 = requests.post(url, data={'some': 'data'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 370why, one step back370 assert post1.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 371–373why, one step back371372 with open('requirements.txt') as f:373 post2 = requests.post(url, data={'some': 'data'}, files={'some': f})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 374why, one step back374 assert post2.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 375–376why, one step back375376 post4 = requests.post(url, data='[{"some": "json"}]')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 377why, one step back377 assert post4.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 378why, one step back378Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 379–380why, one step back379 with pytest.raises(ValueError):380 requests.post(url, files = ['bad file data'])Merge pull request #1503 from skastel/masterKenneth Reitzbefore adoption23ced52
lines 381–386why, one step back381382 def test_conflicting_post_params(self):383 url = httpbin('post')384 with open('requirements.txt') as f:385 pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})")386 pytest.raises(ValueError, "requests.post(url, data=u'[{\"some\": \"data\"}]', files={'some': f})")Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 387–389why, one step back387388 def test_request_ok_set(self):389 r = requests.get(httpbin('status', '404'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 390why, one step back390 assert not r.okMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 391–393why, one step back391392 def test_status_raising(self):393 r = requests.get(httpbin('status', '404'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 394–395why, one step back394 with pytest.raises(requests.exceptions.HTTPError):395 r.raise_for_status()Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 396–397why, one step back396397 r = requests.get(httpbin('status', '500'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 398why, one step back398 assert not r.okMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 399–411why, one step back399400 def test_decompress_gzip(self):401 r = requests.get(httpbin('gzip'))402 r.content.decode('ascii')403404 def test_unicode_get(self):405 url = httpbin('/get')406 requests.get(url, params={'foo': 'føø'})407 requests.get(url, params={'føø': 'føø'})408 requests.get(url, params={'føø': 'føø'})409 requests.get(url, params={'foo': 'foo'})410 requests.get(httpbin('ø'), params={'foo': 'foo'})411Merge pull request #1181 from denis-ryzhkov/masterKenneth Reitzbefore adoptioncdec20a
lines 412–414why, one step back412 def test_unicode_header_name(self):413 requests.put(httpbin('put'), headers={str('Content-Type'): 'application/octet-stream'}, data='\xff') # compat.str is unicode.414Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 415–417why, one step back415 def test_urlencoded_get_query_multivalued_param(self):416417 r = requests.get(httpbin('get'), params=dict(test=['foo', 'baz']))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 418–419why, one step back418 assert r.status_code == 200419 assert r.url == httpbin('get?test=foo&test=baz')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 420–425why, one step back420421 def test_different_encodings_dont_break_post(self):422 r = requests.post(httpbin('post'),423 data={'stuff': json.dumps({'a': 123})},424 params={'blah': 'asdf1234'},425 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 426why, one step back426 assert r.status_code == 200Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 427why, one step back427Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 428–431why, one step back428 def test_unicode_multipart_post(self):429 r = requests.post(httpbin('post'),430 data={'stuff': u'ëlïxr'},431 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 432why, one step back432 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 433–436why, one step back433434 r = requests.post(httpbin('post'),435 data={'stuff': u'ëlïxr'.encode('utf-8')},436 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 437why, one step back437 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 438–441why, one step back438439 r = requests.post(httpbin('post'),440 data={'stuff': 'elixr'},441 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 442why, one step back442 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
lines 443–446why, one step back443444 r = requests.post(httpbin('post'),445 data={'stuff': 'elixr'.encode('utf-8')},446 files={'file': ('test_requests.py', open(__file__, 'rb'))})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 447why, one step back447 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption4438bfc
line 448why, one step back448Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
lines 449–456why, one step back449 def test_unicode_multipart_post_fieldnames(self):450 filename = os.path.splitext(__file__)[0] + '.py'451 r = requests.Request(method='POST',452 url=httpbin('post'),453 data={'stuff'.encode('utf-8'): 'elixr'},454 files={'file': ('test_requests.py',455 open(filename, 'rb'))})456 prep = r.prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 457–458why, one step back457 assert b'name="stuff"' in prep.body458 assert b'name="b\'stuff\'"' not in prep.bodyMerge pull request #1733 from ionrock/pickleable-responsesKenneth Reitzbefore adoptionaf921c7
line 459why, one step back459Merge pull request #1724 from daftshady/dev3Kenneth Reitzbefore adoption7ccbcd2
lines 460–463why, one step back460 def test_unicode_method_name(self):461 files = {'file': open('test_requests.py', 'rb')}462 r = requests.request(method=u'POST', url=httpbin('post'), files=files)463 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
line 464why, one step back464Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 465–470why, one step back465 def test_custom_content_type(self):466 r = requests.post(httpbin('post'),467 data={'stuff': json.dumps({'a': 123})},468 files={'file1': ('test_requests.py', open(__file__, 'rb')),469 'file2': ('test_requests', open(__file__, 'rb'),470 'text/py-content-type')})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 471–472why, one step back471 assert r.status_code == 200472 assert b"text/py-content-type" in r.request.bodyMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 473why, one step back473Merge pull request #1267 from sigmavirus24/masterKenneth Reitzbefore adoptionbd6b981
lines 474–480why, one step back474 def test_hook_receives_request_arguments(self):475 def hook(resp, **kwargs):476 assert resp is not None477 assert kwargs != {}478479 requests.Request('GET', HTTPBIN, hooks={'response': hook})480Merge pull request #1657 from sigmavirus24/fix-session-hooksKenneth Reitzbefore adoption5c91545
lines 481–499why, one step back481 def test_session_hooks_are_used_with_no_request_hooks(self):482 hook = lambda x, *args, **kwargs: x483 s = requests.Session()484 s.hooks['response'].append(hook)485 r = requests.Request('GET', HTTPBIN)486 prep = s.prepare_request(r)487 assert prep.hooks['response'] != []488 assert prep.hooks['response'] == [hook]489490 def test_session_hooks_are_overriden_by_request_hooks(self):491 hook1 = lambda x, *args, **kwargs: x492 hook2 = lambda x, *args, **kwargs: x493 assert hook1 is not hook2494 s = requests.Session()495 s.hooks['response'].append(hook2)496 r = requests.Request('GET', HTTPBIN, hooks={'response': [hook1]})497 prep = s.prepare_request(r)498 assert prep.hooks['response'] == [hook1]499Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 500why, one step back500 def test_prepared_request_hook(self):Merge pull request #1267 from sigmavirus24/masterKenneth Reitzbefore adoptionbd6b981
line 501why, one step back501 def hook(resp, **kwargs):Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 502–508why, one step back502 resp.hook_working = True503 return resp504505 req = requests.Request('GET', HTTPBIN, hooks={'response': hook})506 prep = req.prepare()507508 s = requests.Session()Merge pull request #1482 from dpursehouse/fix-testcases-with-proxyKenneth Reitzbefore adoptionf71bff1
line 509why, one step back509 s.proxies = getproxies()Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 510–511why, one step back510 resp = s.send(prep)511Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 512why, one step back512 assert hasattr(resp, 'hook_working')Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 513why, one step back513Merge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
lines 514–520why, one step back514 def test_prepared_from_session(self):515 class DummyAuth(requests.auth.AuthBase):516 def __call__(self, r):517 r.headers['Dummy-Auth-Test'] = 'dummy-auth-test-ok'518 return r519520 req = requests.Request('GET', httpbin('headers'))Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 521why, one step back521 assert not req.authMerge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
lines 522–528why, one step back522523 s = requests.Session()524 s.auth = DummyAuth()525526 prep = s.prepare_request(req)527 resp = s.send(prep)528Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 529why, one step back529 assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'Merge pull request #1507 from buzztabapp/prepared-session-requestsKenneth Reitzbefore adoption3e6e68b
line 530why, one step back530Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 531–552why, one step back531 def test_links(self):532 r = requests.Response()533 r.headers = {534 'cache-control': 'public, max-age=60, s-maxage=60',535 'connection': 'keep-alive',536 'content-encoding': 'gzip',537 'content-type': 'application/json; charset=utf-8',538 'date': 'Sat, 26 Jan 2013 16:47:56 GMT',539 'etag': '"6ff6a73c0e446c1f61614769e3ceb778"',540 'last-modified': 'Sat, 26 Jan 2013 16:22:39 GMT',541 'link': ('<https://api.github.com/users/kennethreitz/repos?'542 'page=2&per_page=10>; rel="next", <https://api.github.'543 'com/users/kennethreitz/repos?page=7&per_page=10>; '544 ' rel="last"'),545 'server': 'GitHub.com',546 'status': '200 OK',547 'vary': 'Accept',548 'x-content-type-options': 'nosniff',549 'x-github-media-type': 'github.beta',550 'x-ratelimit-limit': '60',551 'x-ratelimit-remaining': '57'552 }Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 553why, one step back553 assert r.links['next']['rel'] == 'next'Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 554–564why, one step back554555 def test_cookie_parameters(self):556 key = 'some_cookie'557 value = 'some_value'558 secure = True559 domain = 'test.com'560 rest = {'HttpOnly': True}561562 jar = requests.cookies.RequestsCookieJar()563 jar.set(key, value, secure=secure, domain=domain, rest=rest)564Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 565–566why, one step back565 assert len(jar) == 1566 assert 'some_cookie' in jarMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 567–568why, one step back567568 cookie = list(jar)[0]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 569–571why, one step back569 assert cookie.secure == secure570 assert cookie.domain == domain571 assert cookie._rest['HttpOnly'] == rest['HttpOnly']Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 572why, one step back572Merge branch 'master' into fix-pickling-adaptersKenneth Reitzbefore adoptiondf1c233
lines 573–660why, one step back573 def test_cookie_as_dict_keeps_len(self):574 key = 'some_cookie'575 value = 'some_value'576577 key1 = 'some_cookie1'578 value1 = 'some_value1'579580 jar = requests.cookies.RequestsCookieJar()581 jar.set(key, value)582 jar.set(key1, value1)583584 d1 = dict(jar)585 d2 = dict(jar.iteritems())586 d3 = dict(jar.items())587588 assert len(jar) == 2589 assert len(d1) == 2590 assert len(d2) == 2591 assert len(d3) == 2592593 def test_cookie_as_dict_keeps_items(self):594 key = 'some_cookie'595 value = 'some_value'596597 key1 = 'some_cookie1'598 value1 = 'some_value1'599600 jar = requests.cookies.RequestsCookieJar()601 jar.set(key, value)602 jar.set(key1, value1)603604 d1 = dict(jar)605 d2 = dict(jar.iteritems())606 d3 = dict(jar.items())607608 assert d1['some_cookie'] == 'some_value'609 assert d2['some_cookie'] == 'some_value'610 assert d3['some_cookie1'] == 'some_value1'611612 def test_cookie_as_dict_keys(self):613 key = 'some_cookie'614 value = 'some_value'615616 key1 = 'some_cookie1'617 value1 = 'some_value1'618619 jar = requests.cookies.RequestsCookieJar()620 jar.set(key, value)621 jar.set(key1, value1)622623 keys = jar.keys()624 assert keys == list(keys)625 # make sure one can use keys multiple times626 assert list(keys) == list(keys)627628 def test_cookie_as_dict_values(self):629 key = 'some_cookie'630 value = 'some_value'631632 key1 = 'some_cookie1'633 value1 = 'some_value1'634635 jar = requests.cookies.RequestsCookieJar()636 jar.set(key, value)637 jar.set(key1, value1)638639 values = jar.values()640 assert values == list(values)641 # make sure one can use values multiple times642 assert list(values) == list(values)643644 def test_cookie_as_dict_items(self):645 key = 'some_cookie'646 value = 'some_value'647648 key1 = 'some_cookie1'649 value1 = 'some_value1'650651 jar = requests.cookies.RequestsCookieJar()652 jar.set(key, value)653 jar.set(key1, value1)654655 items = jar.items()656 assert items == list(items)657 # make sure one can use items multiple times658 assert list(items) == list(items)659660Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 661–665why, one step back661 def test_time_elapsed_blank(self):662 r = requests.get(httpbin('get'))663 td = r.elapsed664 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)665 * 10**6) / 10**6)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 666why, one step back666 assert total_seconds > 0.0Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 667–670why, one step back667668 def test_response_is_iterable(self):669 r = requests.Response()670 io = StringIO.StringIO('abc')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption636476e
lines 671–675why, one step back671 read_ = io.read672673 def read_mock(amt, decode_content=None):674 return read_(amt)675 setattr(io, 'read', read_mock)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 676why, one step back676 r.raw = ioMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 677why, one step back677 assert next(iter(r))Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 678why, one step back678 io.close()Merge pull request #1733 from ionrock/pickleable-responsesKenneth Reitzbefore adoptionaf921c7
lines 679–690why, one step back679680 def test_request_and_response_are_pickleable(self):681 r = requests.get(httpbin('get'))682683 # verify we can pickle the original request684 assert pickle.loads(pickle.dumps(r.request))685686 # verify we can pickle the response and that we have access to687 # the original request.688 pr = pickle.loads(pickle.dumps(r))689 assert r.request.url == pr.request.url690 assert r.request.headers == pr.request.headersMerge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 691–693why, one step back691692 def test_get_auth_from_url(self):693 url = 'http://user:pass@complex.url.com/path?query=yes'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 694why, one step back694 assert ('user', 'pass') == requests.utils.get_auth_from_url(url)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 695why, one step back695Merge pull request #1768 from Lukasa/credpctKenneth Reitzbefore adoption4bceb31
lines 696–706why, one step back696 def test_get_auth_from_url_encoded_spaces(self):697 url = 'http://user:pass%20pass@complex.url.com/path?query=yes'698 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)699700 def test_get_auth_from_url_not_encoded_spaces(self):701 url = 'http://user:pass pass@complex.url.com/path?query=yes'702 assert ('user', 'pass pass') == requests.utils.get_auth_from_url(url)703704 def test_get_auth_from_url_percent_chars(self):705 url = 'http://user%user:pass@complex.url.com/path?query=yes'706 assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url)Unquote the auth after splitting the url.Cory Benfieldbefore adoptionca187ab
lines 707–710why, one step back707708 def test_get_auth_from_url_encoded_hashes(self):709 url = 'http://user:pass%23pass@complex.url.com/path?query=yes'710 assert ('user', 'pass#pass') == requests.utils.get_auth_from_url(url)Merge pull request #1768 from Lukasa/credpctKenneth Reitzbefore adoption4bceb31
line 711why, one step back711Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 712–713why, one step back712 def test_cannot_send_unprepared_requests(self):713 r = requests.Request(url=HTTPBIN)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 714–715why, one step back714 with pytest.raises(ValueError):715 requests.Session().send(r)Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
line 716why, one step back716Merge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
lines 717–718why, one step back717 def test_http_error(self):718 error = requests.exceptions.HTTPError()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 719why, one step back719 assert not error.responseMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
lines 720–721why, one step back720 response = requests.Response()721 error = requests.exceptions.HTTPError(response=response)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 722why, one step back722 assert error.response == responseMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 723why, one step back723 error = requests.exceptions.HTTPError('message', response=response)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 724–725why, one step back724 assert str(error) == 'message'725 assert error.response == responseMerge pull request #1243 from darjus-amzn/masterKenneth Reitzbefore adoption25ea8cd
lines 726–731why, one step back726727 def test_session_pickling(self):728 r = requests.Request('GET', httpbin('get'))729 s = requests.Session()730731 s = pickle.loads(pickle.dumps(s))Merge pull request #1482 from dpursehouse/fix-testcases-with-proxyKenneth Reitzbefore adoptionf71bff1
line 732why, one step back732 s.proxies = getproxies()Merge pull request #1243 from darjus-amzn/masterKenneth Reitzbefore adoption25ea8cd
lines 733–734why, one step back733734 r = s.send(r.prepare())Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 735why, one step back735 assert r.status_code == 200Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 736–745why, one step back736737 def test_fixes_1329(self):738 """739 Ensure that header updates are done case-insensitively.740 """741 s = requests.Session()742 s.headers.update({'ACCEPT': 'BOGUS'})743 s.headers.update({'accept': 'application/json'})744 r = s.get(httpbin('get'))745 headers = r.request.headersMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 746–748why, one step back746 assert headers['accept'] == 'application/json'747 assert headers['Accept'] == 'application/json'748 assert headers['ACCEPT'] == 'application/json'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptione0df216
lines 749–750why, one step back749750 def test_uppercase_scheme_redirect(self):Merge pull request #1487 from dpursehouse/rewrite-test_mixed_case_scheme_acceptableKenneth Reitzbefore adoptiond5fd3d3
lines 751–753why, one step back751 parts = urlparse(httpbin('html'))752 url = "HTTP://" + parts.netloc + parts.path753 r = requests.get(httpbin('redirect-to'), params={'url': url})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 754–755why, one step back754 assert r.status_code == 200755 assert r.url.lower() == url.lower()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 756–759why, one step back756757 def test_transport_adapter_ordering(self):758 s = requests.Session()759 order = ['https://', 'http://']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 760why, one step back760 assert order == list(s.adapters)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 761–772why, one step back761 s.mount('http://git', HTTPAdapter())762 s.mount('http://github', HTTPAdapter())763 s.mount('http://github.com', HTTPAdapter())764 s.mount('http://github.com/about/', HTTPAdapter())765 order = [766 'http://github.com/about/',767 'http://github.com',768 'http://github',769 'http://git',770 'https://',771 'http://',772 ]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–787why, one step back774 s.mount('http://gittip', HTTPAdapter())775 s.mount('http://gittip.com', HTTPAdapter())776 s.mount('http://gittip.com/about/', HTTPAdapter())777 order = [778 'http://github.com/about/',779 'http://gittip.com/about/',780 'http://github.com',781 'http://gittip.com',782 'http://github',783 'http://gittip',784 'http://git',785 'https://',786 'http://',787 ]Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 788why, one step back788 assert order == list(s.adapters)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 789–791why, one step back789 s2 = requests.Session()790 s2.adapters = {'http://': HTTPAdapter()}791 s2.mount('https://', HTTPAdapter())Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 792–793why, one step back792 assert 'http://' in s2.adapters793 assert 'https://' in s2.adaptersMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption8b55a25
lines 794–807why, one step back794795 def test_header_remove_is_case_insensitive(self):796 # From issue #1321797 s = requests.Session()798 s.headers['foo'] = 'bar'799 r = s.get(httpbin('get'), headers={'FOO': None})800 assert 'foo' not in r.request.headers801802 def test_params_are_merged_case_sensitive(self):803 s = requests.Session()804 s.params['foo'] = 'bar'805 r = s.get(httpbin('get'), params={'FOO': 'bar'})806 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}807Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 808–815why, one step back808809 def test_long_authinfo_in_url(self):810 url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(811 'E8A3BE87-9E3F-4620-8858-95478E385B5B',812 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',813 'exactly-------------sixty-----------three------------characters',814 )815 r = requests.Request('GET', url).prepare()Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 816why, one step back816 assert r.url == urlmerge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 817–824why, one step back817818 def test_header_keys_are_native(self):819 headers = {u'unicode': 'blah', 'byte'.encode('ascii'): 'blah'}820 r = requests.Request('GET', httpbin('get'), headers=headers)821 p = r.prepare()822823 # This is testing that they are builtin strings. A bit weird, but there824 # we go.Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 825–826why, one step back825 assert 'unicode' in p.headers.keys()826 assert 'byte' in p.headers.keys()merge 2.0 insto masterKenneth Reitzbefore adoption54ad646
lines 827–833why, one step back827828 def test_can_send_nonstring_objects_with_files(self):829 data = {'a': 0.0}830 files = {'b': 'foo'}831 r = requests.Request('POST', httpbin('post'), data=data, files=files)832 p = r.prepare()833Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 834why, one step back834 assert 'multipart/form-data' in p.headers['Content-Type']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 835why, one step back835Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7b5c11f
lines 836–841why, one step back836 def test_autoset_header_values_are_native(self):837 data = 'this is a string'838 length = '16'839 req = requests.Request('POST', httpbin('post'), data=data)840 p = req.prepare()841Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 842why, one step back842 assert p.headers['Content-Length'] == lengthMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7b5c11f
line 843why, one step back843Merge pull request #1717 from jvantuyl/masterKenneth Reitzbefore adoptionbcb10af
lines 844–855why, one step back844 def test_oddball_schemes_dont_check_URLs(self):845 test_urls = (846 'data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==',847 'file:///etc/passwd',848 'magnet:?xt=urn:btih:be08f00302bc2d1d3cfa3af02024fa647a271431',849 )850 for test_url in test_urls:851 req = requests.Request('GET', test_url)852 preq = req.prepare()853 assert test_url == preq.url854855Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 856–859why, one step back856class TestContentEncodingDetection(unittest.TestCase):857858 def test_none(self):859 encodings = requests.utils.get_encodings_from_content('')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 860why, one step back860 assert not len(encodings)Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 861–865why, one step back861862 def test_html_charset(self):863 """HTML5 meta charset attribute"""864 content = '<meta charset="UTF-8">'865 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 866–867why, one step back866 assert len(encodings) == 1867 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 868–872why, one step back868869 def test_html4_pragma(self):870 """HTML4 pragma directive"""871 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">'872 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 873–874why, one step back873 assert len(encodings) == 1874 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 875–879why, one step back875876 def test_xhtml_pragma(self):877 """XHTML 1.x served with text/html MIME type"""878 content = '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />'879 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 880–881why, one step back880 assert len(encodings) == 1881 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 882–886why, one step back882883 def test_xml(self):884 """XHTML 1.x served as XML"""885 content = '<?xml version="1.0" encoding="UTF-8"?>'886 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 887–888why, one step back887 assert len(encodings) == 1888 assert encodings[0] == 'UTF-8'Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 889–896why, one step back889890 def test_precedence(self):891 content = '''892 <?xml version="1.0" encoding="XML"?>893 <meta charset="HTML5">894 <meta http-equiv="Content-type" content="text/html;charset=HTML4" />895 '''.strip()896 encodings = requests.utils.get_encodings_from_content(content)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 897why, one step back897 assert encodings == ['HTML5', 'HTML4', 'XML']Merge pull request #1575 from jparise/content-encodingKenneth Reitzbefore adoption6c73d86
lines 898–899why, one step back898899Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 900–903why, one step back900class TestCaseInsensitiveDict(unittest.TestCase):901902 def test_mapping_init(self):903 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 904–906why, one step back904 assert len(cid) == 2905 assert 'foo' in cid906 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 907–909why, one step back907908 def test_iterable_init(self):909 cid = CaseInsensitiveDict([('Foo', 'foo'), ('BAr', 'bar')])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 910–912why, one step back910 assert len(cid) == 2911 assert 'foo' in cid912 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 913–915why, one step back913914 def test_kwargs_init(self):915 cid = CaseInsensitiveDict(FOO='foo', BAr='bar')Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 916–918why, one step back916 assert len(cid) == 2917 assert 'foo' in cid918 assert 'bar' in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 919–922why, one step back919920 def test_docstring_example(self):921 cid = CaseInsensitiveDict()922 cid['Accept'] = 'application/json'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 923–924why, one step back923 assert cid['aCCEPT'] == 'application/json'924 assert list(cid) == ['Accept']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 925–928why, one step back925926 def test_len(self):927 cid = CaseInsensitiveDict({'a': 'a', 'b': 'b'})928 cid['A'] = 'a'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 929why, one step back929 assert len(cid) == 2Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 930–932why, one step back930931 def test_getitem(self):932 cid = CaseInsensitiveDict({'Spam': 'blueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 933–934why, one step back933 assert cid['spam'] == 'blueval'934 assert cid['SPAM'] == 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 935–942why, one step back935936 def test_fixes_649(self):937 """__setitem__ should behave case-insensitively."""938 cid = CaseInsensitiveDict()939 cid['spam'] = 'oneval'940 cid['Spam'] = 'twoval'941 cid['sPAM'] = 'redval'942 cid['SPAM'] = 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 943–945why, one step back943 assert cid['spam'] == 'blueval'944 assert cid['SPAM'] == 'blueval'945 assert list(cid.keys()) == ['SPAM']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 946–950why, one step back946947 def test_delitem(self):948 cid = CaseInsensitiveDict()949 cid['Spam'] = 'someval'950 del cid['sPam']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 951–952why, one step back951 assert 'spam' not in cid952 assert len(cid) == 0Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 953–956why, one step back953954 def test_contains(self):955 cid = CaseInsensitiveDict()956 cid['Spam'] = 'someval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 957–961why, one step back957 assert 'Spam' in cid958 assert 'spam' in cid959 assert 'SPAM' in cid960 assert 'sPam' in cid961 assert 'notspam' not in cidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 962–966why, one step back962963 def test_get(self):964 cid = CaseInsensitiveDict()965 cid['spam'] = 'oneval'966 cid['SPAM'] = 'blueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 967–970why, one step back967 assert cid.get('spam') == 'blueval'968 assert cid.get('SPAM') == 'blueval'969 assert cid.get('sPam') == 'blueval'970 assert cid.get('notspam', 'default') == 'default'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 971–975why, one step back971972 def test_update(self):973 cid = CaseInsensitiveDict()974 cid['spam'] = 'blueval'975 cid.update({'sPam': 'notblueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 976why, one step back976 assert cid['spam'] == 'notblueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 977–978why, one step back977 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})978 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 979–981why, one step back979 assert len(cid) == 2980 assert cid['foo'] == 'anotherfoo'981 assert cid['bar'] == 'anotherbar'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 982–985why, one step back982983 def test_update_retains_unchanged(self):984 cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})985 cid.update({'foo': 'newfoo'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 986why, one step back986 assert cid['bar'] == 'bar'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 987–990why, one step back987988 def test_iter(self):989 cid = CaseInsensitiveDict({'Spam': 'spam', 'Eggs': 'eggs'})990 keys = frozenset(['Spam', 'Eggs'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 991why, one step back991 assert frozenset(iter(cid)) == keysMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 992–995why, one step back992993 def test_equality(self):994 cid = CaseInsensitiveDict({'SPAM': 'blueval', 'Eggs': 'redval'})995 othercid = CaseInsensitiveDict({'spam': 'blueval', 'eggs': 'redval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 996why, one step back996 assert cid == othercidMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
line 997why, one step back997 del othercid['spam']Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 998–999why, one step back998 assert cid != othercid999 assert cid == {'spam': 'blueval', 'eggs': 'redval'}Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1000–1002why, one step back10001001 def test_setdefault(self):1002 cid = CaseInsensitiveDict({'Spam': 'blueval'})Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1003–1004why, one step back1003 assert cid.setdefault('spam', 'notblueval') == 'blueval'1004 assert cid.setdefault('notspam', 'notblueval') == 'notblueval'Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1005–1012why, one step back10051006 def test_lower_items(self):1007 cid = CaseInsensitiveDict({1008 'Accept': 'application/json',1009 'user-Agent': 'requests',1010 })1011 keyset = frozenset(lowerkey for lowerkey, v in cid.lower_items())1012 lowerkeyset = frozenset(['accept', 'user-agent'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1013why, one step back1013 assert keyset == lowerkeysetMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1014–1020why, one step back10141015 def test_preserve_key_case(self):1016 cid = CaseInsensitiveDict({1017 'Accept': 'application/json',1018 'user-Agent': 'requests',1019 })1020 keyset = frozenset(['Accept', 'user-Agent'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1021–1023why, one step back1021 assert frozenset(i[0] for i in cid.items()) == keyset1022 assert frozenset(cid.keys()) == keyset1023 assert frozenset(cid) == keysetMerge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption7430a49
lines 1024–1032why, one step back10241025 def test_preserve_last_key_case(self):1026 cid = CaseInsensitiveDict({1027 'Accept': 'application/json',1028 'user-Agent': 'requests',1029 })1030 cid.update({'ACCEPT': 'application/json'})1031 cid['USER-AGENT'] = 'requests'1032 keyset = frozenset(['ACCEPT', 'USER-AGENT'])Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1033–1035why, one step back1033 assert frozenset(i[0] for i in cid.items()) == keyset1034 assert frozenset(cid.keys()) == keyset1035 assert frozenset(cid) == keysetMerge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 1036why, one step back1036Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
lines 1037–1045why, one step back10371038class UtilsTestCase(unittest.TestCase):10391040 def test_super_len_io_streams(self):1041 """ Ensures that we properly deal with different kinds of IO streams. """1042 # uses StringIO or io.StringIO (see import above)1043 from io import BytesIO1044 from requests.utils import super_len1045Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1046–1047why, one step back1046 assert super_len(StringIO.StringIO()) == 01047 assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 29Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption011f6da
line 1048why, one step back1048Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
lines 1049–1050why, one step back1049 assert super_len(BytesIO()) == 01050 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 1051–1056why, one step back10511052 try:1053 import cStringIO1054 except ImportError:1055 pass1056 else:Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoptiona9839dc
line 1057why, one step back1057 assert super_len(cStringIO.StringIO('but some how, some way...')) == 25Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
lines 1058–1097why, one step back10581059 def test_get_environ_proxies_ip_ranges(self):1060 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1061 from requests.utils import get_environ_proxies1062 os.environ['no_proxy'] = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"1063 assert get_environ_proxies('http://192.168.0.1:5000/') == {}1064 assert get_environ_proxies('http://192.168.0.1/') == {}1065 assert get_environ_proxies('http://172.16.1.1/') == {}1066 assert get_environ_proxies('http://172.16.1.1:5000/') == {}1067 assert get_environ_proxies('http://192.168.1.1:5000/') != {}1068 assert get_environ_proxies('http://192.168.1.1/') != {}10691070 def test_get_environ_proxies(self):1071 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1072 from requests.utils import get_environ_proxies1073 os.environ['no_proxy'] = "127.0.0.1,localhost.localdomain,192.168.0.0/24,172.16.1.1"1074 assert get_environ_proxies('http://localhost.localdomain:5000/v1.0/') == {}1075 assert get_environ_proxies('http://www.requests.com/') != {}10761077 def test_is_ipv4_address(self):1078 from requests.utils import is_ipv4_address1079 assert is_ipv4_address('8.8.8.8')1080 assert not is_ipv4_address('8.8.8.8.8')1081 assert not is_ipv4_address('localhost.localdomain')10821083 def test_is_valid_cidr(self):1084 from requests.utils import is_valid_cidr1085 assert not is_valid_cidr('8.8.8.8')1086 assert is_valid_cidr('192.168.1.0/24')10871088 def test_dotted_netmask(self):1089 from requests.utils import dotted_netmask1090 assert dotted_netmask(8) == '255.0.0.0'1091 assert dotted_netmask(24) == '255.255.255.0'1092 assert dotted_netmask(25) == '255.255.255.128'10931094 def test_address_in_network(self):1095 from requests.utils import address_in_network1096 assert address_in_network('192.168.1.1', '192.168.1.0/24')1097 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
lines 1098–1156why, one step back1098109911001101class TestMorselToCookieExpires(unittest.TestCase):11021103 """Tests for morsel_to_cookie when morsel contains expires."""11041105 def test_expires_valid_str(self):1106 """Test case where we convert expires from string time."""11071108 morsel = Morsel()1109 morsel['expires'] = 'Thu, 01-Jan-1970 00:00:01 GMT'1110 cookie = morsel_to_cookie(morsel)1111 assert cookie.expires == 111121113 def test_expires_invalid_int(self):1114 """Test case where an invalid type is passed for expires."""11151116 morsel = Morsel()1117 morsel['expires'] = 1001118 with pytest.raises(TypeError):1119 morsel_to_cookie(morsel)11201121 def test_expires_invalid_str(self):1122 """Test case where an invalid string is input."""11231124 morsel = Morsel()1125 morsel['expires'] = 'woops'1126 with pytest.raises(ValueError):1127 morsel_to_cookie(morsel)11281129 def test_expires_none(self):1130 """Test case where expires is None."""11311132 morsel = Morsel()1133 morsel['expires'] = None1134 cookie = morsel_to_cookie(morsel)1135 assert cookie.expires is None113611371138class TestMorselToCookieMaxAge(unittest.TestCase):11391140 """Tests for morsel_to_cookie when morsel contains max-age."""11411142 def test_max_age_valid_int(self):1143 """Test case where a valid max age in seconds is passed."""11441145 morsel = Morsel()1146 morsel['max-age'] = 601147 cookie = morsel_to_cookie(morsel)1148 assert isinstance(cookie.expires, int)11491150 def test_max_age_invalid_str(self):1151 """Test case where a invalid max age is passed."""11521153 morsel = Morsel()1154 morsel['max-age'] = 'woops'1155 with pytest.raises(TypeError):1156 morsel_to_cookie(morsel)Merge remote-tracking branch 'origin/master'Kenneth Reitzbefore adoption57c4684
line 1157why, one step back1157Merge branch 'httperror_init' of git://github.com/dmedvinsky/requestsKenneth Reitzbefore adoptionc0d4b23
line 1158why, one step back1158Merge pull request #1161 from sigmavirus24/fix1159Kenneth Reitzbefore adoptionf2be5fa
lines 1159–1160why, one step back1159if __name__ == '__main__':1160 unittest.main()