Coverage for databases/tests/arrays/test_int.py: 100%
38 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
1import pytest
3from prisma import Prisma
6@pytest.mark.asyncio
7async def test_updating_ints(client: Prisma) -> None:
8 """Updating an Int[] value"""
9 models = [
10 await client.lists.create({}),
11 await client.lists.create(
12 data={
13 'ints': [1, 2, 3],
14 },
15 ),
16 ]
18 model = await client.lists.update(
19 where={
20 'id': models[1].id,
21 },
22 data={
23 'ints': {
24 'set': [5],
25 },
26 },
27 )
28 assert model is not None
29 assert model.ints == [5]
31 model = await client.lists.update(
32 where={
33 'id': models[1].id,
34 },
35 data={
36 'ints': [6],
37 },
38 )
39 assert model is not None
40 assert model.ints == [6]
43@pytest.mark.asyncio
44async def test_filtering_ints(client: Prisma) -> None:
45 """Searching for records by an Int[] value"""
46 async with client.batch_() as batcher:
47 batcher.lists.create({})
48 batcher.lists.create(
49 data={
50 'ints': [],
51 },
52 )
53 batcher.lists.create(
54 data={
55 'ints': [1, 2, 3],
56 },
57 )
59 model = await client.lists.find_first(
60 where={
61 'ints': {
62 'equals': None,
63 },
64 },
65 )
66 assert model is not None
67 assert model.ints == []
69 model = await client.lists.find_first(
70 where={
71 'ints': {
72 'equals': [1, 2, 3],
73 },
74 },
75 )
76 assert model is not None
77 assert model.ints == [1, 2, 3]
79 model = await client.lists.find_first(
80 where={
81 'ints': {
82 'has': 1,
83 },
84 },
85 )
86 assert model is not None
87 assert model.ints == [1, 2, 3]
89 model = await client.lists.find_first(
90 where={
91 'ints': {
92 'has': 4,
93 },
94 },
95 )
96 assert model is None
98 model = await client.lists.find_first(
99 where={
100 'ints': {
101 'has_some': [2, 3, 4],
102 },
103 },
104 )
105 assert model is not None
106 assert model.ints == [1, 2, 3]
108 model = await client.lists.find_first(
109 where={
110 'ints': {
111 'has_every': [2, 3, 4],
112 },
113 },
114 )
115 assert model is None
117 model = await client.lists.find_first(
118 where={
119 'ints': {
120 'has_every': [1, 2],
121 },
122 },
123 )
124 assert model is not None
125 assert model.ints == [1, 2, 3]
127 count = await client.lists.count(
128 where={
129 'ints': {
130 'is_empty': True,
131 },
132 },
133 )
134 assert count == 1