mirror of
https://github.com/not-kennethreitz/requests-async.git
synced 2026-06-05 23:10:17 +00:00
Add auth test
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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='
|
||||
Reference in New Issue
Block a user