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

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

2from dataclasses import dataclass 

3 

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

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

6 

7 

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

9class GetTrainingCommand: 

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

11 

12 Attributes: 

13 id: the id of the training. 

14 """ 

15 

16 id: int 

17 

18 

19class GetTraining: 

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

21 

22 def __init__(self, repo: TrainingRepository): 

23 """Initialize the use case. 

24 

25 Attributes: 

26 repo: The repository for trainings. 

27 """ 

28 self._repo = repo 

29 

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

31 """Execute the use case. 

32 

33 Args: 

34 command: the input for this use case. 

35 

36 Raises: 

37 TrainingNotFoundException: Raised when the training with the given id 

38 does not exist. 

39 

40 Returns: 

41 A training entity. 

42 """ 

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