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