Coverage for src/kwai/api/v1/trainings/schemas/team.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines the team schema.""" 

2 

3from types import NoneType 

4 

5from pydantic import BaseModel 

6 

7from kwai.api.schemas.resources import TeamResourceIdentifier 

8from kwai.core.json_api import Document, ResourceData 

9from kwai.modules.training.teams.team import TeamEntity 

10 

11 

12class TeamAttributes(BaseModel): 

13 """Attributes for a team JSON:API resource.""" 

14 

15 name: str 

16 

17 

18class TeamResource(TeamResourceIdentifier, ResourceData[TeamAttributes, NoneType]): 

19 """A JSON:API resource for a team.""" 

20 

21 

22class TeamDocument(Document[TeamResource, NoneType]): 

23 """A JSON:API document for one or more teams.""" 

24 

25 @classmethod 

26 def create(cls, team: TeamEntity) -> "TeamDocument": 

27 """Create a document from a team entity.""" 

28 return TeamDocument( 

29 data=TeamResource( 

30 id=str(team.id), attributes=TeamAttributes(name=team.name) 

31 ) 

32 )