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

38 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_floats(client: Prisma) -> None: 

8 """Updating a Float[] value""" 

9 models = [ 

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

11 await client.lists.create( 

12 data={ 

13 'floats': [3.4, 6.8, 12.4], 

14 }, 

15 ), 

16 ] 

17 

18 model = await client.lists.update( 

19 where={ 

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

21 }, 

22 data={ 

23 'floats': { 

24 'set': [99999.999], 

25 }, 

26 }, 

27 ) 

28 assert model is not None 

29 assert model.floats == [99999.999] 

30 

31 model = await client.lists.update( 

32 where={ 

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

34 }, 

35 data={ 

36 'floats': [80], 

37 }, 

38 ) 

39 assert model is not None 

40 assert model.floats == [80] 

41 

42 

43@pytest.mark.asyncio 

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

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

46 async with client.batch_() as batcher: 

47 batcher.lists.create({}) 

48 batcher.lists.create( 

49 data={ 

50 'floats': [], 

51 }, 

52 ) 

53 batcher.lists.create( 

54 data={ 

55 'floats': [1.3, 2.6, 3.9], 

56 }, 

57 ) 

58 

59 model = await client.lists.find_first( 

60 where={ 

61 'floats': { 

62 'equals': None, 

63 }, 

64 }, 

65 ) 

66 assert model is not None 

67 assert model.floats == [] 

68 

69 model = await client.lists.find_first( 

70 where={ 

71 'floats': { 

72 'equals': [1.3, 2.6, 3.9], 

73 }, 

74 }, 

75 ) 

76 assert model is not None 

77 assert model.floats == [1.3, 2.6, 3.9] 

78 

79 model = await client.lists.find_first( 

80 where={ 

81 'floats': { 

82 'has': 2.6, 

83 }, 

84 }, 

85 ) 

86 assert model is not None 

87 assert model.floats == [1.3, 2.6, 3.9] 

88 

89 model = await client.lists.find_first( 

90 where={ 

91 'floats': { 

92 'has': 4.0, 

93 }, 

94 }, 

95 ) 

96 assert model is None 

97 

98 model = await client.lists.find_first( 

99 where={ 

100 'floats': { 

101 'has_some': [2.6, 3.9, 4.5], 

102 }, 

103 }, 

104 ) 

105 assert model is not None 

106 assert model.floats == [1.3, 2.6, 3.9] 

107 

108 model = await client.lists.find_first( 

109 where={ 

110 'floats': { 

111 'has_every': [2.6, 3.9, 4.5], 

112 }, 

113 }, 

114 ) 

115 assert model is None 

116 

117 model = await client.lists.find_first( 

118 where={ 

119 'floats': { 

120 'has_every': [2.6, 3.9], 

121 }, 

122 }, 

123 ) 

124 assert model is not None 

125 assert model.floats == [1.3, 2.6, 3.9] 

126 

127 count = await client.lists.count( 

128 where={ 

129 'floats': { 

130 'is_empty': True, 

131 }, 

132 }, 

133 ) 

134 assert count == 1