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

12 statements  

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

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

2 

3from dataclasses import dataclass 

4 

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

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

7 

8 

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

10class DeleteTrainingCommand: 

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

12 

13 id: int 

14 

15 

16class DeleteTraining: 

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

18 

19 def __init__(self, repo: TrainingRepository): 

20 """Initialize the use case. 

21 

22 Args: 

23 repo: A repository for deleting the training. 

24 """ 

25 self._repo = repo 

26 

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

28 """Execute the use case. 

29 

30 Args: 

31 command: The input for the use case. 

32 

33 Raises: 

34 TrainingNotFoundException: raised when the training does not exist. 

35 """ 

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

37 await self._repo.delete(training)