File size: 1,219 Bytes
9d4bd7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import pytest
from tortoise import Tortoise

@pytest.fixture(scope="session")
async def initialize_tests(request):
    """Initialize test database"""
    db_config = {
        'connections': {
            'default': {
                'engine': 'tortoise.backends.sqlite',
                'credentials': {
                    'file_path': ':memory:',
                }
            },
        },
        'apps': {
            'models': {
                'models': [
                    'App.routers.stocks.models',
                    'App.routers.tasks.models',
                    'App.routers.utt.models',
                    'App.routers.users.models',
                    'App.routers.portfolio.models',
                    'App.routers.bonds.models'
                ],
                'default_connection': 'default',
            }
        }
    }
    
    await Tortoise.init(config=db_config)
    await Tortoise.generate_schemas()
    
    yield
    
    await Tortoise.close_connections()

@pytest.fixture
async def client():
    """Create a test client"""
    from httpx import AsyncClient
    from main import app
    
    async with AsyncClient(app=app, base_url="http://test") as client:
        yield client