Add auth test

This commit is contained in:
Tom Christie
2019-03-21 13:17:11 +00:00
parent 22e40a330c
commit ce1c9103ca
3 changed files with 18 additions and 1 deletions
-1
View File
@@ -22,7 +22,6 @@ Next set of things to deal with:
* streaming support for uploads and downloads.
* connection pooling.
* async cookie persistence, for on-disk cookie stores.
* make sure authentication works okay (does it use adapters, is the API broken there now?)
* timeouts
## Requirements
+8
View File
@@ -31,6 +31,13 @@ async def echo_form_data(request):
)
async def echo_headers(request):
return JSONResponse(
{
"headers": {key: value for key, value in request.headers.items()}
}
)
async def redirect1(request):
url = request.url_for('redirect2')
return RedirectResponse(url)
@@ -48,6 +55,7 @@ async def redirect3(request):
routes = [
Route("/", echo_request, methods=["GET", "DELETE", "OPTIONS", "POST", "PUT", "PATCH"]),
Route("/echo_form_data", echo_form_data, methods=["POST", "PUT", "PATCH"]),
Route("/echo_headers", echo_headers),
Route("/redirect1", redirect1, name='redirect1'),
Route("/redirect2", redirect2, name='redirect2'),
Route("/redirect3", redirect3, name='redirect3'),
+10
View File
@@ -0,0 +1,10 @@
import requests_async
import pytest
@pytest.mark.asyncio
async def test_auth(server):
url = "http://127.0.0.1:8000/echo_headers"
response = await requests_async.get(url, auth=('tom', 'pass'))
assert response.status_code == 200
assert response.json()['headers']['authorization'] == 'Basic dG9tOnBhc3M='