Coverage for tests/test_tutorial/test_one/test_tutorial004.py: 100%
20 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 00:02 +0000
1from unittest.mock import patch 1ghijkl
3import pytest 1ghijkl
4from sqlalchemy.exc import MultipleResultsFound 1ghijkl
5from sqlmodel import Session, create_engine, delete 1ghijkl
7from ...conftest import get_testing_print_function 1ghijkl
10def test_tutorial(clear_sqlmodel): 1ghijkl
11 from docs_src.tutorial.one import tutorial004 as mod 1abcdef
13 mod.sqlite_url = "sqlite://" 1abcdef
14 mod.engine = create_engine(mod.sqlite_url) 1abcdef
15 with pytest.raises(MultipleResultsFound): 1abcdef
16 mod.main() 1abcdef
17 with Session(mod.engine) as session: 1abcdef
18 # TODO: create delete() function
19 # TODO: add overloads for .exec() with delete object
20 session.exec(delete(mod.Hero)) 1abcdef
21 session.add(mod.Hero(name="Test Hero", secret_name="Secret Test Hero", age=24)) 1abcdef
22 session.commit() 1abcdef
24 calls = [] 1abcdef
26 new_print = get_testing_print_function(calls) 1abcdef
28 with patch("builtins.print", new=new_print): 1abcdef
29 mod.select_heroes() 1abcdef
30 assert calls == [ 1abcdef
31 [
32 "Hero:",
33 {
34 "id": 1,
35 "name": "Test Hero",
36 "secret_name": "Secret Test Hero",
37 "age": 24,
38 },
39 ]
40 ]