-
-
Notifications
You must be signed in to change notification settings - Fork 845
Expand file tree
/
Copy pathtest_tutorial002.py
More file actions
83 lines (72 loc) · 2.09 KB
/
test_tutorial002.py
File metadata and controls
83 lines (72 loc) · 2.09 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import importlib
import types
import pytest
from dirty_equals import IsUUID
from sqlmodel import create_engine
from ...conftest import PrintMock, needs_py310
@pytest.fixture(
name="module",
params=[
"tutorial002",
pytest.param("tutorial002_py310", marks=needs_py310),
],
)
def get_module(request: pytest.FixtureRequest):
module_name = request.param
return importlib.import_module(f"docs_src.advanced.uuid.{module_name}")
def test_tutorial(print_mock: PrintMock, module: types.ModuleType) -> None:
module.sqlite_url = "sqlite://"
module.engine = create_engine(module.sqlite_url)
module.main()
# Extract UUIDs from actual calls recorded by print_mock
first_uuid = print_mock.calls[1][0]["id"]
assert first_uuid == IsUUID(4)
second_uuid = print_mock.calls[7][0]["id"]
assert second_uuid == IsUUID(4)
assert first_uuid != second_uuid
# Construct expected_calls using the extracted UUIDs
expected_calls = [
["The hero before saving in the DB"],
[
{
"name": "Deadpond",
"secret_name": "Dive Wilson",
"id": first_uuid,
"age": None,
}
],
["The hero ID was already set"],
[first_uuid],
["After saving in the DB"],
[
{
"name": "Deadpond",
"secret_name": "Dive Wilson",
"age": None,
"id": first_uuid,
}
],
["Created hero:"],
[
{
"name": "Spider-Boy",
"secret_name": "Pedro Parqueador",
"age": None,
"id": second_uuid,
}
],
["Created hero ID:"],
[second_uuid],
["Selected hero:"],
[
{
"name": "Spider-Boy",
"secret_name": "Pedro Parqueador",
"age": None,
"id": second_uuid,
}
],
["Selected hero ID:"],
[second_uuid],
]
assert print_mock.calls == expected_calls