Coverage for kwai/modules/news/stories/story.py: 100%

55 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines a story entity.""" 

2from dataclasses import dataclass, field 

3 

4from kwai.core.domain.entity import Entity 

5from kwai.core.domain.value_objects.identifier import IntIdentifier 

6from kwai.core.domain.value_objects.local_timestamp import LocalTimestamp 

7from kwai.core.domain.value_objects.name import Name 

8from kwai.core.domain.value_objects.period import Period 

9from kwai.core.domain.value_objects.text import LocaleText 

10from kwai.core.domain.value_objects.traceable_time import TraceableTime 

11from kwai.core.domain.value_objects.unique_id import UniqueId 

12 

13StoryIdentifier = IntIdentifier 

14 

15 

16@dataclass(frozen=True, kw_only=True, slots=True) 

17class Promotion: 

18 """Value object for handling promoted news stories.""" 

19 

20 priority: int = 0 

21 end_date: LocalTimestamp = field(default_factory=LocalTimestamp) 

22 

23 

24@dataclass(frozen=True, kw_only=True, slots=True) 

25class Application: 

26 """Value object for an application.""" 

27 

28 id: IntIdentifier 

29 name: str 

30 title: str 

31 

32 

33@dataclass(frozen=True, kw_only=True, slots=True) 

34class Author: 

35 """Value object for an author of content.""" 

36 

37 id: IntIdentifier 

38 uuid: UniqueId 

39 name: Name 

40 

41 

42class StoryEntity(Entity[StoryIdentifier]): 

43 """A story entity.""" 

44 

45 def __init__( 

46 self, 

47 *, 

48 id_: StoryIdentifier | None = None, 

49 enabled: bool = False, 

50 promotion: Promotion = None, 

51 period: Period = None, 

52 application: Application, 

53 content: list[LocaleText], 

54 remark: str = "", 

55 traceable_time: TraceableTime | None = None, 

56 ): 

57 super().__init__(id_ or StoryIdentifier()) 

58 self._enabled = enabled 

59 self._promotion = promotion or Promotion() 

60 self._period = period or Period() 

61 self._application = application 

62 self._content = content 

63 self._remark = remark 

64 self._traceable_time = traceable_time or TraceableTime() 

65 

66 @property 

67 def is_enabled(self) -> bool: 

68 """Check if the story is enabled.""" 

69 return self._enabled 

70 

71 @property 

72 def promotion(self) -> Promotion: 

73 """Return the promotion information of the story.""" 

74 return self._promotion 

75 

76 @property 

77 def period(self) -> Period: 

78 """Return the active period of the story.""" 

79 return self._period 

80 

81 @property 

82 def remark(self) -> str: 

83 """Return the remark.""" 

84 return self._remark 

85 

86 @property 

87 def application(self) -> Application: 

88 """Return the application.""" 

89 return self._application 

90 

91 @property 

92 def content(self) -> list[LocaleText]: 

93 """Return the contents of the story. 

94 

95 Remark: 

96 The list is a copy 

97 """ 

98 return self._content.copy() 

99 

100 @property 

101 def traceable_time(self) -> TraceableTime: 

102 """Return the creation/modification timestamp of this application.""" 

103 return self._traceable_time