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

18 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 dirty_equals import IsUUID 1ghijkl

4from sqlmodel import create_engine 1ghijkl

5 

6from ...conftest import get_testing_print_function 1ghijkl

7 

8 

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

10 from docs_src.advanced.uuid import tutorial001 as mod 1abcdef

11 

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

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

14 calls = [] 1abcdef

15 

16 new_print = get_testing_print_function(calls) 1abcdef

17 

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

19 mod.main() 1abcdef

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

21 assert first_uuid == IsUUID(4) 1abcdef

22 

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

24 assert second_uuid == IsUUID(4) 1abcdef

25 

26 assert first_uuid != second_uuid 1abcdef

27 

28 assert calls == [ 1abcdef

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 ]