File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import ormar
2+ import pytest
3+
4+ from tests .lifespan import init_tests
5+ from tests .settings import create_config
6+
7+ base_ormar_config = create_config ()
8+
9+
10+ class Jimmy (ormar .Model ):
11+ ormar_config = base_ormar_config .copy (tablename = "jimmies" )
12+ name = ormar .String (primary_key = True , max_length = 42 )
13+
14+
15+ create_test_database = init_tests (base_ormar_config )
16+
17+
18+ @pytest .fixture (scope = "session" )
19+ def anyio_backend ():
20+ return "asyncio"
21+
22+
23+ @pytest .mark .anyio
24+ @pytest .fixture (scope = "function" , autouse = True )
25+ async def db_session ():
26+ async with base_ormar_config .database :
27+ async with base_ormar_config .database .transaction (force_rollback = True ):
28+ yield
29+
30+
31+ @pytest .mark .anyio
32+ async def test_jimmy_can ():
33+ await Jimmy .objects .create (
34+ name = "jimmy" ,
35+ )
36+ await Jimmy .objects .create (
37+ name = "jimmyRus" ,
38+ )
39+ jimmies = await Jimmy .objects .all ()
40+ assert len (jimmies ) == 2
41+
42+
43+ @pytest .mark .anyio
44+ async def test_jimmy_cant ():
45+ jimmies = await Jimmy .objects .all ()
46+ assert not jimmies
47+
48+ await Jimmy .objects .create (
49+ name = "jimmy" ,
50+ )
51+ await Jimmy .objects .create (
52+ name = "jimmyRus" ,
53+ )
54+ jimmies = await Jimmy .objects .all ()
55+ assert len (jimmies ) == 2
You can’t perform that action at this time.
0 commit comments