Allow copying of PreparedRequests without headers/cookies

This commit is contained in:
David Gouldin
2014-05-30 10:11:53 -07:00
parent 69996114d9
commit 32f600b083
2 changed files with 30 additions and 2 deletions
+2 -2
View File
@@ -309,8 +309,8 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
p = PreparedRequest()
p.method = self.method
p.url = self.url
p.headers = self.headers.copy()
p._cookies = self._cookies.copy()
p.headers = self.headers.copy() if self.headers is not None else None
p._cookies = self._cookies.copy() if self._cookies is not None else None
p.body = self.body
p.hooks = self.hooks
return p
+28
View File
@@ -1369,6 +1369,34 @@ def test_data_argument_accepts_tuples(list_of_tuples):
)
assert p.body == urlencode(data)
def assert_copy(p, p_copy):
for attr in ('method', 'url', 'headers', '_cookies', 'body', 'hooks'):
assert getattr(p, attr) == getattr(p_copy, attr)
def test_prepared_request_empty_copy():
p = PreparedRequest()
assert_copy(p, p.copy())
def test_prepared_request_no_cookies_copy():
p = PreparedRequest()
p.prepare(
method='GET',
url='http://www.example.com',
data='foo=bar',
hooks=default_hooks()
)
assert_copy(p, p.copy())
def test_prepared_request_complete_copy():
p = PreparedRequest()
p.prepare(
method='GET',
url='http://www.example.com',
data='foo=bar',
hooks=default_hooks(),
cookies={'foo': 'bar'}
)
assert_copy(p, p.copy())
if __name__ == '__main__':
unittest.main()