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

38 statements  

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

1import pytest 

2 

3from prisma import Prisma 

4 

5 

6@pytest.mark.asyncio 

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

8 """Updating a BigInt[] value""" 

9 models = [ 

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

11 await client.lists.create( 

12 data={ 

13 'bigints': [539506179039297536, 281454500584095754], 

14 }, 

15 ), 

16 ] 

17 

18 model = await client.lists.update( 

19 where={ 

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

21 }, 

22 data={ 

23 'bigints': { 

24 'set': [129003276736659456], 

25 }, 

26 }, 

27 ) 

28 assert model is not None 

29 assert model.bigints == [129003276736659456] 

30 

31 model = await client.lists.update( 

32 where={ 

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

34 }, 

35 data={ 

36 'bigints': [298490675715112960], 

37 }, 

38 ) 

39 assert model is not None 

40 assert model.bigints == [298490675715112960] 

41 

42 

43@pytest.mark.asyncio 

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

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

46 async with client.batch_() as batcher: 

47 batcher.lists.create({}) 

48 batcher.lists.create( 

49 data={ 

50 'bigints': [], 

51 }, 

52 ) 

53 batcher.lists.create( 

54 data={ 

55 'bigints': [1, 2, 3], 

56 }, 

57 ) 

58 

59 model = await client.lists.find_first( 

60 where={ 

61 'bigints': { 

62 'equals': None, 

63 }, 

64 }, 

65 ) 

66 assert model is not None 

67 assert model.bigints == [] 

68 

69 model = await client.lists.find_first( 

70 where={ 

71 'bigints': { 

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

73 }, 

74 }, 

75 ) 

76 assert model is not None 

77 assert model.bigints == [1, 2, 3] 

78 

79 model = await client.lists.find_first( 

80 where={ 

81 'bigints': { 

82 'has': 1, 

83 }, 

84 }, 

85 ) 

86 assert model is not None 

87 assert model.bigints == [1, 2, 3] 

88 

89 model = await client.lists.find_first( 

90 where={ 

91 'bigints': { 

92 'has': 4, 

93 }, 

94 }, 

95 ) 

96 assert model is None 

97 

98 model = await client.lists.find_first( 

99 where={ 

100 'bigints': { 

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

102 }, 

103 }, 

104 ) 

105 assert model is not None 

106 assert model.bigints == [1, 2, 3] 

107 

108 model = await client.lists.find_first( 

109 where={ 

110 'bigints': { 

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

112 }, 

113 }, 

114 ) 

115 assert model is None 

116 

117 model = await client.lists.find_first( 

118 where={ 

119 'bigints': { 

120 'has_every': [1, 2], 

121 }, 

122 }, 

123 ) 

124 assert model is not None 

125 assert model.bigints == [1, 2, 3] 

126 

127 count = await client.lists.count( 

128 where={ 

129 'bigints': { 

130 'is_empty': True, 

131 }, 

132 }, 

133 ) 

134 assert count == 1