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