Skip to content

Commit

Permalink
aio-libs#263 functional and unit test for 100-continue
Browse files Browse the repository at this point in the history
  • Loading branch information
tumb1er committed Feb 2, 2015
1 parent 45528b5 commit 290b9c0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import socket
import unittest
import tempfile
from aiohttp import web, request, FormData
from aiohttp import web, request, FormData, CIMultiDict
from aiohttp.multidict import MultiDict


Expand Down Expand Up @@ -95,6 +95,32 @@ def go():

self.loop.run_until_complete(go())

def test_post_100_continue(self):
@asyncio.coroutine
def handler(request):
data = yield from request.post()
self.assertEqual(b'123', data['name'])
return web.Response()

@asyncio.coroutine
def go():
_, _, url = yield from self.create_server('POST', '/', handler)

form = FormData()
form.add_field('name', b'123',
content_transfer_encoding='base64')

resp = yield from request(
'post', url, data=form,
expect100=True, # wait until server returns 100 continue
loop=self.loop)

self.assertEqual(200, resp.status)

self.loop.run_until_complete(
asyncio.wait_for(go(), timeout=0.1, loop=self.loop))


def test_post_json(self):

dct = {'key': 'текст'}
Expand Down
32 changes: 32 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ def test_call_POST_on_GET_request(self):
ret = self.loop.run_until_complete(req.post())
self.assertEqual(CIMultiDict(), ret)

def test_call_POST_for_100_continue(self):
body = b"123"
req = self.make_request(
'POST', '/',
headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''}))
with mock.patch.object(req, "read", side_effect=StopIteration(body)):
ret = self.loop.run_until_complete(req.post())
self.assertEqual(ret, body)
req.transport.write.assert_called_with(b'HTTP/1.1 100 Continue\r\n\r\n')

def test_call_POST_for_100_continue_HTTP10(self):
body = b"123"
req = self.make_request(
'POST', '/',
headers=CIMultiDict({"EXPECT": "100-Continue", 'CONTENT-TYPE': ''}),
version=HttpVersion(1, 0))

with mock.patch.object(req, "read", side_effect=StopIteration(body)):
ret = self.loop.run_until_complete(req.post())
self.assertEqual(ret, body)
self.assertFalse(req.transport.write.call_args_list)

def test_call_POST_for_other_expect(self):
body = b"123"
req = self.make_request(
'POST', '/',
headers=CIMultiDict({"EXPECT": "Other-thing", 'CONTENT-TYPE': ''}))
with mock.patch.object(req, "read", side_effect=StopIteration(body)):
ret = self.loop.run_until_complete(req.post())
self.assertEqual(ret, body)
self.assertFalse(req.transport.write.call_args_list)

def test_call_POST_on_weird_content_type(self):
req = self.make_request(
'POST', '/',
Expand Down

0 comments on commit 290b9c0

Please sign in to comment.