forked from fastapi/sqlmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tutorial001.py
More file actions
56 lines (46 loc) · 1.31 KB
/
test_tutorial001.py
File metadata and controls
56 lines (46 loc) · 1.31 KB
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
46
47
48
49
50
51
52
53
54
55
56
import importlib
from dataclasses import dataclass
from types import ModuleType
import pytest
from sqlmodel import create_engine
from tests.conftest import PrintMock
expected_calls = [
[
"Created hero:",
{
"id": 1,
"name": "Deadpond",
"age": None,
"secret_name": "Dive Wilson",
"team_id": 1,
},
],
[
"Hero's team:",
{"name": "Z-Force", "headquarters": "Sister Margaret's Bar", "id": 1},
],
]
@dataclass
class Modules:
app: ModuleType
database: ModuleType
@pytest.fixture(
name="modules",
params=[
pytest.param("tutorial001_py310"),
],
)
def get_modules(request: pytest.FixtureRequest) -> Modules:
app_module = importlib.import_module(
f"docs_src.tutorial.code_structure.{request.param}.app"
)
database_module = importlib.import_module(
f"docs_src.tutorial.code_structure.{request.param}.database"
)
database_module.sqlite_url = "sqlite://"
database_module.engine = create_engine(database_module.sqlite_url)
app_module.engine = database_module.engine
return Modules(app=app_module, database=database_module)
def test_tutorial(print_mock: PrintMock, modules: Modules):
modules.app.main()
assert print_mock.calls == expected_calls