Coverage for kwai/modules/identity/delete_user_invitation.py: 100%

12 statements  

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

1"""Implement the use case: delete a user invitation.""" 

2from dataclasses import dataclass 

3 

4from kwai.core.domain.value_objects.unique_id import UniqueId 

5from kwai.modules.identity.user_invitations.user_invitation_repository import ( 

6 UserInvitationRepository, 

7) 

8 

9 

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

11class DeleteUserInvitationCommand: 

12 """Input for the use case. 

13 

14 [DeleteUserInvitation][kwai.modules.identity.delete_user_invitation.DeleteUserInvitation] 

15 

16 Attributes: 

17 uuid: The unique id of the user invitation. 

18 """ 

19 

20 uuid: str 

21 

22 

23class DeleteUserInvitation: 

24 """Implements the use case 'delete a user invitation'.""" 

25 

26 def __init__(self, user_invitation_repo: UserInvitationRepository): 

27 """Initialize the use case. 

28 

29 Args: 

30 user_invitation_repo: A repository for deleting the user invitation. 

31 """ 

32 self._user_invitation_repo = user_invitation_repo 

33 

34 async def execute(self, command: DeleteUserInvitationCommand): 

35 """Execute the use case. 

36 

37 Args: 

38 command: The input for this use case. 

39 

40 Raises: 

41 UserInvitationNotFoundException: Raised when then invitation is not found. 

42 """ 

43 entity = await self._user_invitation_repo.get_invitation_by_uuid( 

44 UniqueId.create_from_string(command.uuid) 

45 ) 

46 await self._user_invitation_repo.delete(entity)