Coverage for kwai/modules/training/get_training.py: 100%
11 statements
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
« prev ^ index » next coverage.py v7.3.0, created at 2023-09-05 17:55 +0000
1"""Module for the use case get training."""
2from dataclasses import dataclass
4from kwai.modules.training.trainings.training import TrainingEntity, TrainingIdentifier
5from kwai.modules.training.trainings.training_repository import TrainingRepository
8@dataclass(kw_only=True, frozen=True, slots=True)
9class GetTrainingCommand:
10 """Input for the get training use case.
12 Attributes:
13 id: the id of the training.
14 """
16 id: int
19class GetTraining:
20 """Use case to get a training."""
22 def __init__(self, repo: TrainingRepository):
23 """Initialize the use case.
25 Attributes:
26 repo: The repository for trainings.
27 """
28 self._repo = repo
30 async def execute(self, command: GetTrainingCommand) -> TrainingEntity:
31 """Execute the use case.
33 Args:
34 command: the input for this use case.
36 Raises:
37 TrainingNotFoundException: Raised when the training with the given id
38 does not exist.
40 Returns:
41 A training entity.
42 """
43 return await self._repo.get_by_id(TrainingIdentifier(command.id))