Coverage for src/kwai/api/v1/auth/schemas/user_account.py: 92%

12 statements  

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

1"""Schemas for a user account resource.""" 

2 

3from typing import Self 

4 

5from pydantic import BaseModel 

6 

7from kwai.api.v1.auth.schemas.resources import UserAccountResourceIdentifier 

8from kwai.core.json_api import Document, ResourceData 

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

10 

11 

12class UserAccountAttributes(BaseModel): 

13 """Attributes of a user account JSON:API resource.""" 

14 

15 email: str 

16 

17 

18class UserAccountResource( 

19 UserAccountResourceIdentifier, ResourceData[UserAccountAttributes, None] 

20): 

21 """A JSON:API resource for a user account.""" 

22 

23 

24class UserAccountDocument(Document[UserAccountResource, None]): 

25 """A JSON:API document for a user account.""" 

26 

27 @classmethod 

28 def create(cls, user_account: UserAccountEntity) -> Self: 

29 """Create a document for a user account.""" 

30 return cls( 

31 data=UserAccountResource( 

32 id=str(user_account.id), 

33 attributes=UserAccountAttributes(email=str(user_account.user.email)), 

34 ) 

35 )