Coverage for tests/test_fields_set.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from datetime import datetime, timedelta 1ghijkl

2 

3from sqlmodel import Field, SQLModel 1ghijkl

4from sqlmodel._compat import get_fields_set 1ghijkl

5 

6 

7def test_fields_set(): 1ghijkl

8 class User(SQLModel): 1abcdef

9 username: str 1abcdef

10 email: str = "test@test.com" 1abcdef

11 last_updated: datetime = Field(default_factory=datetime.now) 1abcdef

12 

13 user = User(username="bob") 1abcdef

14 assert get_fields_set(user) == {"username"} 1abcdef

15 user = User(username="bob", email="bob@test.com") 1abcdef

16 assert get_fields_set(user) == {"username", "email"} 1abcdef

17 user = User( 1abcdef

18 username="bob", 

19 email="bob@test.com", 

20 last_updated=datetime.now() - timedelta(days=1), 

21 ) 

22 assert get_fields_set(user) == {"username", "email", "last_updated"} 1abcdef