Coverage for databases/sync_tests/types/test_bool.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-04-28 15:17 +0000

1from prisma import Prisma 

2 

3 

4def test_filtering(client: Prisma) -> None: 

5 """Finding records by a Boolean value""" 

6 with client.batch_() as batcher: 

7 for i in range(10): 

8 batcher.types.create({'bool_': i % 2 == 0}) 

9 

10 total = client.types.count(where={'bool_': {'equals': True}}) 

11 assert total == 5 

12 

13 found = client.types.find_first( 

14 where={ 

15 'bool_': { 

16 'equals': False, 

17 }, 

18 }, 

19 ) 

20 assert found is not None 

21 assert found.bool_ is False 

22 

23 found = client.types.find_first( 

24 where={ 

25 'bool_': { 

26 'not': True, 

27 }, 

28 }, 

29 ) 

30 assert found is not None 

31 assert found.bool_ is False 

32 

33 found = client.types.find_first( 

34 where={ 

35 'bool_': { 

36 'not': False, 

37 }, 

38 }, 

39 ) 

40 assert found is not None 

41 assert found.bool_ is True 

42 

43 found = client.types.find_first( 

44 where={ 

45 'bool_': False, 

46 }, 

47 ) 

48 assert found is not None 

49 assert found.bool_ is False 

50 

51 

52def test_filtering_nulls(client: Prisma) -> None: 

53 """None is a valid filter for nullable Boolean fields""" 

54 client.types.create( 

55 { 

56 'string': 'a', 

57 'optional_bool': None, 

58 }, 

59 ) 

60 client.types.create( 

61 { 

62 'string': 'b', 

63 'optional_bool': True, 

64 }, 

65 ) 

66 client.types.create( 

67 { 

68 'string': 'c', 

69 'optional_bool': False, 

70 }, 

71 ) 

72 

73 found = client.types.find_first( 

74 where={ 

75 'NOT': [ 

76 { 

77 'optional_bool': None, 

78 }, 

79 ], 

80 }, 

81 order={ 

82 'string': 'asc', 

83 }, 

84 ) 

85 assert found is not None 

86 assert found.string == 'b' 

87 assert found.optional_bool is True 

88 

89 count = client.types.count( 

90 where={ 

91 'optional_bool': None, 

92 }, 

93 ) 

94 assert count == 1 

95 

96 count = client.types.count( 

97 where={ 

98 'NOT': [ 

99 { 

100 'optional_bool': None, 

101 }, 

102 ], 

103 }, 

104 ) 

105 assert count == 2