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

11 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 

7@pytest.mark.asyncio 

8async def test_create_many_skip_duplicates(client: Prisma) -> None: 

9 """Skipping duplcates ignores unique constraint errors""" 

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

11 

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

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

14 

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

16 

17 count = await client.user.create_many( 

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

19 skip_duplicates=True, 

20 ) 

21 assert count == 1