11from typing import AsyncGenerator
22
3- import pytest_asyncio
3+ import pytest
44
55from sqlmodel import SQLModel
66from sqlalchemy .ext .asyncio import create_async_engine
1414engine = create_async_engine ("sqlite+aiosqlite:///:memory:" , echo = False , future = True )
1515
1616
17- @pytest_asyncio .fixture (scope = "function" )
17+ @pytest .fixture (scope = "session" , autouse = True )
1818async def db () -> AsyncGenerator [Database , None ]:
1919 async with engine .begin () as conn :
2020 await conn .run_sync (SQLModel .metadata .create_all )
@@ -23,23 +23,26 @@ async def db() -> AsyncGenerator[Database, None]:
2323 yield db
2424
2525
26- @pytest_asyncio .fixture (scope = "function" )
26+ @pytest .fixture (scope = "session" , autouse = True )
2727async def logic (db : Database ) -> Logic :
2828 return Logic (db )
2929
3030
31- @pytest_asyncio .fixture (scope = "function" )
32- async def user_create_model () -> UserCreate :
31+ @pytest .fixture (scope = "function" )
32+ async def user_create () -> UserCreate :
3333 return UserCreate (email = "email@email.email" , password = "password" )
3434
3535
36- @pytest_asyncio .fixture (scope = "function" )
36+ @pytest .fixture (scope = "function" )
3737async def token (logic : Logic ) -> str :
3838 return logic .security .jwt .encode_token ({}, 1 )
3939
4040
41- @pytest_asyncio .fixture (scope = "function" )
42- async def access_token (
43- logic : Logic , user_create_model : UserCreate
44- ) -> AccessToken | None :
45- return await logic .auth .generate_token (user_create_model )
41+ @pytest .fixture (scope = "function" )
42+ async def access_token (logic : Logic , user_create : UserCreate ) -> AccessToken | None :
43+ return await logic .auth .generate_token (user_create )
44+
45+
46+ @pytest .fixture (scope = "function" )
47+ async def hashpwd (logic : Logic , user_create : UserCreate ) -> str | None :
48+ return logic .security .pwd .hashpwd (user_create .password )
0 commit comments