Skip to content
Myr

remove safe_mode tests

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 966672d · Browse files · 1 file+0 added−70 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+0 added−70 removed

  • tests:+0 added−70 removed

1 file+0 added−70 removed

modified:tests/test_requests.py-70 removed
928 unmodified lines
929 ds1 = pickle.loads(pickle.dumps(requests.session()))930 ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=False)))931 self.assertTrue(ds1.prefetch)932 self.assertFalse(ds2.prefetch)933 934 def test_session_connection_error_with_safe_mode(self):935 config = {"safe_mode":True}933937 s = requests.session()938 r = s.get("http://localhost:1/nope", timeout=0.1, config=config)939 self.assertFalse(r.ok)940 self.assertTrue(r.content is None)941942 s2 = requests.session(config=config)943 r2 = s2.get("http://localhost:1/nope", timeout=0.1)944 self.assertFalse(r2.ok)945 self.assertTrue(r2.content is None)946934 def test_connection_error(self):935 try:936 get('http://localhost:1/nope')937 except requests.ConnectionError:938 pass939 else:940 self.fail()941955 def test_connection_error_with_safe_mode(self):956 config = {'safe_mode': True}957 r = get('http://localhost:1/nope', allow_redirects=False, config=config)958 self.assertTrue(r.content is None)959960 # def test_invalid_content(self):961 # # WARNING: if you're using a terrible DNS provider (comcast),962 # # this will fail.963 # try:964 # hah = 'http://somedomainthatclearlydoesntexistg.com'965 # r = get(hah, allow_redirects=False)966 # except requests.ConnectionError:967 # pass # \o/968 # else:969 # assert False970971 # config = {'safe_mode': True}972 # r = get(hah, allow_redirects=False, config=config)973 # assert r.content == None974942 def test_cached_response(self):943944 r1 = get(httpbin('get'), prefetch=False)945 self.assertFalse(r1._content)
52 unmodified lines
998 for chunk_size in range(2, 20):999 self.assertEqual(bytes().join(r.iter_content(chunk_size=chunk_size)), r.content)100010011035 # def test_safe_mode(self):10361037 # safe = requests.session(config=dict(safe_mode=True))10381039 # # Safe mode creates empty responses for failed requests.1040 # # Iterating on these responses should produce empty sequences1041 # r = get('http://0.0.0.0:700/', session=safe)1042 # self.assertEqual(list(r.iter_lines()), [])1043 # assert isinstance(r.error, requests.exceptions.ConnectionError)10441045 # r = get('http://0.0.0.0:789/', session=safe)1046 # self.assertEqual(list(r.iter_content()), [])1047 # assert isinstance(r.error, requests.exceptions.ConnectionError)10481049 # # When not in safe mode, should raise Timeout exception1050 # self.assertRaises(1051 # requests.exceptions.Timeout,1052 # get,1053 # httpbin('stream', '1000'), timeout=0.0001)10541055 # # In safe mode, should return a blank response1056 # r = get(httpbin('stream', '1000'), timeout=0.0001,1057 # config=dict(safe_mode=True))1058 # assert r.content is None1059 # assert isinstance(r.error, requests.exceptions.Timeout)10601002 def test_upload_binary_data(self):10031004 requests.get(httpbin('post'), auth=('a', 'b'), data='\xff')1005
28 unmodified lines
1034 def test_empty_response(self):1035 r = requests.get(httpbin('status', '404'))1036 r.text10371097 def test_max_redirects(self):1098 """Test the max_redirects config variable, normally and under safe_mode."""1099 def unsafe_callable():1100 requests.get(httpbin('redirect', '3'), config=dict(max_redirects=2))1101 self.assertRaises(requests.exceptions.TooManyRedirects, unsafe_callable)11021103 # add safe mode1104 response = requests.get(httpbin('redirect', '3'), config=dict(safe_mode=True, max_redirects=2))1105 self.assertTrue(response.content is None)1106 self.assertTrue(isinstance(response.error, requests.exceptions.TooManyRedirects))11071038 def test_connection_keepalive_and_close(self):1039 """Test that we send 'Connection: close' when keep_alive is disabled."""1040 # keep-alive should be on by default1041 r1 = requests.get(httpbin('get'))
123 unmodified lines