Skip to content
Myr

Add prepared request pickling tests

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

authored by Keyan Pishdadian · committed by Nate Prewitt · parent d3567aa · Browse files · 1 file+37 added−0 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+37 added−0 removed

  • tests:+37 added−0 removed

1 file+37 added−0 removed

modified:tests/test_requests.py+37 added
1051 unmodified lines
1052 pr = pickle.loads(pickle.dumps(r))1053 assert r.request.url == pr.request.url1054 assert r.request.headers == pr.request.headers10551056 def test_prepared_request_is_pickleable(self):1057 p = requests.Request('GET', httpbin('get')).prepare()10581059 # Verify we can pickle the request.1060 assert pickle.dumps(p)1061 r = pickle.dumps(p)10621063 # Verify we can use the pickled request.1064 assert pickle.loads(r)1065 r = pickle.loads(r)10661067 # Verify we can use the unpickled request.1068 s = requests.Session()1069 r = s.send(r)10701071 assert r.status_code == 20010721073 def test_prepared_request_with_file_is_pickleable(self):1074 data = {'a': 0.0}1075 files = {'b': 'foo'}1076 r = requests.Request('POST', httpbin('post'), data=data, files=files)1077 p = r.prepare()10781079 # Verify we can pickle the request.1080 assert pickle.dumps(p)1081 r = pickle.dumps(p)10821083 # Verify we can use the pickled request.1084 assert pickle.loads(r)1085 r = pickle.loads(r)10861087 # Verify we can use the unpickled request.1088 s = requests.Session()1089 r = s.send(r)10901091 assert r.status_code == 20010921093 def test_cannot_send_unprepared_requests(self, httpbin):1094 r = requests.Request(url=httpbin())1095 with pytest.raises(ValueError):1096 requests.Session().send(r)
765 unmodified lines