Coverage for databases/sync_tests/arrays/test_decimal.py: 100%
36 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 decimal import Decimal
3from prisma import Prisma
6def test_updating_decimal(client: Prisma) -> None:
7 """Updating a Decimal[] value"""
8 models = [
9 client.lists.create({}),
10 client.lists.create(
11 data={
12 'decimals': [Decimal('22.99'), Decimal('30.01')],
13 },
14 ),
15 ]
17 model = client.lists.update(
18 where={
19 'id': models[1].id,
20 },
21 data={
22 'decimals': {
23 'set': [Decimal('3')],
24 },
25 },
26 )
27 assert model is not None
28 assert model.decimals == [Decimal('3')]
30 model = client.lists.update(
31 where={
32 'id': models[1].id,
33 },
34 data={
35 'decimals': [Decimal('7')],
36 },
37 )
38 assert model is not None
39 assert model.decimals == [Decimal('7')]
42def test_filtering_decimal(client: Prisma) -> None:
43 """Searching for records by a Decimal[] value"""
44 with client.batch_() as batcher:
45 batcher.lists.create({})
46 batcher.lists.create(
47 data={
48 'decimals': [],
49 },
50 )
51 batcher.lists.create(
52 data={
53 'decimals': [Decimal('1'), Decimal('2')],
54 },
55 )
57 model = client.lists.find_first(
58 where={
59 'decimals': {
60 'equals': None,
61 },
62 },
63 )
64 assert model is not None
65 assert model.decimals == []
67 model = client.lists.find_first(
68 where={
69 'decimals': {
70 'equals': [Decimal('1'), Decimal('2')],
71 },
72 },
73 )
74 assert model is not None
75 assert model.decimals == [Decimal(1), Decimal(2)]
77 model = client.lists.find_first(
78 where={
79 'decimals': {
80 'has': Decimal('1'),
81 },
82 },
83 )
84 assert model is not None
85 assert model.decimals == [Decimal(1), Decimal(2)]
87 model = client.lists.find_first(
88 where={
89 'decimals': {
90 'has': Decimal(3),
91 },
92 },
93 )
94 assert model is None
96 model = client.lists.find_first(
97 where={
98 'decimals': {
99 'has_some': [Decimal(1), Decimal(3)],
100 },
101 },
102 )
103 assert model is not None
104 assert model.decimals == [Decimal(1), Decimal(2)]
106 model = client.lists.find_first(
107 where={
108 'decimals': {
109 'has_every': [Decimal(1), Decimal(2), Decimal(3)],
110 },
111 },
112 )
113 assert model is None
115 model = client.lists.find_first(
116 where={
117 'decimals': {
118 'has_every': [Decimal(1)],
119 },
120 },
121 )
122 assert model is not None
123 assert model.decimals == [Decimal(1), Decimal(2)]
125 count = client.lists.count(
126 where={
127 'decimals': {
128 'is_empty': True,
129 },
130 },
131 )
132 assert count == 1