Coverage for databases/sync_tests/arrays/test_int.py: 100%

35 statements  

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

1from prisma import Prisma 

2 

3 

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

5 """Updating an Int[] value""" 

6 models = [ 

7 client.lists.create({}), 

8 client.lists.create( 

9 data={ 

10 'ints': [1, 2, 3], 

11 }, 

12 ), 

13 ] 

14 

15 model = client.lists.update( 

16 where={ 

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

18 }, 

19 data={ 

20 'ints': { 

21 'set': [5], 

22 }, 

23 }, 

24 ) 

25 assert model is not None 

26 assert model.ints == [5] 

27 

28 model = client.lists.update( 

29 where={ 

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

31 }, 

32 data={ 

33 'ints': [6], 

34 }, 

35 ) 

36 assert model is not None 

37 assert model.ints == [6] 

38 

39 

40def test_filtering_ints(client: Prisma) -> None: 

41 """Searching for records by an Int[] value""" 

42 with client.batch_() as batcher: 

43 batcher.lists.create({}) 

44 batcher.lists.create( 

45 data={ 

46 'ints': [], 

47 }, 

48 ) 

49 batcher.lists.create( 

50 data={ 

51 'ints': [1, 2, 3], 

52 }, 

53 ) 

54 

55 model = client.lists.find_first( 

56 where={ 

57 'ints': { 

58 'equals': None, 

59 }, 

60 }, 

61 ) 

62 assert model is not None 

63 assert model.ints == [] 

64 

65 model = client.lists.find_first( 

66 where={ 

67 'ints': { 

68 'equals': [1, 2, 3], 

69 }, 

70 }, 

71 ) 

72 assert model is not None 

73 assert model.ints == [1, 2, 3] 

74 

75 model = client.lists.find_first( 

76 where={ 

77 'ints': { 

78 'has': 1, 

79 }, 

80 }, 

81 ) 

82 assert model is not None 

83 assert model.ints == [1, 2, 3] 

84 

85 model = client.lists.find_first( 

86 where={ 

87 'ints': { 

88 'has': 4, 

89 }, 

90 }, 

91 ) 

92 assert model is None 

93 

94 model = client.lists.find_first( 

95 where={ 

96 'ints': { 

97 'has_some': [2, 3, 4], 

98 }, 

99 }, 

100 ) 

101 assert model is not None 

102 assert model.ints == [1, 2, 3] 

103 

104 model = client.lists.find_first( 

105 where={ 

106 'ints': { 

107 'has_every': [2, 3, 4], 

108 }, 

109 }, 

110 ) 

111 assert model is None 

112 

113 model = client.lists.find_first( 

114 where={ 

115 'ints': { 

116 'has_every': [1, 2], 

117 }, 

118 }, 

119 ) 

120 assert model is not None 

121 assert model.ints == [1, 2, 3] 

122 

123 count = client.lists.count( 

124 where={ 

125 'ints': { 

126 'is_empty': True, 

127 }, 

128 }, 

129 ) 

130 assert count == 1