66import pytest_asyncio
77from beanie import Document , PydanticObjectId , init_beanie
88from fastapi_users import InvalidID
9- from motor .motor_asyncio import AsyncIOMotorClient , AsyncIOMotorDatabase
109from pydantic import Field
10+ from pymongo import AsyncMongoClient
1111
1212from fastapi_users_db_beanie import (
1313 BaseOAuthAccount ,
@@ -31,7 +31,7 @@ class UserOAuth(User):
3131
3232@pytest_asyncio .fixture
3333async def mongodb_client ():
34- client = AsyncIOMotorClient (
34+ client = AsyncMongoClient (
3535 "mongodb://localhost:27017" ,
3636 serverSelectionTimeoutMS = 10000 ,
3737 uuidRepresentation = "standard" ,
@@ -40,17 +40,17 @@ async def mongodb_client():
4040 try :
4141 await client .server_info ()
4242 yield client
43- client .close ()
43+ await client .close ()
4444 except pymongo .errors .ServerSelectionTimeoutError :
4545 pytest .skip ("MongoDB not available" , allow_module_level = True )
4646 return
4747
4848
4949@pytest_asyncio .fixture
5050async def beanie_user_db (
51- mongodb_client : AsyncIOMotorClient ,
51+ mongodb_client : AsyncMongoClient ,
5252) -> AsyncGenerator [BeanieUserDatabase , None ]:
53- database : AsyncIOMotorDatabase = mongodb_client ["test_database" ]
53+ database = mongodb_client ["test_database" ]
5454 await init_beanie (database = database , document_models = [User ])
5555
5656 yield BeanieUserDatabase (User )
@@ -60,9 +60,9 @@ async def beanie_user_db(
6060
6161@pytest_asyncio .fixture
6262async def beanie_user_db_oauth (
63- mongodb_client : AsyncIOMotorClient ,
63+ mongodb_client : AsyncMongoClient ,
6464) -> AsyncGenerator [BeanieUserDatabase , None ]:
65- database : AsyncIOMotorDatabase = mongodb_client ["test_database" ]
65+ database = mongodb_client ["test_database" ]
6666 await init_beanie (database = database , document_models = [UserOAuth ])
6767
6868 yield BeanieUserDatabase (UserOAuth , OAuthAccount )
0 commit comments