Bump dependencies

This commit is contained in:
François Voron
2020-10-14 14:11:51 +02:00
parent e18be91f06
commit ad56933836
11 changed files with 230 additions and 196 deletions

View File

@ -1,5 +1,5 @@
import asyncio
from typing import List, Optional
from typing import AsyncGenerator, List, Optional
import httpx
import pytest
@ -257,12 +257,12 @@ def mock_authentication():
@pytest.fixture
def get_test_client():
async def _get_test_client(app: ASGIApp) -> httpx.AsyncClient:
async def _get_test_client(app: ASGIApp) -> AsyncGenerator[httpx.AsyncClient, None]:
async with LifespanManager(app):
async with httpx.AsyncClient(
app=app, base_url="http://app.io"
) as test_client:
return test_client
yield test_client
return _get_test_client
@ -272,7 +272,7 @@ def get_test_client():
def get_test_auth_client(mock_user_db, get_test_client):
async def _get_test_auth_client(
backends: List[BaseAuthentication],
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
app = FastAPI()
authenticator = Authenticator(backends, mock_user_db)
@ -292,7 +292,8 @@ def get_test_auth_client(mock_user_db, get_test_client):
):
return user
return await get_test_client(app)
async for client in get_test_client(app):
yield client
return _get_test_auth_client

View File

@ -43,21 +43,24 @@ class BackendUser(BaseAuthentication[str]):
@pytest.mark.authentication
@pytest.mark.asyncio
async def test_authenticator(get_test_auth_client, user):
client = await get_test_auth_client([BackendNone(), BackendUser(user)])
response = await client.get("/test-current-user")
assert response.status_code == status.HTTP_200_OK
async for client in get_test_auth_client([BackendNone(), BackendUser(user)]):
response = await client.get("/test-current-user")
assert response.status_code == status.HTTP_200_OK
@pytest.mark.authentication
@pytest.mark.asyncio
async def test_authenticator_none(get_test_auth_client):
client = await get_test_auth_client([BackendNone(), BackendNone(name="none-bis")])
response = await client.get("/test-current-user")
assert response.status_code == status.HTTP_401_UNAUTHORIZED
async for client in get_test_auth_client(
[BackendNone(), BackendNone(name="none-bis")]
):
response = await client.get("/test-current-user")
assert response.status_code == status.HTTP_401_UNAUTHORIZED
@pytest.mark.authentication
@pytest.mark.asyncio
async def test_authenticators_with_same_name(get_test_auth_client):
with pytest.raises(DuplicateBackendNamesError):
await get_test_auth_client([BackendNone(), BackendNone()])
async for client in get_test_auth_client([BackendNone(), BackendNone()]):
pass

View File

@ -1,3 +1,5 @@
from typing import AsyncGenerator
import pytest
import httpx
from fastapi import Depends, FastAPI, status
@ -10,7 +12,7 @@ from tests.conftest import User, UserCreate, UserUpdate, UserDB
@pytest.mark.asyncio
async def test_app_client(
mock_user_db, mock_authentication, oauth_client, get_test_client
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
fastapi_users = FastAPIUsers(
mock_user_db,
[mock_authentication],
@ -55,7 +57,8 @@ async def test_app_client(
):
return user
return await get_test_client(app)
async for client in get_test_client(app):
yield client
@pytest.mark.fastapi_users

View File

@ -1,4 +1,4 @@
from typing import cast, Dict, Any
from typing import AsyncGenerator, cast, Dict, Any
import httpx
import pytest
@ -13,7 +13,7 @@ from tests.conftest import MockAuthentication, UserDB
@pytest.mark.asyncio
async def test_app_client(
mock_user_db, mock_authentication, get_test_client
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
mock_authentication_bis = MockAuthentication(name="mock-bis")
authenticator = Authenticator(
[mock_authentication, mock_authentication_bis], mock_user_db
@ -28,7 +28,8 @@ async def test_app_client(
app.include_router(mock_auth_router, prefix="/mock")
app.include_router(mock_bis_auth_router, prefix="/mock-bis")
return await get_test_client(app)
async for client in get_test_client(app):
yield client
@pytest.mark.router

View File

@ -1,5 +1,5 @@
from unittest.mock import MagicMock
from typing import Dict, Any, cast
from typing import AsyncGenerator, Dict, Any, cast
import asynctest
import httpx
@ -36,7 +36,9 @@ def get_test_app_client(
after_register,
get_test_client,
):
async def _get_test_app_client(redirect_url: str = None) -> httpx.AsyncClient:
async def _get_test_app_client(
redirect_url: str = None,
) -> AsyncGenerator[httpx.AsyncClient, None]:
mock_authentication_bis = MockAuthentication(name="mock-bis")
authenticator = Authenticator(
[mock_authentication, mock_authentication_bis], mock_user_db_oauth
@ -55,7 +57,8 @@ def get_test_app_client(
app = FastAPI()
app.include_router(oauth_router)
return await get_test_client(app)
async for client in get_test_client(app):
yield client
return _get_test_app_client
@ -63,13 +66,15 @@ def get_test_app_client(
@pytest.fixture
@pytest.mark.asyncio
async def test_app_client(get_test_app_client):
return await get_test_app_client()
async for client in get_test_app_client():
yield client
@pytest.fixture
@pytest.mark.asyncio
async def test_app_client_redirect_url(get_test_app_client):
return await get_test_app_client("http://www.tintagel.bt/callback")
async for client in get_test_app_client("http://www.tintagel.bt/callback"):
yield client
@pytest.mark.router

View File

@ -1,4 +1,4 @@
from typing import cast, Dict, Any
from typing import AsyncGenerator, cast, Dict, Any
from unittest.mock import MagicMock
import asynctest
@ -30,7 +30,7 @@ def after_register(request):
@pytest.mark.asyncio
async def test_app_client(
mock_user_db, mock_authentication, after_register, get_test_client
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
register_router = get_register_router(
mock_user_db,
User,
@ -42,7 +42,8 @@ async def test_app_client(
app = FastAPI()
app.include_router(register_router)
return await get_test_client(app)
async for client in get_test_client(app):
yield client
@pytest.mark.router

View File

@ -1,4 +1,4 @@
from typing import cast, Dict, Any
from typing import AsyncGenerator, cast, Dict, Any
from unittest.mock import MagicMock
import asynctest
@ -43,7 +43,7 @@ def after_forgot_password(request):
@pytest.mark.asyncio
async def test_app_client(
mock_user_db, mock_authentication, after_forgot_password, get_test_client
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
reset_router = get_reset_password_router(
mock_user_db, SECRET, LIFETIME, after_forgot_password
)
@ -51,7 +51,8 @@ async def test_app_client(
app = FastAPI()
app.include_router(reset_router)
return await get_test_client(app)
async for client in get_test_client(app):
yield client
@pytest.mark.router

View File

@ -1,4 +1,4 @@
from typing import cast, Dict, Any
from typing import AsyncGenerator, cast, Dict, Any
from unittest.mock import MagicMock
import asynctest
@ -31,7 +31,7 @@ def after_update(request):
@pytest.mark.asyncio
async def test_app_client(
mock_user_db, mock_authentication, after_update, get_test_client
) -> httpx.AsyncClient:
) -> AsyncGenerator[httpx.AsyncClient, None]:
mock_authentication_bis = MockAuthentication(name="mock-bis")
authenticator = Authenticator(
[mock_authentication, mock_authentication_bis], mock_user_db
@ -49,7 +49,8 @@ async def test_app_client(
app = FastAPI()
app.include_router(user_router)
return await get_test_client(app)
async for client in get_test_client(app):
yield client
@pytest.mark.router