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

1"""Module for the use case get training.""" 

2 

3from dataclasses import dataclass 

4 

5from kwai.modules.training.trainings.training import TrainingEntity, TrainingIdentifier 

6from kwai.modules.training.trainings.training_repository import TrainingRepository 

7 

8 

9@dataclass(kw_only=True, frozen=True, slots=True) 

10class GetTrainingCommand: 

11 """Input for the get training use case. 

12 

13 Attributes: 

14 id: the id of the training. 

15 """ 

16 

17 id: int 

18 

19 

20class GetTraining: 

21 """Use case to get a training.""" 

22 

23 def __init__(self, repo: TrainingRepository): 

24 """Initialize the use case. 

25 

26 Attributes: 

27 repo: The repository for trainings. 

28 """ 

29 self._repo = repo 

30 

31 async def execute(self, command: GetTrainingCommand) -> TrainingEntity: 

32 """Execute the use case. 

33 

34 Args: 

35 command: the input for this use case. 

36 

37 Raises: 

38 TrainingNotFoundException: Raised when the training with the given id 

39 does not exist. 

40 

41 Returns: 

42 A training entity. 

43 """ 

44 return await self._repo.get_by_id(TrainingIdentifier(command.id))