Coverage for tests/test_advanced/test_uuid/test_tutorial002.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-07 05:42 +0000

1from unittest.mock import patch 1hijklmn

2 

3from dirty_equals import IsUUID 1hijklmn

4from sqlmodel import create_engine 1hijklmn

5 

6from ...conftest import get_testing_print_function 1hijklmn

7 

8 

9def test_tutorial(clear_sqlmodel) -> None: 1hijklmn

10 from docs_src.advanced.uuid import tutorial002 as mod 1abcdefg

11 

12 mod.sqlite_url = "sqlite://" 1abcdefg

13 mod.engine = create_engine(mod.sqlite_url) 1abcdefg

14 calls = [] 1abcdefg

15 

16 new_print = get_testing_print_function(calls) 1abcdefg

17 

18 with patch("builtins.print", new=new_print): 1abcdefg

19 mod.main() 1abcdefg

20 first_uuid = calls[1][0]["id"] 1abcdefg

21 assert first_uuid == IsUUID(4) 1abcdefg

22 

23 second_uuid = calls[7][0]["id"] 1abcdefg

24 assert second_uuid == IsUUID(4) 1abcdefg

25 

26 assert first_uuid != second_uuid 1abcdefg

27 

28 assert calls == [ 1abcdefg

29 ["The hero before saving in the DB"], 

30 [ 

31 { 

32 "name": "Deadpond", 

33 "secret_name": "Dive Wilson", 

34 "id": first_uuid, 

35 "age": None, 

36 } 

37 ], 

38 ["The hero ID was already set"], 

39 [first_uuid], 

40 ["After saving in the DB"], 

41 [ 

42 { 

43 "name": "Deadpond", 

44 "secret_name": "Dive Wilson", 

45 "age": None, 

46 "id": first_uuid, 

47 } 

48 ], 

49 ["Created hero:"], 

50 [ 

51 { 

52 "name": "Spider-Boy", 

53 "secret_name": "Pedro Parqueador", 

54 "age": None, 

55 "id": second_uuid, 

56 } 

57 ], 

58 ["Created hero ID:"], 

59 [second_uuid], 

60 ["Selected hero:"], 

61 [ 

62 { 

63 "name": "Spider-Boy", 

64 "secret_name": "Pedro Parqueador", 

65 "age": None, 

66 "id": second_uuid, 

67 } 

68 ], 

69 ["Selected hero ID:"], 

70 [second_uuid], 

71 ]