Coverage for src/kwai/modules/training/delete_training_definition.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module for the use case "Delete Training Definition"."""
3from dataclasses import dataclass
5from kwai.modules.training.trainings.training_definition import (
6 TrainingDefinitionIdentifier,
7)
8from kwai.modules.training.trainings.training_definition_repository import (
9 TrainingDefinitionRepository,
10)
11from kwai.modules.training.trainings.training_repository import TrainingRepository
14@dataclass(kw_only=True, frozen=True, slots=True)
15class DeleteTrainingDefinitionCommand:
16 """Input for the use case DeleteTrainingDefinition."""
18 id: int
19 delete_trainings: bool = False
22class DeleteTrainingDefinition:
23 """Use case "Delete Training Definition".
25 When delete_trainings is True, Trainings that are related to this definition,
26 will be. When False, the training will be updated.
27 """
29 def __init__(
30 self, repo: TrainingDefinitionRepository, training_repo: TrainingRepository
31 ):
32 """Initialize the use case.
34 Args:
35 repo: A repository for deleting a training definition.
36 training_repo: A repository for deleting or updating a training(s).
37 """
38 self._repo = repo
39 self._training_repo = training_repo
41 async def execute(self, command: DeleteTrainingDefinitionCommand):
42 """Execute the use case.
44 Raises:
45 TrainingDefinitionNotFoundException: when the training definition
46 does not exist.
47 """
48 training_definition = await self._repo.get_by_id(
49 TrainingDefinitionIdentifier(command.id)
50 )
52 await self._training_repo.reset_definition(
53 training_definition, command.delete_trainings
54 )
56 await self._repo.delete(training_definition)