Coverage for functions \ flipdare \ generated \ model \ payment \ audit_info_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.util.time_util import TimeUtil 

27 

28 

29class AuditInfoKeys(StrEnum): 

30 UID = "uid" 

31 STAMP = "stamp" 

32 IP_ADDRESS = "ip_address" 

33 DEVICE_FINGERPRINT = "device_fingerprint" 

34 ENDPOINT = "endpoint" 

35 

36 

37class AuditInfoModel(AppBaseModel): 

38 """Internal Stripe Payment Audit Info Schema""" 

39 

40 model_config = ConfigDict(populate_by_name=True) 

41 

42 # The user ID associated with the payment event. 

43 uid: str 

44 stamp: float 

45 # The IP address associated with the payment event. 

46 ip_address: str 

47 # The device fingerprint associated with the payment event. 

48 device_fingerprint: str | None = None 

49 endpoint: str 

50 

51 @classmethod 

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

53 """ 

54 Uses Unpack to give you autocomplete and static warnings 

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

56 

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

58 """ 

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

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

61 if k in cls.__pydantic_fields__: 

62 field_info = cls.__pydantic_fields__[k] 

63 validated_value = cast( 

64 "Any", 

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

66 ) 

67 # Use alias if defined, otherwise use field name 

68 output_key = field_info.alias or k 

69 result[output_key] = validated_value 

70 return result 

71 

72 # ---- Convenience factories ----------------------------------------- 

73 

74 @classmethod 

75 def create( 

76 cls, 

77 uid: str, 

78 ip_address: str, 

79 device_fingerprint: str | None, 

80 endpoint: str, 

81 ) -> AuditInfoModel: 

82 return cls( 

83 uid=uid, 

84 stamp=TimeUtil.get_current_utc_float_time(), 

85 ip_address=ip_address, 

86 device_fingerprint=device_fingerprint, 

87 endpoint=endpoint, 

88 ) 

89 

90 

91AUDITINFO_FIELD_NAMES: list[str] = list(AuditInfoModel.model_fields.keys()) 

92 

93 

94class AuditInfoDict(TypedDict, total=False): 

95 uid: str 

96 stamp: float 

97 ip_address: str 

98 device_fingerprint: str | None 

99 endpoint: str