Coverage for databases/sync_tests/test_delete.py: 100%
19 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2024-08-27 18:25 +0000
1from prisma import Prisma
4def test_delete(client: Prisma) -> None:
5 """Deleting a record with a relationship does not delete the related record"""
6 post = client.post.create(
7 {
8 'title': 'Hi from Prisma!',
9 'published': False,
10 'author': {'create': {'name': 'Alice'}},
11 },
12 include={'author': True},
13 )
14 assert post.title == 'Hi from Prisma!'
15 assert post.author is not None
16 assert post.author.name == 'Alice'
18 deleted = client.post.delete(where={'id': post.id}, include={'author': True})
19 assert deleted is not None
20 assert deleted.title == 'Hi from Prisma!'
21 assert deleted.author is not None
22 assert deleted.author.name == 'Alice'
24 found = client.post.find_unique(where={'id': post.id}, include={'author': True})
25 assert found is None
27 user = client.user.find_unique(where={'id': post.author.id})
28 assert user is not None
29 assert user.name == 'Alice'
32def test_delete_record_not_found(client: Prisma) -> None:
33 """Deleting a non-existent record returns None"""
34 deleted = client.post.delete(where={'id': 'ksdjsdh'})
35 assert deleted is None