Added token property to Request object & added test to confirm new functionality.

This commit is contained in:
Sean Parsons
2016-12-25 18:01:26 -05:00
parent d5ad5e46da
commit 8220515e72
2 changed files with 36 additions and 1 deletions

View File

@@ -112,6 +112,29 @@ def test_post_json():
assert response.text == 'OK'
def test_post_token():
app = Sanic('test_post_token')
@app.route('/')
async def handler(request):
return text('OK')
payload = {'test': 'OK'}
# uuid4 generated token.
token = 'a1d895e0-553a-421a-8e22-5ff8ecb48cbf'
headers = {
'content-type': 'application/json',
'Authorization': 'Token {}'.format(token)
}
request, response = sanic_endpoint_test(app, data=json_dumps(payload), headers=headers)
assert request.token == token
assert response.text == 'OK'
def test_post_form_urlencoded():
app = Sanic('test_post_form_urlencoded')