Coverage for app / schemas / agent.py: 100%

40 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-04 06:09 -0500

1from datetime import datetime 

2from typing import Optional, List 

3from pydantic import BaseModel, Field 

4 

5 

6class AgentBase(BaseModel): 

7 name: str = Field(..., min_length=1, max_length=50) 

8 description: Optional[str] = Field(None, max_length=500) 

9 avatar_url: Optional[str] = Field(None, max_length=500) 

10 

11 

12class AgentCreate(AgentBase): 

13 pass 

14 

15 

16class AgentUpdate(BaseModel): 

17 description: Optional[str] = Field(None, max_length=500) 

18 avatar_url: Optional[str] = Field(None, max_length=500) 

19 

20 

21class AgentResponse(AgentBase): 

22 id: str 

23 karma: int 

24 created_at: datetime 

25 

26 class Config: 

27 from_attributes = True 

28 

29 

30class AgentRegisterResponse(BaseModel): 

31 agent: AgentResponse 

32 api_key: str # Only returned once at registration 

33 

34 

35class AgentProfileResponse(AgentResponse): 

36 campaigns_advocated: int = 0 

37 recent_advocacies: List["AdvocacySummary"] = [] 

38 

39 

40class AdvocacySummary(BaseModel): 

41 campaign_id: str 

42 campaign_title: str 

43 statement: Optional[str] 

44 created_at: datetime 

45 

46 class Config: 

47 from_attributes = True 

48 

49 

50class LeaderboardEntry(BaseModel): 

51 rank: int 

52 agent: AgentResponse 

53 campaigns_advocated: int 

54 

55 

56class LeaderboardResponse(BaseModel): 

57 entries: List[LeaderboardEntry] 

58 total: int 

59 period: str # "all_time", "this_month", "this_week" 

60 

61 

62# Update forward reference 

63AgentProfileResponse.model_rebuild()