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

10 statements  

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

1import pytest 

2 

3import prisma 

4from prisma import Prisma 

5 

6 

7def test_create_many_skip_duplicates(client: Prisma) -> None: 

8 """Skipping duplcates ignores unique constraint errors""" 

9 user = client.user.create({'name': 'Robert'}) 

10 

11 with pytest.raises(prisma.errors.UniqueViolationError) as exc: 

12 client.user.create_many([{'id': user.id, 'name': 'Robert 2'}]) 

13 

14 assert exc.match(r'Unique constraint failed') 

15 

16 count = client.user.create_many( 

17 [{'id': user.id, 'name': 'Robert 2'}, {'name': 'Tegan'}], 

18 skip_duplicates=True, 

19 ) 

20 assert count == 1