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

1import pytest 

2 

3from prisma import Prisma 

4 

5 

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 

11 

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' 

21 

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' 

31 

32 assert await client.user.count() == 1