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
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines the team schema."""
3from types import NoneType
5from pydantic import BaseModel
7from kwai.api.schemas.resources import TeamResourceIdentifier
8from kwai.core.json_api import Document, ResourceData
9from kwai.modules.training.teams.team import TeamEntity
12class TeamAttributes(BaseModel):
13 """Attributes for a team JSON:API resource."""
15 name: str
18class TeamResource(TeamResourceIdentifier, ResourceData[TeamAttributes, NoneType]):
19 """A JSON:API resource for a team."""
22class TeamDocument(Document[TeamResource, NoneType]):
23 """A JSON:API document for one or more teams."""
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 )