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

19 statements  

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

1from unittest.mock import patch 1defghi

2 

3from dirty_equals import IsUUID 1defghi

4from sqlmodel import create_engine 1defghi

5 

6from ...conftest import get_testing_print_function, needs_py310 1defghi

7 

8 

9@needs_py310 1defghi

10def test_tutorial(clear_sqlmodel) -> None: 1defghi

11 from docs_src.advanced.uuid import tutorial002_py310 as mod 1abc

12 

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

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

15 calls = [] 1abc

16 

17 new_print = get_testing_print_function(calls) 1abc

18 

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

20 mod.main() 1abc

21 first_uuid = calls[1][0]["id"] 1abc

22 assert first_uuid == IsUUID(4) 1abc

23 

24 second_uuid = calls[7][0]["id"] 1abc

25 assert second_uuid == IsUUID(4) 1abc

26 

27 assert first_uuid != second_uuid 1abc

28 

29 assert calls == [ 1abc

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 ]