Skip to content

Commit

Permalink
support request tuple data
Browse files Browse the repository at this point in the history
rewrite the TestModels

Ajust the code
  • Loading branch information
Feng23 committed Mar 27, 2014
1 parent 0303e9b commit 24819e8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 1 addition & 3 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,7 @@ def prepare_body(self, data, files):

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:
Expand Down
27 changes: 27 additions & 0 deletions test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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
Expand Down Expand Up @@ -1275,5 +1277,30 @@ def test_requests_are_updated_each_time(self):
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()

0 comments on commit 24819e8

Please sign in to comment.