Coverage for functions \ flipdare \ generated \ model \ content_model.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# 

3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

4# 

5# This file is part of Flipdare's proprietary software and contains 

6# confidential and copyrighted material. Unauthorised copying, 

7# modification, distribution, or use of this file is strictly 

8# prohibited without prior written permission from Flipdare Pty Ltd. 

9# 

10# This software includes third-party components licensed under MIT, 

11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

12# 

13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT. 

14# 

15# Generated by codegen_models.py 

16# 

17# Modify 'codegen_models.py' 

18# and re-run the script above to update. 

19# 

20# pragma: no cover 

21from __future__ import annotations 

22from datetime import datetime 

23from google.cloud.firestore_v1.transforms import Sentinel 

24from flipdare.core.firestore_field import FirestoreField 

25from flipdare.util.time_util import FirestoreTime 

26from typing import Any, TypedDict, cast, Unpack 

27from enum import StrEnum 

28from pydantic import Field, ConfigDict, TypeAdapter 

29from flipdare.firestore.core.app_base_model import AppBaseModel 

30from flipdare.generated.shared.model.model_obj_type import ModelObjType 

31from flipdare.generated.model.internal.view_stats_model import ViewStatsModel, ViewStatsDict 

32from flipdare.generated.model.internal.video_model import VideoModel, VideoDict 

33from flipdare.generated.model.internal.image_model import ImageModel, ImageDict 

34from typing import override 

35 

36 

37class ContentKeys(StrEnum): 

38 ID = "id" 

39 CREATED_AT = "created_at" 

40 UPDATED_AT = "updated_at" 

41 OBJ_ID = "obj_id" 

42 UID = "uid" 

43 OBJ_TYPE = "obj_type" 

44 VIEW_STATS = "view_stats" 

45 VIDEO = "video" 

46 IMAGE = "image" 

47 DESCRIPTION = "description" 

48 VERSION = "version" 

49 PROCESSED = "processed" 

50 ERROR_COUNT = "error_count" 

51 THUMBNAIL_CREATED = "thumbnail_created" 

52 HASH_CREATED = "hash_created" 

53 OPTIMIZED_VIDEO = "optimized_video" 

54 SEARCH_INDEXED = "search_indexed" 

55 

56 

57# !! IMPORTANT !! 

58# !! 

59# !! this should only be used in the database to query. 

60# !! 

61class ContentInternalKeys(StrEnum): 

62 CREATED_AT = "created_at" 

63 UPDATED_AT = "updated_at" 

64 VERSION = "VERSION" 

65 PROCESSED = "INT_P" 

66 ERROR_COUNT = "INT_E" 

67 THUMBNAIL_CREATED = "INT_C_T" 

68 HASH_CREATED = "INT_C_HG" 

69 OPTIMIZED_VIDEO = "INT_C_O" 

70 SEARCH_INDEXED = "INT_C_I" 

71 

72 

73class ContentModel(AppBaseModel): 

74 """User Content.""" 

75 

76 model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True) 

77 

78 id: str | None = Field(None, alias="id") 

79 created_at: FirestoreField = Field( 

80 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

81 ) 

82 updated_at: FirestoreField = Field( 

83 default_factory=cast("Any", lambda: FirestoreTime.server_timestamp()) 

84 ) 

85 obj_id: str 

86 uid: str 

87 obj_type: ModelObjType 

88 view_stats: ViewStatsModel = Field(default_factory=lambda: ViewStatsModel()) 

89 video: VideoModel | None = None 

90 image: ImageModel | None = None 

91 description: str | None = None 

92 # Version (base internal field) 

93 version: int = Field(default=1, alias="VERSION") 

94 # Processed (base internal field) 

95 processed: bool = Field(default=False, alias="INT_P") 

96 # Error Count (base internal field) 

97 error_count: int = Field(default=0, alias="INT_E") 

98 # Thumbnail Created (internal field) 

99 thumbnail_created: bool = Field(default=False, alias="INT_C_T") 

100 # Hash Created (internal field) 

101 hash_created: bool = Field(default=False, alias="INT_C_HG") 

102 # Optimized Video (internal field) 

103 optimized_video: bool = Field(default=False, alias="INT_C_O") 

104 # Search Indexed (internal field) 

105 search_indexed: bool = Field(default=False, alias="INT_C_I") 

106 

107 @classmethod 

108 def validate_partial(cls, **data: Unpack[ContentDict]) -> dict[str, Any]: 

109 """ 

110 Uses Unpack to give you autocomplete and static warnings 

111 if you pass an invalid key or type in your code. 

112 

113 Returns a dict with Firestore field names (aliases) for use with batch.update(). 

114 """ 

115 result: dict[str, Any] = {} 

116 for k, v in data.items(): 

117 if k in cls.__pydantic_fields__: 

118 field_info = cls.__pydantic_fields__[k] 

119 validated_value = cast( 

120 "Any", 

121 TypeAdapter(field_info.annotation).validate_python(v), 

122 ) 

123 # Use alias if defined, otherwise use field name 

124 output_key = field_info.alias or k 

125 result[output_key] = validated_value 

126 return result 

127 

128 # ---- Convenience factories ----------------------------------------- 

129 

130 @classmethod 

131 def create_image( 

132 cls, 

133 obj_id: str, 

134 image: ImageModel, 

135 is_user: bool = False, 

136 description: str | None = None, 

137 ) -> ContentModel: 

138 return cls( 

139 id=None, 

140 obj_id=obj_id, 

141 uid=image.source.uid, 

142 obj_type=ModelObjType.USER if is_user else ModelObjType.GROUP, 

143 image=image, 

144 video=None, 

145 description=description, 

146 ) 

147 

148 @classmethod 

149 def create_video( 

150 cls, 

151 obj_id: str, 

152 video: VideoModel, 

153 is_user: bool = False, 

154 description: str | None = None, 

155 ) -> ContentModel: 

156 return cls( 

157 id=None, 

158 obj_id=obj_id, 

159 uid=video.source.uid, 

160 obj_type=ModelObjType.USER if is_user else ModelObjType.GROUP, 

161 image=None, 

162 video=video, 

163 description=description, 

164 ) 

165 

166 # ---- Convenience predicates ----------------------------------------- 

167 @property 

168 @override 

169 def searchable_values(self) -> list[str]: 

170 return [self.description] if self.description is not None else [] 

171 

172 

173CONTENT_FIELD_NAMES: list[str] = list(ContentModel.model_fields.keys()) 

174 

175 

176class ContentDict(TypedDict, total=False): 

177 id: str | None 

178 created_at: Sentinel | datetime | str 

179 updated_at: Sentinel | datetime | str 

180 obj_id: str 

181 uid: str 

182 obj_type: ModelObjType 

183 view_stats: ViewStatsDict 

184 video: VideoDict | None 

185 image: ImageDict | None 

186 description: str | None 

187 VERSION: int | None 

188 INT_P: bool | None 

189 INT_E: int | None 

190 INT_C_T: bool | None 

191 INT_C_HG: bool | None 

192 INT_C_O: bool | None 

193 INT_C_I: bool | None