Skip to content
Myr

various pep-8 cleanups; remove unsused imports; remove unused variables

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jeff Knupp · committed by Jeff Knupp · parent 3ee781b · Browse files · 1 file+71 added−48 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+71 added−48 removed

  • other:+71 added−48 removed

1 file+71 added−48 removed

modified:test_requests.py+71 added-48 removed
17 unmodified lines
18from requests.compat import (19 Morsel, cookielib, getproxies, str, urljoin, urlparse, is_py3, builtin_str)20from requests.cookies import cookiejar_from_dict, morsel_to_cookie21from requests.exceptions import InvalidURL, MissingSchema22from requests.models import PreparedRequest, Response22from requests.models import PreparedRequest23from requests.structures import CaseInsensitiveDict24from requests.sessions import SessionRedirectMixin25from requests.models import PreparedRequest, urlencode25from requests.models import urlencode26from requests.hooks import default_hooks2728try:29 import StringIO
122 unmodified lines
152153 def test_set_cookie_on_301(self):154 s = requests.session()155 url = httpbin('cookies/set?foo=bar')156 r = s.get(url)156 s.get(url)157 assert s.cookies['foo'] == 'bar'158159 def test_cookie_sent_on_redirect(self):160 s = requests.session()
51 unmodified lines
212 assert s.cookies is cj213214 def test_param_cookiejar_works(self):215 cj = cookielib.CookieJar()216 cookiejar_from_dict({'foo' : 'bar'}, cj)216 cookiejar_from_dict({'foo': 'bar'}, cj)217 s = requests.session()218 r = s.get(httpbin('cookies'), cookies=cj)219 # Make sure the cookie was sent220 assert r.json()['cookies']['foo'] == 'bar'
171 unmodified lines
392 post4 = requests.post(url, data='[{"some": "json"}]')393 assert post4.status_code == 200394395 with pytest.raises(ValueError):396 requests.post(url, files = ['bad file data'])396 requests.post(url, files=['bad file data'])397398 def test_POSTBIN_GET_POST_FILES_WITH_DATA(self):399400 url = httpbin('post')
2 unmodified lines
403 post1 = requests.post(url, data={'some': 'data'})404 assert post1.status_code == 200405406 with open('requirements.txt') as f:407 post2 = requests.post(url, data={'some': 'data'}, files={'some': f})407 post2 = requests.post(408 url, data={'some': 'data'}, files={'some': f})409 assert post2.status_code == 200410411 post4 = requests.post(url, data='[{"some": "json"}]')412 assert post4.status_code == 200413414 with pytest.raises(ValueError):414 requests.post(url, files = ['bad file data'])415 requests.post(url, files=['bad file data'])416417 def test_conflicting_post_params(self):418 url = httpbin('post')419 with open('requirements.txt') as f:
24 unmodified lines
444 requests.get(url, params={'foo': 'foo'})445 requests.get(httpbin('ø'), params={'foo': 'foo'})446447 def test_unicode_header_name(self):447 requests.put(httpbin('put'), headers={str('Content-Type'): 'application/octet-stream'}, data='\xff') # compat.str is unicode.448 requests.put(449 httpbin('put'),450 headers={str('Content-Type'): 'application/octet-stream'},451 data='\xff') # compat.str is unicode.452453 def test_pyopenssl_redirect(self):454 requests.get('https://httpbin.org/status/301')455
3 unmodified lines
459 assert r.status_code == 200460 assert r.url == httpbin('get?test=foo&test=baz')461462 def test_different_encodings_dont_break_post(self):463 r = requests.post(459 r = requests.post(httpbin('post'),460 data={'stuff': json.dumps({'a': 123})},461 params={'blah': 'asdf1234'},462 files={'file': ('test_requests.py', open(__file__, 'rb'))})464 httpbin('post'),465 data={'stuff': json.dumps({'a': 123})},466 params={'blah': 'asdf1234'},467 files={'file': ('test_requests.py', open(__file__, 'rb'))})468 assert r.status_code == 200469470 def test_unicode_multipart_post(self):471 r = requests.post(466 r = requests.post(httpbin('post'),467 data={'stuff': u('ëlïxr')},468 files={'file': ('test_requests.py', open(__file__, 'rb'))})472 httpbin('post'),473 data={'stuff': u('ëlïxr')},474 files={'file': ('test_requests.py', open(__file__, 'rb'))})475 assert r.status_code == 200476477 r = requests.post(471 r = requests.post(httpbin('post'),472 data={'stuff': u('ëlïxr').encode('utf-8')},473 files={'file': ('test_requests.py', open(__file__, 'rb'))})478 httpbin('post'),479 data={'stuff': u('ëlïxr').encode('utf-8')},480 files={'file': ('test_requests.py', open(__file__, 'rb'))})481 assert r.status_code == 200482483 r = requests.post(476 r = requests.post(httpbin('post'),477 data={'stuff': 'elixr'},478 files={'file': ('test_requests.py', open(__file__, 'rb'))})484 httpbin('post'),485 data={'stuff': 'elixr'},486 files={'file': ('test_requests.py', open(__file__, 'rb'))})487 assert r.status_code == 200488489 r = requests.post(481 r = requests.post(httpbin('post'),482 data={'stuff': 'elixr'.encode('utf-8')},483 files={'file': ('test_requests.py', open(__file__, 'rb'))})490 httpbin('post'),491 data={'stuff': 'elixr'.encode('utf-8')},492 files={'file': ('test_requests.py', open(__file__, 'rb'))})493 assert r.status_code == 200494495 def test_unicode_multipart_post_fieldnames(self):496 filename = os.path.splitext(__file__)[0] + '.py'
7 unmodified lines
504 assert b'name="b\'stuff\'"' not in prep.body505506 def test_unicode_method_name(self):507 files = {'file': open('test_requests.py', 'rb')}499 r = requests.request(method=u('POST'), url=httpbin('post'), files=files)508 r = requests.request(509 method=u('POST'), url=httpbin('post'), files=files)510 assert r.status_code == 200511512 def test_custom_content_type(self):513 r = requests.post(503 r = requests.post(httpbin('post'),504 data={'stuff': json.dumps({'a': 123})},505 files={'file1': ('test_requests.py', open(__file__, 'rb')),506 'file2': ('test_requests', open(__file__, 'rb'),507 'text/py-content-type')})514 httpbin('post'),515 data={'stuff': json.dumps({'a': 123})},516 files={'file1': ('test_requests.py', open(__file__, 'rb')),517 'file2': ('test_requests', open(__file__, 'rb'),518 'text/py-content-type')})519 assert r.status_code == 200520 assert b"text/py-content-type" in r.request.body521522 def test_hook_receives_request_arguments(self):
50 unmodified lines
573574 prep = s.prepare_request(req)575 resp = s.send(prep)576566 assert resp.json()['headers']['Dummy-Auth-Test'] == 'dummy-auth-test-ok'577 assert resp.json()['headers'][578 'Dummy-Auth-Test'] == 'dummy-auth-test-ok'579580 def test_links(self):581 r = requests.Response()582 r.headers = {
122 unmodified lines
705 assert items == list(items)706 # make sure one can use items multiple times707 assert list(items) == list(items)708697709 def test_time_elapsed_blank(self):710 r = requests.get(httpbin('get'))711 td = r.elapsed712 total_seconds = ((td.microseconds + (td.seconds + td.days * 24 * 3600)
159 unmodified lines
872 s.params['foo'] = 'bar'873 r = s.get(httpbin('get'), params={'FOO': 'bar'})874 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}875865876 def test_long_authinfo_in_url(self):877 url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(878 'E8A3BE87-9E3F-4620-8858-95478E385B5B',879 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',
146 unmodified lines
10261027class TestCaseInsensitiveDict(unittest.TestCase):10281029 def test_mapping_init(self):1020 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1030 cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1031 assert len(cid) == 21032 assert 'foo' in cid1033 assert 'bar' in cid1034
65 unmodified lines
1100 cid = CaseInsensitiveDict()1101 cid['spam'] = 'blueval'1102 cid.update({'sPam': 'notblueval'})1103 assert cid['spam'] == 'notblueval'1094 cid = CaseInsensitiveDict({'Foo': 'foo','BAr': 'bar'})1104 cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})1105 cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})1106 assert len(cid) == 21107 assert cid['foo'] == 'anotherfoo'1108 assert cid['bar'] == 'anotherbar'
61 unmodified lines
1170 from io import BytesIO1171 from requests.utils import super_len11721173 assert super_len(StringIO.StringIO()) == 01174 assert super_len(1164 assert super_len(StringIO.StringIO('with so much drama in the LBC')) == 291175 StringIO.StringIO('with so much drama in the LBC')) == 2911761177 assert super_len(BytesIO()) == 01178 assert super_len(1167 assert super_len(BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 401179 BytesIO(b"it's kinda hard bein' snoop d-o-double-g")) == 4011801181 try:1182 import cStringIO1183 except ImportError:1184 pass1185 else:1174 assert super_len(cStringIO.StringIO('but some how, some way...')) == 251186 assert super_len(1187 cStringIO.StringIO('but some how, some way...')) == 2511881189 def test_get_environ_proxies_ip_ranges(self):1177 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1190 """Ensures that IP addresses are correctly matches with ranges1191 in no_proxy variable."""1192 from requests.utils import get_environ_proxies1193 os.environ['no_proxy'] = "192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1"1194 assert get_environ_proxies('http://192.168.0.1:5000/') == {}1195 assert get_environ_proxies('http://192.168.0.1/') == {}
2 unmodified lines
1198 assert get_environ_proxies('http://192.168.1.1:5000/') != {}1199 assert get_environ_proxies('http://192.168.1.1/') != {}12001201 def test_get_environ_proxies(self):1188 """ Ensures that IP addresses are correctly matches with ranges in no_proxy variable """1202 """Ensures that IP addresses are correctly matches with ranges1203 in no_proxy variable."""1204 from requests.utils import get_environ_proxies1205 os.environ['no_proxy'] = "127.0.0.1,localhost.localdomain,192.168.0.0/24,172.16.1.1"1191 assert get_environ_proxies('http://localhost.localdomain:5000/v1.0/') == {}1206 assert get_environ_proxies(1207 'http://localhost.localdomain:5000/v1.0/') == {}1208 assert get_environ_proxies('http://www.requests.com/') != {}12091210 def test_is_ipv4_address(self):1211 from requests.utils import is_ipv4_address
17 unmodified lines
1229 assert address_in_network('192.168.1.1', '192.168.1.0/24')1230 assert not address_in_network('172.16.0.1', '192.168.1.0/24')12311232 def test_get_auth_from_url(self):1217 """ Ensures that username and password in well-encoded URI as per RFC 3986 are correclty extracted """1233 """Ensures that username and password in well-encoded URI as per1234 RFC 3986 are correclty extracted."""1235 from requests.utils import get_auth_from_url1236 from requests.compat import quote1237 percent_encoding_test_chars = "%!*'();:@&=+$,/?#[] "1238 url_address = "request.com/url.html#test"1222 url = "http://" + quote(percent_encoding_test_chars, '') + ':' + quote(percent_encoding_test_chars, '') + '@' + url_address1239 url = "http://" + quote(1240 percent_encoding_test_chars, '') + ':' + quote(1241 percent_encoding_test_chars, '') + '@' + url_address1242 (username, password) = get_auth_from_url(url)1243 assert username == percent_encoding_test_chars1244 assert password == percent_encoding_test_chars1245
58 unmodified lines
13041305class TestTimeout:1306 def test_stream_timeout(self):1307 try:1289 r = requests.get('https://httpbin.org/delay/10', timeout=5.0)1308 requests.get('https://httpbin.org/delay/10', timeout=5.0)1309 except requests.exceptions.Timeout as e:1310 assert 'Read timed out' in e.args[0].args[0]13111312
58 unmodified lines
13711372@pytest.fixture1373def list_of_tuples():1374 return [1356 (('a', 'b'), ('c', 'd')),1357 (('c', 'd'), ('a', 'b')),1358 (('a', 'b'), ('c', 'd'), ('e', 'f')),1359 ]1375 (('a', 'b'), ('c', 'd')),1376 (('c', 'd'), ('a', 'b')),1377 (('a', 'b'), ('c', 'd'), ('e', 'f')),1378 ]137913801381def test_data_argument_accepts_tuples(list_of_tuples):1382 """
9 unmodified lines
1392 hooks=default_hooks()1393 )1394 assert p.body == urlencode(data)139513961397def assert_copy(p, p_copy):1398 for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):1399 assert getattr(p, attr) == getattr(p_copy, attr)140014011402def test_prepared_request_empty_copy():1403 p = PreparedRequest()1404 assert_copy(p, p.copy())140514061407def test_prepared_request_no_cookies_copy():1408 p = PreparedRequest()1409 p.prepare(1410 method='GET',
2 unmodified lines
1413 hooks=default_hooks()1414 )1415 assert_copy(p, p.copy())141614171418def test_prepared_request_complete_copy():1419 p = PreparedRequest()1420 p.prepare(1421 method='GET',
9 unmodified lines