From 6d2d9d3afc299e48f6b3ff6a4a9446d6c71f4b38 Mon Sep 17 00:00:00 2001 From: Eshin Kunishima Date: Wed, 19 Oct 2016 16:23:44 +0900 Subject: [PATCH] Added tests for Request.form --- tests/test_requests.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_requests.py b/tests/test_requests.py index 42dc3e8e..290c9b99 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -80,3 +80,38 @@ def test_post_json(): assert request.json.get('test') == 'OK' assert response.text == 'OK' + + +def test_post_form_urlencoded(): + app = Sanic('test_post_form_urlencoded') + + @app.route('/') + async def handler(request): + return text('OK') + + payload = 'test=OK' + headers = {'content-type': 'application/x-www-form-urlencoded'} + + request, response = sanic_endpoint_test(app, data=payload, headers=headers) + + assert request.form.get('test') == 'OK' + + +def test_post_form_multipart_form_data(): + app = Sanic('test_post_form_multipart_form_data') + + @app.route('/') + async def handler(request): + return text('OK') + + payload = '------sanic\r\n' \ + 'Content-Disposition: form-data; name="test"\r\n' \ + '\r\n' \ + 'OK\r\n' \ + '------sanic--\r\n' + + headers = {'content-type': 'multipart/form-data; boundary=----sanic'} + + request, response = sanic_endpoint_test(app, data=payload, headers=headers) + + assert request.form.get('test') == 'OK'