1+ import uuid
12from typing import AsyncGenerator
23
34import pytest
1415from tests .conftest import OAuthAccount , UserDB , UserDBOAuth
1516
1617
18+ safe_uuid = uuid .UUID ("a9089e5d-2642-406d-a7c0-cbc641aca0ec" )
19+
1720async def init_sync_engine (url : str ) -> AsyncGenerator [Engine , None ]:
1821 engine = create_engine (url , connect_args = {"check_same_thread" : False })
1922 SQLModel .metadata .create_all (engine )
@@ -73,6 +76,7 @@ async def sqlmodel_user_db_oauth(request) -> AsyncGenerator[SQLModelUserDatabase
7376@pytest .mark .db
7477async def test_queries (sqlmodel_user_db : SQLModelUserDatabase [UserDB , OAuthAccount ]):
7578 user = UserDB (
79+ id = safe_uuid ,
7680 email = "lancelot@camelot.bt" ,
7781 hashed_password = "guinevere" ,
7882 )
@@ -107,12 +111,12 @@ async def test_queries(sqlmodel_user_db: SQLModelUserDatabase[UserDB, OAuthAccou
107111 # Exception when inserting existing email
108112 with pytest .raises (exc .IntegrityError ):
109113 await sqlmodel_user_db .create (
110- UserDB (email = user_db .email , hashed_password = "guinevere" )
114+ UserDB (id = safe_uuid , email = user_db .email , hashed_password = "guinevere" )
111115 )
112116
113117 # Exception when inserting non-nullable fields
114118 with pytest .raises (exc .IntegrityError ):
115- wrong_user = UserDB (email = "lancelot@camelot.bt" , hashed_password = "aaa" )
119+ wrong_user = UserDB (id = safe_uuid , email = "lancelot@camelot.bt" , hashed_password = "aaa" )
116120 wrong_user .email = None # type: ignore
117121 await sqlmodel_user_db .create (wrong_user )
118122
@@ -137,6 +141,7 @@ async def test_queries_custom_fields(
137141):
138142 """It should output custom fields in query result."""
139143 user = UserDB (
144+ id = safe_uuid ,
140145 email = "lancelot@camelot.bt" ,
141146 hashed_password = "guinevere" ,
142147 first_name = "Lancelot" ,
@@ -157,6 +162,7 @@ async def test_queries_oauth(
157162 oauth_account2 ,
158163):
159164 user = UserDBOAuth (
165+ id = safe_uuid ,
160166 email = "lancelot@camelot.bt" ,
161167 hashed_password = "guinevere" ,
162168 oauth_accounts = [oauth_account1 , oauth_account2 ],
0 commit comments