Skip to content

Commit 056b045

Browse files
committed
Remove UserDB Pydantic schema
1 parent 923aeb9 commit 056b045

File tree

7 files changed

+14
-31
lines changed

7 files changed

+14
-31
lines changed

fastapi_users/fastapi_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
BaseOAuth2 = Type # type: ignore
2323

2424

25-
class FastAPIUsers(Generic[models.UP, schemas.U, schemas.UC, schemas.UU, schemas.UD]):
25+
class FastAPIUsers(Generic[models.UP, schemas.U, schemas.UC, schemas.UU]):
2626
"""
2727
Main object that ties together the component for users authentication.
2828

fastapi_users/schemas.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,9 @@ class BaseUserUpdate(CreateUpdateDictModel):
4747
is_verified: Optional[bool]
4848

4949

50-
class BaseUserDB(BaseUser):
51-
hashed_password: str
52-
53-
class Config:
54-
orm_mode = True
55-
56-
5750
U = TypeVar("U", bound=BaseUser)
5851
UC = TypeVar("UC", bound=BaseUserCreate)
5952
UU = TypeVar("UU", bound=BaseUserUpdate)
60-
UD = TypeVar("UD", bound=BaseUserDB)
6153

6254

6355
class BaseOAuthAccount(BaseModel):

tests/conftest.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,10 @@ class UserUpdate(schemas.BaseUserUpdate):
8282
first_name: Optional[str]
8383

8484

85-
class UserDB(User, schemas.BaseUserDB):
86-
pass
87-
88-
8985
class UserOAuth(User, schemas.BaseOAuthAccountMixin):
9086
pass
9187

9288

93-
class UserDBOAuth(UserOAuth, UserDB):
94-
pass
95-
96-
9789
class BaseTestUserManager(Generic[models.UP], BaseUserManager[models.UP]):
9890
reset_password_token_secret = "SECRET"
9991
verification_token_secret = "SECRET"

tests/test_authentication_backend.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from fastapi import Response
55

6-
from fastapi_users import models, schemas
6+
from fastapi_users import models
77
from fastapi_users.authentication import (
88
AuthenticationBackend,
99
BearerTransport,
@@ -12,23 +12,23 @@
1212
from fastapi_users.authentication.strategy import StrategyDestroyNotSupportedError
1313
from fastapi_users.authentication.transport.base import Transport
1414
from fastapi_users.manager import BaseUserManager
15-
from tests.conftest import MockStrategy, MockTransport, UserDB
15+
from tests.conftest import MockStrategy, MockTransport, UserModel
1616

1717

1818
class MockTransportLogoutNotSupported(BearerTransport):
1919
pass
2020

2121

22-
class MockStrategyDestroyNotSupported(Strategy, Generic[schemas.UC, schemas.UD]):
22+
class MockStrategyDestroyNotSupported(Strategy, Generic[models.UP]):
2323
async def read_token(
2424
self, token: Optional[str], user_manager: BaseUserManager[models.UP]
25-
) -> Optional[schemas.UD]:
25+
) -> Optional[models.UP]:
2626
return None
2727

28-
async def write_token(self, user: schemas.UD) -> str:
28+
async def write_token(self, user: models.UP) -> str:
2929
return "TOKEN"
3030

31-
async def destroy_token(self, token: str, user: schemas.UD) -> None:
31+
async def destroy_token(self, token: str, user: models.UP) -> None:
3232
raise StrategyDestroyNotSupportedError
3333

3434

@@ -55,7 +55,7 @@ def backend(
5555

5656
@pytest.mark.asyncio
5757
@pytest.mark.authentication
58-
async def test_logout(backend: AuthenticationBackend, user: UserDB):
58+
async def test_logout(backend: AuthenticationBackend, user: UserModel):
5959
strategy = cast(Strategy, backend.get_strategy())
6060
result = await backend.logout(strategy, user, "TOKEN", Response())
6161
assert result is None

tests/test_fastapi_users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from fastapi import Depends, FastAPI, status
66

77
from fastapi_users import FastAPIUsers
8-
from tests.conftest import User, UserCreate, UserDB, UserModel, UserUpdate
8+
from tests.conftest import User, UserCreate, UserModel, UserUpdate
99

1010

1111
@pytest.fixture
@@ -17,7 +17,7 @@ async def test_app_client(
1717
oauth_client,
1818
get_test_client,
1919
) -> AsyncGenerator[httpx.AsyncClient, None]:
20-
fastapi_users = FastAPIUsers[UserModel, User, UserCreate, UserUpdate, UserDB](
20+
fastapi_users = FastAPIUsers[UserModel, User, UserCreate, UserUpdate](
2121
get_user_manager,
2222
[mock_authentication],
2323
User,

tests/test_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from tests.conftest import (
2121
OAuthAccountModel,
2222
UserCreate,
23-
UserDBOAuth,
2423
UserManagerMock,
2524
UserModel,
2625
UserOAuthModel,
@@ -106,7 +105,7 @@ async def test_not_existing_user(
106105
await user_manager_oauth.get_by_oauth_account("service1", "foo")
107106

108107
async def test_existing_user(
109-
self, user_manager_oauth: UserManagerMock[UserModel], user_oauth: UserDBOAuth
108+
self, user_manager_oauth: UserManagerMock[UserModel], user_oauth: UserOAuthModel
110109
):
111110
oauth_account = user_oauth.oauth_accounts[0]
112111
retrieved_user = await user_manager_oauth.get_by_oauth_account(
@@ -192,7 +191,7 @@ async def test_existing_user_with_oauth(
192191
async def test_existing_user_without_oauth(
193192
self,
194193
user_manager_oauth: UserManagerMock[UserOAuthModel],
195-
superuser_oauth: UserDBOAuth,
194+
superuser_oauth: UserOAuthModel,
196195
):
197196
oauth_account = OAuthAccountModel(
198197
oauth_name="service1",

tests/test_openapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from fastapi import FastAPI, status
44

55
from fastapi_users.fastapi_users import FastAPIUsers
6-
from tests.conftest import User, UserCreate, UserDB, UserModel, UserUpdate
6+
from tests.conftest import User, UserCreate, UserModel, UserUpdate
77

88

99
@pytest.fixture
1010
def fastapi_users(get_user_manager, mock_authentication) -> FastAPIUsers:
11-
return FastAPIUsers[UserModel, User, UserCreate, UserUpdate, UserDB](
11+
return FastAPIUsers[UserModel, User, UserCreate, UserUpdate](
1212
get_user_manager, [mock_authentication], User, UserCreate, UserUpdate
1313
)
1414

0 commit comments

Comments
 (0)