Coverage for databases/sync_tests/arrays/test_float.py: 100%
35 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from prisma import Prisma
4def test_updating_floats(client: Prisma) -> None:
5 """Updating a Float[] value"""
6 models = [
7 client.lists.create({}),
8 client.lists.create(
9 data={
10 'floats': [3.4, 6.8, 12.4],
11 },
12 ),
13 ]
15 model = client.lists.update(
16 where={
17 'id': models[1].id,
18 },
19 data={
20 'floats': {
21 'set': [99999.999],
22 },
23 },
24 )
25 assert model is not None
26 assert model.floats == [99999.999]
28 model = client.lists.update(
29 where={
30 'id': models[1].id,
31 },
32 data={
33 'floats': [80],
34 },
35 )
36 assert model is not None
37 assert model.floats == [80]
40def test_filtering_floats(client: Prisma) -> None:
41 """Searching for records by a Float[] value"""
42 with client.batch_() as batcher:
43 batcher.lists.create({})
44 batcher.lists.create(
45 data={
46 'floats': [],
47 },
48 )
49 batcher.lists.create(
50 data={
51 'floats': [1.3, 2.6, 3.9],
52 },
53 )
55 model = client.lists.find_first(
56 where={
57 'floats': {
58 'equals': None,
59 },
60 },
61 )
62 assert model is not None
63 assert model.floats == []
65 model = client.lists.find_first(
66 where={
67 'floats': {
68 'equals': [1.3, 2.6, 3.9],
69 },
70 },
71 )
72 assert model is not None
73 assert model.floats == [1.3, 2.6, 3.9]
75 model = client.lists.find_first(
76 where={
77 'floats': {
78 'has': 2.6,
79 },
80 },
81 )
82 assert model is not None
83 assert model.floats == [1.3, 2.6, 3.9]
85 model = client.lists.find_first(
86 where={
87 'floats': {
88 'has': 4.0,
89 },
90 },
91 )
92 assert model is None
94 model = client.lists.find_first(
95 where={
96 'floats': {
97 'has_some': [2.6, 3.9, 4.5],
98 },
99 },
100 )
101 assert model is not None
102 assert model.floats == [1.3, 2.6, 3.9]
104 model = client.lists.find_first(
105 where={
106 'floats': {
107 'has_every': [2.6, 3.9, 4.5],
108 },
109 },
110 )
111 assert model is None
113 model = client.lists.find_first(
114 where={
115 'floats': {
116 'has_every': [2.6, 3.9],
117 },
118 },
119 )
120 assert model is not None
121 assert model.floats == [1.3, 2.6, 3.9]
123 count = client.lists.count(
124 where={
125 'floats': {
126 'is_empty': True,
127 },
128 },
129 )
130 assert count == 1