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

19 statements  

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

1import importlib 1abcdefghijklm

2from types import ModuleType 1abcdefghijklm

3 

4import pytest 1abcdefghijklm

5from dirty_equals import IsUUID 1abcdefghijklm

6from sqlalchemy import Engine 1abcdefghijklm

7 

8from ...conftest import PrintMock 1abcdefghijklm

9 

10 

11@pytest.fixture( 1abcdefghijklm

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial002"), 

15 ], 

16) 

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

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

19 mod.engine = database_engine 1abcdefghijklm

20 return mod 1abcdefghijklm

21 

22 

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

24 mod.main() 1nopqrstuvwxyz

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

26 assert first_uuid == IsUUID(4) 1nopqrstuvwxyz

27 

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

29 assert second_uuid == IsUUID(4) 1nopqrstuvwxyz

30 

31 assert first_uuid != second_uuid 1nopqrstuvwxyz

32 

33 assert print_mock.calls == [ 1nopqrstuvwxyz

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 ]