Coverage for kwai/modules/identity/users/user_account_repository.py: 100%

6 statements  

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

1"""Module that defines a repository for a user account.""" 

2from abc import abstractmethod 

3 

4from kwai.core.domain.value_objects.email_address import EmailAddress 

5from kwai.modules.identity.users.user_account import UserAccountEntity 

6 

7 

8class UserAccountRepository: 

9 """Interface for a user account repository.""" 

10 

11 @abstractmethod 

12 async def get_user_by_email(self, email: EmailAddress) -> UserAccountEntity: 

13 """Get a user account with the given email address.""" 

14 raise NotImplementedError 

15 

16 async def exists_with_email(self, email: EmailAddress) -> bool: 

17 """Check if a user account with the given email address already exists. 

18 

19 Args: 

20 email: The email address to check. 

21 

22 Returns: 

23 True when a user with the given email address exists. 

24 """ 

25 raise NotImplementedError 

26 

27 @abstractmethod 

28 async def create(self, user_account: UserAccountEntity) -> UserAccountEntity: 

29 """Save a new user account.""" 

30 raise NotImplementedError 

31 

32 @abstractmethod 

33 async def update(self, user_account: UserAccountEntity): 

34 """Save a user account.""" 

35 raise NotImplementedError 

36 

37 @abstractmethod 

38 async def delete(self, user_account): 

39 """Delete a user account.""" 

40 raise NotImplementedError 

41 

42 

43class UserAccountNotFoundException(Exception): 

44 """Raised when a user account cannot be found."""