Coverage for databases/sync_tests/test_upsert.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-08-27 18:25 +0000

1from prisma import Prisma 

2 

3 

4def test_upsert(client: Prisma) -> None: 

5 """Upserting a non-existent and existing model updates fields""" 

6 user_id = 'asjdhsajd' 

7 assert client.user.find_unique(where={'id': user_id}) is None 

8 

9 user = client.user.upsert( 

10 where={'id': user_id}, 

11 data={ 

12 'create': {'id': user_id, 'name': 'Robert'}, 

13 'update': {'name': 'Robert'}, 

14 }, 

15 ) 

16 assert user.id == user_id 

17 assert user.name == 'Robert' 

18 

19 user = client.user.upsert( 

20 where={'id': user_id}, 

21 data={ 

22 'create': {'id': user_id, 'name': 'Bob'}, 

23 'update': {'name': 'Bob'}, 

24 }, 

25 ) 

26 assert user.id == user_id 

27 assert user.name == 'Bob' 

28 

29 assert client.user.count() == 1