Coverage for tests/test_advanced/test_uuid/test_tutorial001_py310.py: 100%
19 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-24 00:02 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-24 00:02 +0000
1from unittest.mock import patch 1efghij
3from dirty_equals import IsUUID 1efghij
4from sqlmodel import create_engine 1efghij
6from ...conftest import get_testing_print_function, needs_py310 1efghij
9@needs_py310 1efghij
10def test_tutorial(clear_sqlmodel) -> None: 1efghij
11 from docs_src.advanced.uuid import tutorial001_py310 as mod 1abcd
13 mod.sqlite_url = "sqlite://" 1abcd
14 mod.engine = create_engine(mod.sqlite_url) 1abcd
15 calls = [] 1abcd
17 new_print = get_testing_print_function(calls) 1abcd
19 with patch("builtins.print", new=new_print): 1abcd
20 mod.main() 1abcd
21 first_uuid = calls[1][0]["id"] 1abcd
22 assert first_uuid == IsUUID(4) 1abcd
24 second_uuid = calls[7][0]["id"] 1abcd
25 assert second_uuid == IsUUID(4) 1abcd
27 assert first_uuid != second_uuid 1abcd
29 assert calls == [ 1abcd
30 ["The hero before saving in the DB"],
31 [
32 {
33 "name": "Deadpond",
34 "secret_name": "Dive Wilson",
35 "id": first_uuid,
36 "age": None,
37 }
38 ],
39 ["The hero ID was already set"],
40 [first_uuid],
41 ["After saving in the DB"],
42 [
43 {
44 "name": "Deadpond",
45 "secret_name": "Dive Wilson",
46 "age": None,
47 "id": first_uuid,
48 }
49 ],
50 ["Created hero:"],
51 [
52 {
53 "name": "Spider-Boy",
54 "secret_name": "Pedro Parqueador",
55 "age": None,
56 "id": second_uuid,
57 }
58 ],
59 ["Created hero ID:"],
60 [second_uuid],
61 ["Selected hero:"],
62 [
63 {
64 "name": "Spider-Boy",
65 "secret_name": "Pedro Parqueador",
66 "age": None,
67 "id": second_uuid,
68 }
69 ],
70 ["Selected hero ID:"],
71 [second_uuid],
72 ]