Coverage for functions \ flipdare \ generated \ model \ search \ search_document_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.shared.search.search_obj_type import SearchObjType 

27 

28 

29class SearchDocumentKeys(StrEnum): 

30 OBJ_TYPE = "obj_type" 

31 MODEL = "model" 

32 

33 

34class SearchDocumentModel(AppBaseModel): 

35 """A search result document.""" 

36 

37 model_config = ConfigDict(populate_by_name=True) 

38 

39 obj_type: SearchObjType 

40 model: dict[str, Any] 

41 

42 @classmethod 

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

44 """ 

45 Uses Unpack to give you autocomplete and static warnings 

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

47 

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

49 """ 

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

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

52 if k in cls.__pydantic_fields__: 

53 field_info = cls.__pydantic_fields__[k] 

54 validated_value = cast( 

55 "Any", 

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

57 ) 

58 # Use alias if defined, otherwise use field name 

59 output_key = field_info.alias or k 

60 result[output_key] = validated_value 

61 return result 

62 

63 

64SEARCHDOCUMENT_FIELD_NAMES: list[str] = list(SearchDocumentModel.model_fields.keys()) 

65 

66 

67class SearchDocumentDict(TypedDict, total=False): 

68 obj_type: SearchObjType 

69 model: dict[str, Any]