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