Coverage for src/kwai/api/v1/auth/presenters.py: 60%

10 statements  

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

1"""Module that defines presenters for the auth api.""" 

2 

3from kwai.api.v1.auth.schemas.user_account import UserAccountDocument 

4from kwai.core.domain.presenter import AsyncPresenter, IterableResult 

5from kwai.core.json_api import JsonApiPresenter, Meta 

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

7 

8 

9class JsonApiUserAccountPresenter( 

10 JsonApiPresenter[UserAccountDocument], 

11 AsyncPresenter[IterableResult[UserAccountEntity]], 

12): 

13 """A presenter that transform a user account entity into a JSON:API document.""" 

14 

15 async def present(self, result: IterableResult[UserAccountEntity]) -> None: 

16 self._document = UserAccountDocument( 

17 meta=Meta(count=result.count, offset=result.offset, limit=result.limit), 

18 data=[], 

19 ) 

20 async for user_account in result.iterator: 

21 user_account_document = UserAccountDocument.create(user_account) 

22 self._document.merge(user_account_document)