-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
test_count.py
71 lines (54 loc) · 2.03 KB
/
test_count.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pytest
from prisma import Prisma
# TODO: more tests
@pytest.mark.asyncio
async def test_count(client: Prisma) -> None:
"""Basic usage with a result"""
await client.post.create({'title': 'post 1', 'published': False})
assert await client.post.count() == 1
@pytest.mark.asyncio
async def test_count_no_results(client: Prisma) -> None:
"""No results returns 0"""
total = await client.post.count(where={'title': 'kdbsajdh'})
assert total == 0
@pytest.mark.asyncio
async def test_take(client: Prisma) -> None:
"""Take argument limits the maximum value"""
async with client.batch_() as batcher:
batcher.post.create({'title': 'Foo 1', 'published': False})
batcher.post.create({'title': 'Foo 2', 'published': False})
batcher.post.create({'title': 'Foo 3', 'published': False})
total = await client.post.count(take=1)
assert total == 1
@pytest.mark.asyncio
async def test_skip(client: Prisma) -> None:
"""Skip argument ignores the first N records"""
async with client.batch_() as batcher:
batcher.post.create({'title': 'Foo 1', 'published': False})
batcher.post.create({'title': 'Foo 2', 'published': False})
batcher.post.create({'title': 'Foo 3', 'published': False})
total = await client.post.count(skip=1)
assert total == 2
@pytest.mark.asyncio
async def test_select(client: Prisma) -> None:
"""Selecting a field counts non-null values"""
async with client.batch_() as batcher:
batcher.post.create({'title': 'Foo', 'published': False})
batcher.post.create({'title': 'Foo 2', 'published': False, 'description': 'A'})
count = await client.post.count(
select={},
)
assert count == {'_all': 2}
count = await client.post.count(
select={
'description': True,
},
)
assert count == {'description': 1}
count = await client.post.count(
select={
'_all': True,
'description': True,
},
)
assert count == {'_all': 2, 'description': 1}