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

19 statements  

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

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from dirty_equals import IsUUID 1abcdefghi

6from sqlalchemy import Engine 1abcdefghi

7 

8from ...conftest import PrintMock 1abcdefghi

9 

10 

11@pytest.fixture( 1abcdefghi

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001_py310"), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi

18 mod = importlib.import_module(f"docs_src.advanced.uuid.{request.param}") 1abcdefghi

19 mod.engine = database_engine 1abcdefghi

20 return mod 1abcdefghi

21 

22 

23def test_tutorial(print_mock: PrintMock, mod: ModuleType) -> None: 1abcdefghi

24 mod.main() 1jklmnopqr

25 first_uuid = print_mock.calls[1][0]["id"] 1jklmnopqr

26 assert first_uuid == IsUUID(4) 1jklmnopqr

27 

28 second_uuid = print_mock.calls[7][0]["id"] 1jklmnopqr

29 assert second_uuid == IsUUID(4) 1jklmnopqr

30 

31 assert first_uuid != second_uuid 1jklmnopqr

32 

33 assert print_mock.calls == [ 1jklmnopqr

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

35 [ 

36 { 

37 "name": "Deadpond", 

38 "secret_name": "Dive Wilson", 

39 "id": first_uuid, 

40 "age": None, 

41 } 

42 ], 

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

44 [first_uuid], 

45 ["After saving in the DB"], 

46 [ 

47 { 

48 "name": "Deadpond", 

49 "secret_name": "Dive Wilson", 

50 "age": None, 

51 "id": first_uuid, 

52 } 

53 ], 

54 ["Created hero:"], 

55 [ 

56 { 

57 "name": "Spider-Boy", 

58 "secret_name": "Pedro Parqueador", 

59 "age": None, 

60 "id": second_uuid, 

61 } 

62 ], 

63 ["Created hero ID:"], 

64 [second_uuid], 

65 ["Selected hero:"], 

66 [ 

67 { 

68 "name": "Spider-Boy", 

69 "secret_name": "Pedro Parqueador", 

70 "age": None, 

71 "id": second_uuid, 

72 } 

73 ], 

74 ["Selected hero ID:"], 

75 [second_uuid], 

76 ]