Skip to content

Commit

Permalink
Merge pull request #143 from kxepal/handle-falsy-data-on-request
Browse files Browse the repository at this point in the history
Pass falsy data to ClientRequest.update_body_from_data handler
  • Loading branch information
kxepal committed Aug 29, 2014
2 parents 4c83197 + efda67c commit d418ca5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ def __init__(self, method, url, *,
'not supported at the same time.')
data = files

if data:
self.update_body_from_data(data)

self.update_body_from_data(data)
self.update_transfer_encoding()
self.update_expect_continue(expect100)

Expand Down Expand Up @@ -355,6 +353,9 @@ def update_auth(self, auth):
self.headers['AUTHORIZATION'] = auth.encode()

def update_body_from_data(self, data):
if not data:
return

if isinstance(data, str):
data = data.encode(self.encoding)

Expand Down
7 changes: 7 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,13 @@ def test_post_data(self):
self.assertEqual('application/x-www-form-urlencoded',
req.headers['CONTENT-TYPE'])

@unittest.mock.patch('aiohttp.client.ClientRequest.update_body_from_data')
def test_pass_falsy_data(self, _):
req = ClientRequest(
'post', 'http://python.org/',
data={}, loop=self.loop)
req.update_body_from_data.assert_called_once_with({})

def test_get_with_data(self):
for meth in ClientRequest.GET_METHODS:
req = ClientRequest(
Expand Down

0 comments on commit d418ca5

Please sign in to comment.