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

21 statements  

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

1from prisma import Prisma 

2 

3 

4def test_create_many(client: Prisma) -> None: 

5 """Standard usage""" 

6 total = client.user.create_many([{'name': 'Robert'}, {'name': 'Tegan'}]) 

7 assert total == 2 

8 

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

10 assert user is not None 

11 assert user.name == 'Robert' 

12 

13 assert client.user.count() == 2 

14 

15 

16def test_required_relation_key_field(client: Prisma) -> None: 

17 """Explicitly passing a field used as a foreign key connects the relations""" 

18 user = client.user.create( 

19 data={ 

20 'name': 'Robert', 

21 }, 

22 ) 

23 user2 = client.user.create( 

24 data={ 

25 'name': 'Robert', 

26 }, 

27 ) 

28 count = client.profile.create_many( 

29 data=[ 

30 {'user_id': user.id, 'description': 'Foo', 'country': 'Scotland'}, 

31 { 

32 'user_id': user2.id, 

33 'description': 'Foo 2', 

34 'country': 'Scotland', 

35 }, 

36 ], 

37 ) 

38 assert count == 2 

39 

40 found = client.user.find_unique( 

41 where={ 

42 'id': user.id, 

43 }, 

44 include={ 

45 'profile': True, 

46 }, 

47 ) 

48 assert found is not None 

49 assert found.profile is not None 

50 assert found.profile.description == 'Foo' 

51 

52 found = client.user.find_unique( 

53 where={ 

54 'id': user2.id, 

55 }, 

56 include={ 

57 'profile': True, 

58 }, 

59 ) 

60 assert found is not None 

61 assert found.profile is not None 

62 assert found.profile.description == 'Foo 2'