Coverage for tests/test_tutorial/test_relationship_attributes/test_delete_records_relationship/test_tutorial001.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from unittest.mock import patch 1ghijkl

2 

3from sqlmodel import create_engine 1ghijkl

4 

5from ....conftest import get_testing_print_function 1ghijkl

6 

7 

8def test_tutorial(clear_sqlmodel): 1ghijkl

9 from docs_src.tutorial.relationship_attributes.cascade_delete_relationships import ( 1abcdef

10 tutorial001 as mod, 

11 ) 

12 

13 mod.sqlite_url = "sqlite://" 1abcdef

14 mod.engine = create_engine(mod.sqlite_url) 1abcdef

15 calls = [] 1abcdef

16 

17 new_print = get_testing_print_function(calls) 1abcdef

18 

19 with patch("builtins.print", new=new_print): 1abcdef

20 mod.main() 1abcdef

21 assert calls == [ 1abcdef

22 [ 

23 "Created hero:", 

24 { 

25 "name": "Deadpond", 

26 "secret_name": "Dive Wilson", 

27 "team_id": 1, 

28 "id": 1, 

29 "age": None, 

30 }, 

31 ], 

32 [ 

33 "Created hero:", 

34 { 

35 "name": "Rusty-Man", 

36 "secret_name": "Tommy Sharp", 

37 "team_id": 2, 

38 "id": 2, 

39 "age": 48, 

40 }, 

41 ], 

42 [ 

43 "Created hero:", 

44 { 

45 "name": "Spider-Boy", 

46 "secret_name": "Pedro Parqueador", 

47 "team_id": None, 

48 "id": 3, 

49 "age": None, 

50 }, 

51 ], 

52 [ 

53 "Updated hero:", 

54 { 

55 "name": "Spider-Boy", 

56 "secret_name": "Pedro Parqueador", 

57 "team_id": 2, 

58 "id": 3, 

59 "age": None, 

60 }, 

61 ], 

62 [ 

63 "Team Wakaland:", 

64 {"name": "Wakaland", "id": 3, "headquarters": "Wakaland Capital City"}, 

65 ], 

66 [ 

67 "Deleted team:", 

68 {"name": "Wakaland", "id": 3, "headquarters": "Wakaland Capital City"}, 

69 ], 

70 ["Black Lion not found:", None], 

71 ["Princess Sure-E not found:", None], 

72 ]