Coverage for functions \ flipdare \ generated \ model \ backend \ email \ public_image_link_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 typing import Any, TypedDict, cast, Unpack 

23from enum import StrEnum 

24from pydantic import ConfigDict, TypeAdapter 

25from flipdare.firestore.core.app_base_model import AppBaseModel 

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

27from flipdare.util.scaled_image import ScaledImageType 

28 

29 

30class PublicImageLinkKeys(StrEnum): 

31 IMAGE = "image" 

32 PUBLIC_URL = "public_url" 

33 

34 

35class PublicImageLinkModel(AppBaseModel): 

36 """This is used in emails for public images.""" 

37 

38 model_config = ConfigDict(populate_by_name=True) 

39 

40 image: ImageModel 

41 public_url: str 

42 

43 @classmethod 

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

45 """ 

46 Uses Unpack to give you autocomplete and static warnings 

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

48 

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

50 """ 

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

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

53 if k in cls.__pydantic_fields__: 

54 field_info = cls.__pydantic_fields__[k] 

55 validated_value = cast( 

56 "Any", 

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

58 ) 

59 # Use alias if defined, otherwise use field name 

60 output_key = field_info.alias or k 

61 result[output_key] = validated_value 

62 return result 

63 

64 # ---- Convenience predicates ----------------------------------------- 

65 @property 

66 def scaled_width(self) -> int: 

67 scaled_dimensions = self.image.scaled(ScaledImageType.EMAIL) 

68 return scaled_dimensions[0] 

69 

70 @property 

71 def scaled_height(self) -> int: 

72 scaled_dimensions = self.image.scaled(ScaledImageType.EMAIL) 

73 return scaled_dimensions[1] 

74 

75 

76PUBLICIMAGELINK_FIELD_NAMES: list[str] = list(PublicImageLinkModel.model_fields.keys()) 

77 

78 

79class PublicImageLinkDict(TypedDict, total=False): 

80 image: ImageDict 

81 public_url: str