Merge pull request #477 from messense/fix-requests-post-test-cases

Fix test cases for requests post
This commit is contained in:
Eli Uriegas 2017-02-22 20:39:03 -06:00 committed by GitHub
commit 6afac06596

View File

@ -145,14 +145,14 @@ def test_token():
def test_post_json(): def test_post_json():
app = Sanic('test_post_json') app = Sanic('test_post_json')
@app.route('/') @app.route('/', methods=['POST'])
async def handler(request): async def handler(request):
return text('OK') return text('OK')
payload = {'test': 'OK'} payload = {'test': 'OK'}
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
request, response = app.test_client.get( request, response = app.test_client.post(
'/', data=json_dumps(payload), headers=headers) '/', data=json_dumps(payload), headers=headers)
assert request.json.get('test') == 'OK' assert request.json.get('test') == 'OK'
@ -162,14 +162,14 @@ def test_post_json():
def test_post_form_urlencoded(): def test_post_form_urlencoded():
app = Sanic('test_post_form_urlencoded') app = Sanic('test_post_form_urlencoded')
@app.route('/') @app.route('/', methods=['POST'])
async def handler(request): async def handler(request):
return text('OK') return text('OK')
payload = 'test=OK' payload = 'test=OK'
headers = {'content-type': 'application/x-www-form-urlencoded'} headers = {'content-type': 'application/x-www-form-urlencoded'}
request, response = app.test_client.get('/', data=payload, headers=headers) request, response = app.test_client.post('/', data=payload, headers=headers)
assert request.form.get('test') == 'OK' assert request.form.get('test') == 'OK'
@ -177,7 +177,7 @@ def test_post_form_urlencoded():
def test_post_form_multipart_form_data(): def test_post_form_multipart_form_data():
app = Sanic('test_post_form_multipart_form_data') app = Sanic('test_post_form_multipart_form_data')
@app.route('/') @app.route('/', methods=['POST'])
async def handler(request): async def handler(request):
return text('OK') return text('OK')
@ -189,6 +189,6 @@ def test_post_form_multipart_form_data():
headers = {'content-type': 'multipart/form-data; boundary=----sanic'} headers = {'content-type': 'multipart/form-data; boundary=----sanic'}
request, response = app.test_client.get(data=payload, headers=headers) request, response = app.test_client.post(data=payload, headers=headers)
assert request.form.get('test') == 'OK' assert request.form.get('test') == 'OK'