Coverage for src/kwai/modules/club/repositories/file_upload_preview_repository.py: 100%

13 statements  

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

1"""Module that defines a file upload repository that can be used for preview.""" 

2 

3from kwai.modules.club.domain.file_upload import FileUploadEntity 

4from kwai.modules.club.domain.member import MemberEntity 

5from kwai.modules.club.repositories.file_upload_repository import ( 

6 DuplicateMemberUploadedException, 

7 FileUploadRepository, 

8) 

9 

10 

11class FileUploadPreviewRepository(FileUploadRepository): 

12 """A file upload repository that can be used for preview. 

13 

14 This implementation doesn't save anything to the database. 

15 """ 

16 

17 def __init__(self): 

18 self._saved_members: dict[str, MemberEntity] = {} 

19 

20 async def create(self, file_upload: FileUploadEntity) -> FileUploadEntity: ... 

21 

22 def is_duplicate(self, member: MemberEntity) -> bool: 

23 return member.license.number in self._saved_members 

24 

25 async def save_member(self, file_upload: FileUploadEntity, member: MemberEntity): 

26 if self.is_duplicate(member): 

27 raise DuplicateMemberUploadedException( 

28 f"Member with license {member.license.number} is already uploaded." 

29 ) 

30 self._saved_members[member.license.number] = member