From: Feng Liu Date: Fri, 14 Mar 2014 08:24:25 +0000 (+0800) Subject: support request tuple data X-Git-Tag: v2.3.0~21^2~6^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=24819e8aae62170ed2c8439e400cc16423207660;p=services%2Fpython-requests.git support request tuple data rewrite the TestModels Ajust the code --- diff --git a/requests/models.py b/requests/models.py index e2fa09f..7390d1c 100644 --- a/requests/models.py +++ b/requests/models.py @@ -408,9 +408,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): is_stream = all([ hasattr(data, '__iter__'), - not isinstance(data, basestring), - not isinstance(data, list), - not isinstance(data, dict) + not isinstance(data, (basestring, list, tuple, dict)) ]) try: diff --git a/test_requests.py b/test_requests.py index dbb3806..55e7a3d 100755 --- a/test_requests.py +++ b/test_requests.py @@ -21,6 +21,8 @@ from requests.exceptions import InvalidURL, MissingSchema from requests.models import PreparedRequest, Response from requests.structures import CaseInsensitiveDict from requests.sessions import SessionRedirectMixin +from requests.models import PreparedRequest, urlencode +from requests.hooks import default_hooks try: import StringIO @@ -1275,5 +1277,30 @@ class TestRedirects: assert session.calls[-1] == send_call +@pytest.fixture +def list_of_tuples(): + return [ + (('a', 'b'), ('c', 'd')), + (('c', 'd'), ('a', 'b')), + (('a', 'b'), ('c', 'd'), ('e', 'f')), + ] + + +def test_data_argument_accepts_tuples(list_of_tuples): + """ + Ensure that the data argument will accept tuples of strings + and properly encode them. + """ + for data in list_of_tuples: + p = PreparedRequest() + p.prepare( + method='GET', + url='http://www.example.com', + data=data, + hooks=default_hooks() + ) + assert p.body == urlencode(data) + + if __name__ == '__main__': unittest.main()