Coverage for kwai/modules/training/delete_training.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines the use case "Delete Training".""" 

2from dataclasses import dataclass 

3 

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

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

6 

7 

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

9class DeleteTrainingCommand: 

10 """Input for the use case DeleteTraining.""" 

11 

12 id: int 

13 

14 

15class DeleteTraining: 

16 """Use case for deleting a training.""" 

17 

18 def __init__(self, repo: TrainingRepository): 

19 """Initialize the use case. 

20 

21 Args: 

22 repo: A repository for deleting the training. 

23 """ 

24 self._repo = repo 

25 

26 async def execute(self, command: DeleteTrainingCommand) -> None: 

27 """Execute the use case. 

28 

29 Args: 

30 command: The input for the use case. 

31 

32 Raises: 

33 TrainingNotFoundException: raised when the training does not exist. 

34 """ 

35 training = await self._repo.get_by_id(TrainingIdentifier(command.id)) 

36 await self._repo.delete(training)