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