Coverage for databases/tests/arrays/test_bool.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-08-27 18:25 +0000

1import pytest 

2 

3from prisma import Prisma 

4 

5 

6@pytest.mark.asyncio 

7async def test_updating_boolean(client: Prisma) -> None: 

8 """Updating a Boolean[] value""" 

9 models = [ 

10 await client.lists.create({}), 

11 await client.lists.create( 

12 data={ 

13 'bools': [False, True], 

14 }, 

15 ), 

16 ] 

17 

18 model = await client.lists.update( 

19 where={ 

20 'id': models[1].id, 

21 }, 

22 data={ 

23 'bools': { 

24 'set': [False], 

25 }, 

26 }, 

27 ) 

28 assert model is not None 

29 assert model.bools == [False] 

30 

31 model = await client.lists.update( 

32 where={ 

33 'id': models[1].id, 

34 }, 

35 data={ 

36 'bools': [True], 

37 }, 

38 ) 

39 assert model is not None 

40 assert model.bools == [True] 

41 

42 

43@pytest.mark.asyncio 

44async def test_filtering_bools(client: Prisma) -> None: 

45 """Searching for records by a Boolean[] value""" 

46 async with client.batch_() as batcher: 

47 batcher.lists.create({}) 

48 batcher.lists.create( 

49 data={ 

50 'bools': [], 

51 }, 

52 ) 

53 batcher.lists.create( 

54 data={ 

55 'bools': [False, True], 

56 }, 

57 ) 

58 

59 model = await client.lists.find_first( 

60 where={ 

61 'bools': { 

62 'equals': None, 

63 }, 

64 }, 

65 ) 

66 assert model is not None 

67 assert model.bools == [] 

68 

69 model = await client.lists.find_first( 

70 where={ 

71 'bools': { 

72 'equals': [], 

73 }, 

74 }, 

75 ) 

76 assert model is not None 

77 assert model.bools == [] 

78 

79 model = await client.lists.find_first( 

80 where={ 

81 'bools': { 

82 'equals': [False, True], 

83 }, 

84 }, 

85 ) 

86 assert model is not None 

87 assert model.bools == [False, True] 

88 

89 model = await client.lists.find_first( 

90 where={ 

91 'bools': { 

92 'has': True, 

93 }, 

94 }, 

95 ) 

96 assert model is not None 

97 assert model.bools == [False, True] 

98 

99 model = await client.lists.find_first( 

100 where={ 

101 'bools': { 

102 'has_some': [True], 

103 }, 

104 }, 

105 ) 

106 assert model is not None 

107 assert model.bools == [False, True] 

108 

109 model = await client.lists.find_first( 

110 where={ 

111 'bools': { 

112 'has_every': [False, True, False, True], 

113 }, 

114 }, 

115 ) 

116 assert model is not None 

117 assert model.bools == [False, True] 

118 

119 model = await client.lists.find_first( 

120 where={ 

121 'bools': { 

122 'has_every': [False, True], 

123 }, 

124 }, 

125 ) 

126 assert model is not None 

127 assert model.bools == [False, True] 

128 

129 count = await client.lists.count( 

130 where={ 

131 'bools': { 

132 'is_empty': True, 

133 }, 

134 }, 

135 ) 

136 assert count == 1