Coverage for databases/sync_tests/test_update_many.py: 100%
36 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_update_many(client: Prisma) -> None:
5 """Filters update correct records
7 TODO: refactor this test, its a messs
8 """
9 posts = [
10 client.post.create({'title': 'Test post 1', 'published': False}),
11 client.post.create({'title': 'Test post 2', 'published': False}),
12 ]
13 count = client.post.update_many(where={'published': False}, data={'published': True})
14 assert count == 2
16 post = client.post.find_unique(where={'id': posts[0].id})
17 assert post is not None
18 assert post.published is True
20 count = client.post.update_many(where={'published': False}, data={'published': True})
21 assert count == 0
23 count = client.post.update_many(where={'id': posts[0].id}, data={'published': False})
24 assert count == 1
26 post = client.post.find_unique(where={'id': posts[0].id})
27 assert post is not None
28 assert post.published is False
30 count = client.post.update_many(where={'published': False}, data={'views': 10})
31 assert count == 1
33 post = client.post.find_unique(where={'id': posts[0].id})
34 assert post is not None
35 assert post.views == 10
37 count = client.post.update_many(where={'id': posts[0].id}, data={'id': 'sdhajd'})
38 assert count == 1
40 post = client.post.find_unique(where={'id': 'sdhajd'})
41 assert post is not None
43 post = client.post.find_unique(where={'id': posts[0].id})
44 assert post is None
47def test_setting_to_null(client: Prisma) -> None:
48 """Setting a field to None sets the database record to None"""
49 post = client.post.create(
50 data={
51 'title': 'Foo',
52 'published': True,
53 'description': 'Description',
54 }
55 )
56 assert post.description == 'Description'
58 count = client.post.update_many(
59 where={},
60 data={'description': None},
61 )
62 assert count == 1
64 found = client.post.find_unique(where={'id': post.id})
65 assert found is not None
66 assert found.id == post.id
67 assert found.title == 'Foo'
68 assert found.description is None