Coverage for src/kwai/modules/portal/applications/application_repository.py: 100%

6 statements  

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

1"""Module that defines an interface for an application repository.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import AsyncIterator 

5 

6from kwai.modules.portal.applications.application import ( 

7 ApplicationEntity, 

8 ApplicationIdentifier, 

9) 

10from kwai.modules.portal.applications.application_query import ApplicationQuery 

11 

12 

13class ApplicationNotFoundException(Exception): 

14 """Raised when the application can not be found.""" 

15 

16 

17class ApplicationRepository(ABC): 

18 """An application repository interface.""" 

19 

20 @abstractmethod 

21 def create_query(self) -> ApplicationQuery: 

22 """Create a query for querying applications.""" 

23 raise NotImplementedError 

24 

25 @abstractmethod 

26 async def get_by_id(self, id_: ApplicationIdentifier) -> ApplicationEntity: 

27 """Get the application with the given id. 

28 

29 Args: 

30 id_: The id of the application. 

31 

32 Returns: 

33 An application entity. 

34 

35 Raises: 

36 ApplicationNotFoundException: when the application does not exist. 

37 """ 

38 raise NotImplementedError 

39 

40 @abstractmethod 

41 async def get_by_name(self, name: str) -> ApplicationEntity: 

42 """Get the application with the given name. 

43 

44 Args: 

45 name: The name of the application. 

46 

47 Returns: 

48 An application entity. 

49 

50 Raises: 

51 ApplicationNotFoundException: when the application with the given name 

52 does not exist. 

53 """ 

54 raise NotImplementedError 

55 

56 @abstractmethod 

57 async def get_all( 

58 self, 

59 query: ApplicationQuery | None = None, 

60 limit: int | None = None, 

61 offset: int | None = None, 

62 ) -> AsyncIterator[ApplicationEntity]: 

63 """Return all applications of a given query. 

64 

65 Args: 

66 query: The query to use for selecting the rows. 

67 limit: The maximum number of entities to return. 

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

69 

70 Yields: 

71 A list of applications. 

72 """ 

73 raise NotImplementedError 

74 

75 @abstractmethod 

76 async def create(self, application: ApplicationEntity) -> ApplicationEntity: 

77 """Create a new application entity. 

78 

79 Args: 

80 application: The application to create. 

81 """ 

82 raise NotImplementedError 

83 

84 @abstractmethod 

85 async def update(self, application: ApplicationEntity): 

86 """Update an application entity. 

87 

88 Args: 

89 application: The application to update. 

90 """ 

91 raise NotImplementedError 

92 

93 @abstractmethod 

94 async def delete(self, application: ApplicationEntity): 

95 """Delete an application entity. 

96 

97 Args: 

98 application: The application to delete. 

99 """ 

100 raise NotImplementedError