mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-01 01:48:46 +08:00
Remove list endpoint and related methods
This commit is contained in:
@ -155,9 +155,6 @@ def oauth_account3() -> BaseOAuthAccount:
|
||||
@pytest.fixture
|
||||
def mock_user_db(user, inactive_user, superuser) -> BaseUserDatabase:
|
||||
class MockUserDatabase(BaseUserDatabase[UserDB]):
|
||||
async def list(self) -> List[UserDB]:
|
||||
return [user, inactive_user, superuser]
|
||||
|
||||
async def get(self, id: str) -> Optional[UserDB]:
|
||||
if id == user.id:
|
||||
return user
|
||||
@ -193,9 +190,6 @@ def mock_user_db_oauth(
|
||||
user_oauth, inactive_user_oauth, superuser_oauth
|
||||
) -> BaseUserDatabase:
|
||||
class MockUserDatabase(BaseUserDatabase[UserDBOAuth]):
|
||||
async def list(self) -> List[UserDBOAuth]:
|
||||
return [user_oauth, inactive_user_oauth, superuser_oauth]
|
||||
|
||||
async def get(self, id: str) -> Optional[UserDBOAuth]:
|
||||
if id == user_oauth.id:
|
||||
return user_oauth
|
||||
|
||||
@ -18,9 +18,6 @@ def create_oauth2_password_request_form():
|
||||
async def test_not_implemented_methods(user):
|
||||
base_user_db = BaseUserDatabase(UserDB)
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
await base_user_db.list()
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
await base_user_db.get("aaa")
|
||||
|
||||
|
||||
@ -77,12 +77,6 @@ async def test_queries(mongodb_user_db: MongoDBUserDatabase[UserDB]):
|
||||
assert email_user is not None
|
||||
assert email_user.id == user_db.id
|
||||
|
||||
# List
|
||||
users = await mongodb_user_db.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
|
||||
# Exception when inserting existing email
|
||||
with pytest.raises(pymongo.errors.DuplicateKeyError):
|
||||
await mongodb_user_db.create(user)
|
||||
@ -151,13 +145,6 @@ async def test_queries_oauth(
|
||||
assert email_user.id == user_db.id
|
||||
assert len(email_user.oauth_accounts) == 2
|
||||
|
||||
# List
|
||||
users = await mongodb_user_db_oauth.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
assert len(first_user.oauth_accounts) == 2
|
||||
|
||||
# Get by OAuth account
|
||||
oauth_user = await mongodb_user_db_oauth.get_by_oauth_account(
|
||||
oauth_account1.oauth_name, oauth_account1.account_id
|
||||
|
||||
@ -97,12 +97,6 @@ async def test_queries(sqlalchemy_user_db: SQLAlchemyUserDatabase[UserDB]):
|
||||
assert email_user is not None
|
||||
assert email_user.id == user_db.id
|
||||
|
||||
# List
|
||||
users = await sqlalchemy_user_db.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
|
||||
# Exception when inserting existing email
|
||||
with pytest.raises(sqlite3.IntegrityError):
|
||||
await sqlalchemy_user_db.create(user)
|
||||
@ -193,13 +187,6 @@ async def test_queries_oauth(
|
||||
assert email_user.id == user_db.id
|
||||
assert len(email_user.oauth_accounts) == 2
|
||||
|
||||
# List
|
||||
users = await sqlalchemy_user_db_oauth.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
assert len(first_user.oauth_accounts) == 2
|
||||
|
||||
# Get by OAuth account
|
||||
oauth_user = await sqlalchemy_user_db_oauth.get_by_oauth_account(
|
||||
oauth_account1.oauth_name, oauth_account1.account_id
|
||||
|
||||
@ -82,12 +82,6 @@ async def test_queries(tortoise_user_db: TortoiseUserDatabase[UserDB]):
|
||||
assert email_user is not None
|
||||
assert email_user.id == user_db.id
|
||||
|
||||
# List
|
||||
users = await tortoise_user_db.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
|
||||
# Exception when inserting existing email
|
||||
with pytest.raises(IntegrityError):
|
||||
await tortoise_user_db.create(user)
|
||||
@ -161,13 +155,6 @@ async def test_queries_oauth(
|
||||
assert email_user.id == user_db.id
|
||||
assert len(email_user.oauth_accounts) == 2
|
||||
|
||||
# List
|
||||
users = await tortoise_user_db_oauth.list()
|
||||
assert len(users) == 1
|
||||
first_user = users[0]
|
||||
assert first_user.id == user_db.id
|
||||
assert len(first_user.oauth_accounts) == 2
|
||||
|
||||
# Get by OAuth account
|
||||
oauth_user = await tortoise_user_db_oauth.get_by_oauth_account(
|
||||
oauth_account1.oauth_name, oauth_account1.account_id
|
||||
|
||||
@ -93,9 +93,6 @@ class TestRouter:
|
||||
response = await test_app_client.post("/users/reset-password")
|
||||
assert response.status_code != status.HTTP_404_NOT_FOUND
|
||||
|
||||
response = await test_app_client.get("/users")
|
||||
assert response.status_code != status.HTTP_404_NOT_FOUND
|
||||
|
||||
response = await test_app_client.get("/users/aaa")
|
||||
assert response.status_code != status.HTTP_404_NOT_FOUND
|
||||
|
||||
|
||||
@ -500,34 +500,6 @@ class TestUpdateMe:
|
||||
assert isinstance(request, Request)
|
||||
|
||||
|
||||
@pytest.mark.router
|
||||
@pytest.mark.asyncio
|
||||
class TestListUsers:
|
||||
async def test_missing_token(self, test_app_client: httpx.AsyncClient):
|
||||
response = await test_app_client.get("/")
|
||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||
|
||||
async def test_regular_user(self, test_app_client: httpx.AsyncClient, user: UserDB):
|
||||
response = await test_app_client.get(
|
||||
"/", headers={"Authorization": f"Bearer {user.id}"}
|
||||
)
|
||||
assert response.status_code == status.HTTP_403_FORBIDDEN
|
||||
|
||||
async def test_superuser(
|
||||
self, test_app_client: httpx.AsyncClient, superuser: UserDB
|
||||
):
|
||||
response = await test_app_client.get(
|
||||
"/", headers={"Authorization": f"Bearer {superuser.id}"}
|
||||
)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
response_json = response.json()
|
||||
assert len(response_json) == 3
|
||||
for user in response_json:
|
||||
assert "id" in user
|
||||
assert "hashed_password" not in user
|
||||
|
||||
|
||||
@pytest.mark.router
|
||||
@pytest.mark.asyncio
|
||||
class TestGetUser:
|
||||
|
||||
Reference in New Issue
Block a user