Coverage for bc/kwai-bc-training/src/kwai_bc_training/get_training.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

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

2 

3from dataclasses import dataclass 

4 

5from kwai_core.domain.presenter import Presenter 

6 

7from kwai_bc_training.trainings.training import TrainingEntity, TrainingIdentifier 

8from kwai_bc_training.trainings.training_repository import TrainingRepository 

9 

10 

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

12class GetTrainingCommand: 

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

14 

15 Attributes: 

16 id: the id of the training. 

17 """ 

18 

19 id: int 

20 

21 

22class GetTraining: 

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

24 

25 def __init__(self, repo: TrainingRepository, presenter: Presenter[TrainingEntity]): 

26 """Initialize the use case. 

27 

28 Attributes: 

29 repo: The repository for trainings. 

30 presenter: A presenter for a training. 

31 """ 

32 self._repo = repo 

33 self._presenter = presenter 

34 

35 async def execute(self, command: GetTrainingCommand): 

36 """Execute the use case. 

37 

38 Args: 

39 command: the input for this use case. 

40 

41 Raises: 

42 TrainingNotFoundException: Raised when the training with the given id 

43 does not exist. 

44 """ 

45 self._presenter.present( 

46 await self._repo.get_by_id(TrainingIdentifier(command.id)) 

47 )