Coverage for functions \ flipdare \ generated \ model \ internal \ exchange_rate_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.stripe.stripe_currency_code import StripeCurrencyCode 

31 

32 

33class ExchangeRateKeys(StrEnum): 

34 ID = "id" 

35 UPDATED_AT = "updated_at" 

36 CREATED_AT = "created_at" 

37 BASE_CURRENCY = "base_currency" 

38 TARGET_CURRENCY = "target_currency" 

39 RATE = "rate" 

40 

41 

42# !! IMPORTANT !! 

43# !! 

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

45# !! 

46class ExchangeRateInternalKeys(StrEnum): 

47 UPDATED_AT = "updated_at" 

48 CREATED_AT = "created_at" 

49 

50 

51class ExchangeRateModel(AppBaseModel): 

52 """Stores daily exchange rates.""" 

53 

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

55 

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

57 updated_at: FirestoreField = Field( 

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

59 ) 

60 created_at: FirestoreField = Field( 

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

62 ) 

63 base_currency: StripeCurrencyCode 

64 target_currency: StripeCurrencyCode 

65 rate: float 

66 

67 @classmethod 

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

69 """ 

70 Uses Unpack to give you autocomplete and static warnings 

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

72 

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

74 """ 

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

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

77 if k in cls.__pydantic_fields__: 

78 field_info = cls.__pydantic_fields__[k] 

79 validated_value = cast( 

80 "Any", 

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

82 ) 

83 # Use alias if defined, otherwise use field name 

84 output_key = field_info.alias or k 

85 result[output_key] = validated_value 

86 return result 

87 

88 

89EXCHANGERATE_FIELD_NAMES: list[str] = list(ExchangeRateModel.model_fields.keys()) 

90 

91 

92class ExchangeRateDict(TypedDict, total=False): 

93 id: str | None 

94 updated_at: Sentinel | datetime | str 

95 created_at: Sentinel | datetime | str 

96 base_currency: StripeCurrencyCode 

97 target_currency: StripeCurrencyCode 

98 rate: float