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

9 statements  

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

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

2 

3from abc import abstractmethod 

4from collections.abc import AsyncGenerator 

5 

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

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

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

9from kwai.modules.identity.users.user_account_query import UserAccountQuery 

10 

11 

12class UserAccountRepository: 

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

14 

15 @abstractmethod 

16 async def get_all( 

17 self, 

18 query: UserAccountQuery | None = None, 

19 limit: int | None = None, 

20 offset: int | None = None, 

21 ) -> AsyncGenerator[UserAccountEntity, None]: 

22 """Return all user accounts. 

23 

24 Args: 

25 query: Query to filter user accounts. 

26 limit: The maximum number of entities to return. 

27 offset: Skip the offset rows before beginning to return entities. 

28 

29 Yields: 

30 A list of user account entities. 

31 """ 

32 raise NotImplementedError 

33 

34 @abstractmethod 

35 def create_query(self) -> UserAccountQuery: 

36 """Return a new user account query. 

37 

38 Returns: 

39 A query for user accounts. 

40 """ 

41 raise NotImplementedError 

42 

43 @abstractmethod 

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

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

46 

47 Raises: 

48 UserAccountNotFoundException: If no user account with the given email address exists. 

49 """ 

50 raise NotImplementedError 

51 

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

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

54 

55 Args: 

56 email: The email address to check. 

57 

58 Returns: 

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

60 """ 

61 raise NotImplementedError 

62 

63 @abstractmethod 

64 async def get_user_by_uuid(self, uuid: UniqueId) -> UserAccountEntity: 

65 """Get a user account using the unique id. 

66 

67 Raises: 

68 UserAccountNotFoundException: If no user account with the given uuid exists. 

69 """ 

70 raise NotImplementedError 

71 

72 @abstractmethod 

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

74 """Save a new user account.""" 

75 raise NotImplementedError 

76 

77 @abstractmethod 

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

79 """Save a user account.""" 

80 raise NotImplementedError 

81 

82 @abstractmethod 

83 async def delete(self, user_account): 

84 """Delete a user account.""" 

85 raise NotImplementedError 

86 

87 

88class UserAccountNotFoundException(Exception): 

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