syntax changes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent 18b26d2 · Browse files · 2 files·+39 added−63 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+39 added−63 removed
- tests:+39 added−63 removed
Provenance
- Commit
bbadf47- Tree
637eb7c- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent
18b26d2
2 files changed+39 added−63 removed
modified:tests/test_requests.py+27 added-40 removed
30 unmodified lines31 from .compat import StringIO, u32 33 # Requests to this URL should always fail with a connection timeout (nothing34 # listening on that port)35-TARPIT = "http://10.255.255.1"35+TARPIT = 'http://10.255.255.1'36 37 38 class TestRequests:39 7 unmodified lines47 requests.put48 requests.patch49 requests.post50 51- @pytest.mark.parametrize('exception, url',52- (51+ @pytest.mark.parametrize(52+ 'exception, url', (53 (MissingSchema, 'hiwpefhipowhefopw'),54 (InvalidSchema, 'localhost:3128'),55 (InvalidSchema, 'localhost.localdomain:3128/'),56 (InvalidSchema, '10.122.1.1:3128/'),57 (InvalidURL, 'http://'),58- )59- )58+ ))59 def test_invalid_url(self, exception, url):60 with pytest.raises(exception):61 requests.get(url)62 23 unmodified lines86 request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()87 88 assert request.path_url == '/get/test%20case'89 91- @pytest.mark.parametrize('url, expected',92- (90+ @pytest.mark.parametrize(91+ 'url, expected', (92 ('http://example.com/path#fragment', 'http://example.com/path?a=b#fragment'),93 ('http://example.com/path?key=value#fragment', 'http://example.com/path?key=value&a=b#fragment')95- )96- )94+ ))95 def test_params_are_added_before_fragment(self, url, expected):96 request = requests.Request('GET', url, params={"a": "b"}).prepare()97 assert request.url == expected98 174 unmodified lines273 274 @pytest.mark.parametrize('key', ('User-agent', 'user-agent'))275 def test_user_agent_transfers(self, httpbin, key):276 279- heads = {280- key: 'Mozilla/5.0 (github.com/kennethreitz/requests)'281- }277+ heads = {key: 'Mozilla/5.0 (github.com/kennethreitz/requests)'}278 279 r = requests.get(httpbin('user-agent'), headers=heads)280 assert heads[key] in r.text281 27 unmodified lines309 # Connecting to an invalid port should raise a ConnectionError310 ('http://localhost:1', ConnectionError),311 # Inputing a URL that cannot be parsed should raise an InvalidURL error312 ('http://fe80::5054:ff:fe5a:fc0', InvalidURL)317- )318- )313+ ))314 def test_errors(self, url, exception):315 with pytest.raises(exception):316 requests.get(url, timeout=1)317 156 unmodified lines474 r = requests.get(httpbin('gzip'))475 r.content.decode('ascii')476 477 @pytest.mark.parametrize(483- 'url, params',484- (478+ 'url, params', (479 ('/get', {'foo': 'føø'}),480 ('/get', {'føø': 'føø'}),481 ('/get', {'føø': 'føø'}),482 ('/get', {'foo': 'foo'}),483 ('ø', {'foo': 'foo'}),490- )491- )484+ ))485 def test_unicode_get(self, httpbin, url, params):486 requests.get(httpbin(url), params=params)487 488 def test_unicode_header_name(self, httpbin):23 unmodified lines512 {'stuff': u('ëlïxr')},513 {'stuff': u('ëlïxr').encode('utf-8')},514 {'stuff': 'elixr'},515 {'stuff': 'elixr'.encode('utf-8')},523- )524- )516+ ))517 def test_unicode_multipart_post(self, httpbin, data):518 r = requests.post(httpbin('post'),519 data=data,520 files={'file': ('test_requests.py', open(__file__, 'rb'))})521 assert r.status_code == 200522 523 def test_unicode_multipart_post_fieldnames(self, httpbin):524 filename = os.path.splitext(__file__)[0] + '.py'533- r = requests.Request(method='POST',534- url=httpbin('post'),535- data={'stuff'.encode('utf-8'): 'elixr'},536- files={'file': ('test_requests.py',537- open(filename, 'rb'))})525+ r = requests.Request(526+ method='POST', url=httpbin('post'),527+ data={'stuff'.encode('utf-8'): 'elixr'},528+ files={'file': ('test_requests.py', open(filename, 'rb'))})529 prep = r.prepare()530 assert b'name="stuff"' in prep.body531 assert b'name="b\'stuff\'"' not in prep.body532 5 unmodified lines538 539 def test_unicode_method_name_with_request_object(self, httpbin):540 files = {'file': open(__file__, 'rb')}541 s = requests.Session()551- req = requests.Request(u("POST"), httpbin('post'), files=files)542+ req = requests.Request(u('POST'), httpbin('post'), files=files)543 prep = s.prepare_request(req)544 assert isinstance(prep.method, builtin_str)554- assert prep.method == "POST"545+ assert prep.method == 'POST'546 547 resp = s.send(prep)548 assert resp.status_code == 200549 550 def test_custom_content_type(self, httpbin):551 r = requests.post(552 httpbin('post'),553 data={'stuff': json.dumps({'a': 123})},554+ files={563- files={'file1': ('test_requests.py', open(__file__, 'rb')),564- 'file2': ('test_requests', open(__file__, 'rb'),565- 'text/py-content-type')})555+ 'file1': ('test_requests.py', open(__file__, 'rb')),556+ 'file2': ('test_requests', open(__file__, 'rb'),557+ 'text/py-content-type')})558 assert r.status_code == 200559 assert b"text/py-content-type" in r.request.body560 561 def test_hook_receives_request_arguments(self, httpbin):510 unmodified lines1072 'cid', (1073 CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'}),1074 CaseInsensitiveDict([('Foo', 'foo'), ('BAr', 'bar')]),1075 CaseInsensitiveDict(FOO='foo', BAr='bar'),1084- )1085- )1076+ ))1077 def test_init(self, cid):1078 assert len(cid) == 21079 assert 'foo' in cid1080 assert 'bar' in cid141 unmodified lines1222 @pytest.mark.parametrize(1223 'value, exception', (1224 (100, TypeError),1225 ('woops', ValueError),1235- )1236- )1226+ ))1227 def test_expires_invalid_int(self, value, exception):1228 """Test case where an invalid type is passed for expires."""1229 morsel = Morsel()1230 morsel['expires'] = value41 unmodified lines1272 @pytest.mark.parametrize(1273 'timeout, error_text', (1274 ((3, 4, 5), '(connect, read)'),1275 ('foo', 'must be an int or float'),1286- )1287- )1276+ ))1277 def test_invalid_timeout(self, httpbin, timeout, error_text):1278 with pytest.raises(ValueError) as e:1279 requests.get(httpbin('get'), timeout=timeout)1280 assert error_text in str(e)98 unmodified lines1379 'data', (1380 (('a', 'b'), ('c', 'd')),1381 (('c', 'd'), ('a', 'b')),1382 (('a', 'b'), ('c', 'd'), ('e', 'f')),1394- )1395-)1383+ ))1384 def test_data_argument_accepts_tuples(data):1385 """Ensure that the data argument will accept tuples of strings1386 and properly encode them.1387 """26 unmodified lines1414 {1415 'method': 'GET',1416 'url': u('http://www.example.com/üniçø∂é')1417 },1430- )1431-)1418+ ))1419 def test_prepared_copy(kwargs):1420 p = PreparedRequest()1421 if kwargs:1422 p.prepare(**kwargs)32 unmodified linesmodified:tests/test_utils.py+12 added-23 removed
18 unmodified lines19 @pytest.mark.parametrize(20 'stream, value', (21 (StringIO.StringIO, 'Test'),22 (BytesIO, b'Test'),23- pytest.mark.skipif('cStringIO is None')(24- (cStringIO, 'Test')25- ),23+ pytest.mark.skipif('cStringIO is None')((cStringIO, 'Test')),24 ))25 def test_io_streams(self, stream, value):28- """ Ensures that we properly deal with different kinds of IO streams. """26+ """Ensures that we properly deal with different kinds of IO streams."""27 assert super_len(stream()) == 028 assert super_len(stream(value)) == 429 30 def test_super_len_correctly_calculates_len_of_partially_read_file(self):4 unmodified lines35 36 37 class TestGetEnvironProxies:38 """Ensures that IP addresses are correctly matches with ranges41- in no_proxy variable."""39+ in no_proxy variable."""40 41 @pytest.yield_fixture(scope='class', autouse=True, params=['no_proxy', 'NO_PROXY'])42 def no_proxy(self, request):43 os.environ[request.param] = '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1'6 unmodified lines50 'http://192.168.0.1/',51 'http://172.16.1.1/',52 'http://172.16.1.1:5000/',53 'http://localhost.localdomain:5000/v1.0/',56- )57- )54+ ))55 def test_bypass(self, url):56 assert get_environ_proxies(url) == {}57 58 @pytest.mark.parametrize(59 'url', (60 'http://192.168.1.1:5000/',61 'http://192.168.1.1/',62 'http://www.requests.com/',66- )67- )63+ ))64 def test_not_bypass(self, url):65 assert get_environ_proxies(url) != {}66 67 18 unmodified lines86 '192.168.1.0/a',87 '192.168.1.0/128',88 '192.168.1.0/-1',89 '192.168.1.999/24',94- )95- )90+ ))91 def test_invalid(self, value):92 assert not is_valid_cidr(value)93 94 17 unmodified lines112 @pytest.mark.parametrize(113 'value, expected_type', (114 (b'value', compat.bytes),115 (b'value'.decode('utf-8'), compat.str)121- )122- )116+ ))117 def test_guess_filename_valid(self, value, expected_type):118 obj = type('Fake', (object,), {'name': value})()119 result = guess_filename(obj)120 assert result == value15 unmodified lines136 # XHTML 1.x served with text/html MIME type137 '<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />',138 # XHTML 1.x served as XML139 '<?xml version="1.0" encoding="UTF-8"?>',146- )147- )140+ ))141 def test_pragmas(self, content):142 encodings = get_encodings_from_content(content)143 assert len(encodings) == 1144 assert encodings[0] == 'UTF-8'38 unmodified lines183 (184 'http://user:pass%23pass@complex.url.com/path?query=yes',185 ('user', 'pass#pass')186 ),194- )195-)187+ ))188 def test_get_auth_from_url(url, auth):189 assert get_auth_from_url(url) == auth190 191 8 unmodified lines200 # Ensure we handle unquoted percent signs in redirects201 'http://example.com/fiz?buz=%ppicture',202 'http://example.com/fiz?buz=%25ppicture',203 ),212- )213-)204+ ))205 def test_requote_uri_with_unquoted_percents(uri, expected):206 """See: https://github.com/kennethreitz/requests/issues/2356207 """208 assert requote_uri(uri) == expected3 unmodified lines212 'mask, expected', (213 (8, '255.0.0.0'),214 (24, '255.255.255.0'),215 (25, '255.255.255.128'),225- )226-)216+ ))217 def test_dotted_netmask(mask, expected):218 assert dotted_netmask(mask) == expected219 220 1 unmodified line222 'url, expected', (223 ('hTTp://u:p@Some.Host/path', 'http://some.host.proxy'),224 ('hTTp://u:p@Other.Host/path', 'http://http.proxy'),225 ('hTTps://Other.Host', None),236- )237-)226+ ))227 def test_select_proxies(url, expected):228 """Make sure we can select per-host proxies correctly."""229 proxies = {'http': 'http://http.proxy',230 'http://some.host': 'http://some.host.proxy'}1 unmodified line