Coverage for functions \ flipdare \ generated \ model \ internal \ tag_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.tag_type import TagType 

31 

32 

33class TagKeys(StrEnum): 

34 ID = "id" 

35 CREATED_AT = "created_at" 

36 UPDATED_AT = "updated_at" 

37 VALUE = "value" 

38 SEGMENTS = "segments" 

39 TAG_TYPE = "tag_type" 

40 COUNT = "count" 

41 

42 

43# !! IMPORTANT !! 

44# !! 

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

46# !! 

47class TagInternalKeys(StrEnum): 

48 CREATED_AT = "created_at" 

49 UPDATED_AT = "updated_at" 

50 

51 

52class TagModel(AppBaseModel): 

53 """Represents a tag that can be associated with users, groups, or dares.""" 

54 

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

56 

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

58 created_at: FirestoreField = Field( 

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

60 ) 

61 updated_at: FirestoreField = Field( 

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

63 ) 

64 value: str 

65 segments: list[str] 

66 tag_type: TagType 

67 count: int 

68 

69 @classmethod 

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

71 """ 

72 Uses Unpack to give you autocomplete and static warnings 

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

74 

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

76 """ 

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

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

79 if k in cls.__pydantic_fields__: 

80 field_info = cls.__pydantic_fields__[k] 

81 validated_value = cast( 

82 "Any", 

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

84 ) 

85 # Use alias if defined, otherwise use field name 

86 output_key = field_info.alias or k 

87 result[output_key] = validated_value 

88 return result 

89 

90 

91TAG_FIELD_NAMES: list[str] = list(TagModel.model_fields.keys()) 

92 

93 

94class TagDict(TypedDict, total=False): 

95 id: str | None 

96 created_at: Sentinel | datetime | str 

97 updated_at: Sentinel | datetime | str 

98 value: str 

99 segments: list[str] 

100 tag_type: TagType 

101 count: int