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

22 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_delete(client: Prisma) -> None: 

8 """Deleting a record with a relationship does not delete the related record""" 

9 post = await client.post.create( 

10 { 

11 'title': 'Hi from Prisma!', 

12 'published': False, 

13 'author': {'create': {'name': 'Alice'}}, 

14 }, 

15 include={'author': True}, 

16 ) 

17 assert post.title == 'Hi from Prisma!' 

18 assert post.author is not None 

19 assert post.author.name == 'Alice' 

20 

21 deleted = await client.post.delete(where={'id': post.id}, include={'author': True}) 

22 assert deleted is not None 

23 assert deleted.title == 'Hi from Prisma!' 

24 assert deleted.author is not None 

25 assert deleted.author.name == 'Alice' 

26 

27 found = await client.post.find_unique(where={'id': post.id}, include={'author': True}) 

28 assert found is None 

29 

30 user = await client.user.find_unique(where={'id': post.author.id}) 

31 assert user is not None 

32 assert user.name == 'Alice' 

33 

34 

35@pytest.mark.asyncio 

36async def test_delete_record_not_found(client: Prisma) -> None: 

37 """Deleting a non-existent record returns None""" 

38 deleted = await client.post.delete(where={'id': 'ksdjsdh'}) 

39 assert deleted is None