Coverage for tests/test_generation/test_attributes.py: 100%

6 statements  

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

1from ..utils import Testdir 

2 

3 

4def test_field_map(testdir: Testdir) -> None: 

5 """Mapping fields does not rename pydantic model fields""" 

6 

7 # NOTE: this just tests that map can be used with Prisma Client Python 

8 # prisma handles mapping for us 

9 def tests() -> None: # mark: filedef 

10 from prisma.models import User 

11 

12 def test_field_map() -> None: # pyright: ignore[reportUnusedFunction] 

13 """Correct model field name access""" 

14 user = User(id='1', my_field='bar', foo_field='baz') # type: ignore[call-arg] 

15 assert user.id == '1' 

16 assert user.my_field == 'bar' # type: ignore[attr-defined] 

17 assert user.foo_field == 'baz' # type: ignore[attr-defined] 

18 

19 schema = """ 

20 datasource db {{ 

21 provider = "sqlite" 

22 url = "file:dev.db" 

23 }} 

24 

25 generator db {{ 

26 provider = "coverage run -m prisma" 

27 output = "{output}" 

28 {options} 

29 }} 

30 

31 model User {{ 

32 id String @id 

33 my_field String @map("myField") 

34 foo_field String @map(name: "fooField") 

35 }} 

36 """ 

37 testdir.generate(schema=schema) 

38 testdir.make_from_function(tests) 

39 testdir.runpytest().assert_outcomes(passed=1)