Coverage for databases/tests/test_upsert.py: 100%
13 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_upsert(client: Prisma) -> None:
8 """Upserting a non-existent and existing model updates fields"""
9 user_id = 'asjdhsajd'
10 assert await client.user.find_unique(where={'id': user_id}) is None
12 user = await client.user.upsert(
13 where={'id': user_id},
14 data={
15 'create': {'id': user_id, 'name': 'Robert'},
16 'update': {'name': 'Robert'},
17 },
18 )
19 assert user.id == user_id
20 assert user.name == 'Robert'
22 user = await client.user.upsert(
23 where={'id': user_id},
24 data={
25 'create': {'id': user_id, 'name': 'Bob'},
26 'update': {'name': 'Bob'},
27 },
28 )
29 assert user.id == user_id
30 assert user.name == 'Bob'
32 assert await client.user.count() == 1