Coverage for databases/sync_tests/test_case_sensitivity.py: 100%
22 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_case_sensitivity(client: Prisma) -> None:
5 """Ensure string fields can be filtered in a case-insensitive manner"""
6 client.user.create(
7 data={
8 'name': 'Robert',
9 'posts': {
10 'create': {
11 'title': 'POST 1',
12 },
13 },
14 },
15 )
16 client.user.create(
17 data={
18 'name': 'robert',
19 'posts': {
20 'create': {
21 'title': 'post 2',
22 },
23 },
24 },
25 )
27 users = client.user.find_many(
28 where={
29 'name': {
30 'equals': 'robert',
31 'mode': 'insensitive',
32 },
33 },
34 order={
35 'created_at': 'asc',
36 },
37 )
38 assert len(users) == 2
39 assert users[0].name == 'Robert'
40 assert users[1].name == 'robert'
42 users = client.user.find_many(
43 where={
44 'name': {
45 'equals': 'robert',
46 'mode': 'default',
47 },
48 },
49 )
50 assert len(users) == 1
51 assert users[0].name == 'robert'
53 users = client.user.find_many(
54 where={
55 'name': {
56 'equals': 'robert',
57 },
58 },
59 )
60 assert len(users) == 1
61 assert users[0].name == 'robert'
63 posts = client.post.find_many(
64 where={
65 'author': {
66 'is': {
67 'name': {
68 'equals': 'robert',
69 'mode': 'insensitive',
70 },
71 },
72 },
73 },
74 include={
75 'author': True,
76 },
77 order={
78 'created_at': 'asc',
79 },
80 )
81 assert len(posts) == 2
82 assert posts[0].title == 'POST 1'
83 assert posts[0].author is not None
84 assert posts[0].author.name == 'Robert'
85 assert posts[1].title == 'post 2'
86 assert posts[1].author is not None
87 assert posts[1].author.name == 'robert'