Coverage for src/kwai/modules/training/get_training.py: 100%
11 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 for the use case get training."""
3from dataclasses import dataclass
5from kwai.modules.training.trainings.training import TrainingEntity, TrainingIdentifier
6from kwai.modules.training.trainings.training_repository import TrainingRepository
9@dataclass(kw_only=True, frozen=True, slots=True)
10class GetTrainingCommand:
11 """Input for the get training use case.
13 Attributes:
14 id: the id of the training.
15 """
17 id: int
20class GetTraining:
21 """Use case to get a training."""
23 def __init__(self, repo: TrainingRepository):
24 """Initialize the use case.
26 Attributes:
27 repo: The repository for trainings.
28 """
29 self._repo = repo
31 async def execute(self, command: GetTrainingCommand) -> TrainingEntity:
32 """Execute the use case.
34 Args:
35 command: the input for this use case.
37 Raises:
38 TrainingNotFoundException: Raised when the training with the given id
39 does not exist.
41 Returns:
42 A training entity.
43 """
44 return await self._repo.get_by_id(TrainingIdentifier(command.id))