Coverage for fingerprint_server_sdk/models/geolocation.py: 70%

47 statements  

« prev     ^ index     » next       coverage.py v7.14.3, created at 2026-07-14 10:45 +0000

1""" 

2Server API 

3Fingerprint Server API allows you to get, search, and update Events in a server environment. It can be used for data exports, decision-making, and data analysis scenarios. 

4Server API is intended for server-side usage, it's not intended to be used from the client side, whether it's a browser or a mobile device. 

5The API also supports collection of Automation Intelligence for requests to your server in edge, pre-origin, or middleware contexts. 

6 

7The version of the OpenAPI document: 4 

8Contact: support@fingerprint.com 

9Generated by OpenAPI Generator (https://openapi-generator.tech) 

10 

11Do not edit the class manually. 

12""" # noqa: E501 

13 

14from __future__ import annotations 

15 

16import json 

17import pprint 

18import re # noqa: F401 

19from typing import Annotated, Any, ClassVar, Optional, Union 

20 

21from pydantic import BaseModel, ConfigDict, Field, StrictStr 

22from typing_extensions import Self 

23 

24from fingerprint_server_sdk.models.geolocation_subdivisions_inner import ( 

25 GeolocationSubdivisionsInner, 

26) 

27 

28 

29class Geolocation(BaseModel): 

30 """ 

31 Geolocation 

32 """ 

33 

34 accuracy_radius: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field( 

35 default=None, 

36 description='The IP address is likely to be within this radius (in km) of the specified location.', 

37 ) 

38 latitude: Optional[ 

39 Union[ 

40 Annotated[float, Field(le=90, strict=True, ge=-90)], 

41 Annotated[int, Field(le=90, strict=True, ge=-90)], 

42 ] 

43 ] = None 

44 longitude: Optional[ 

45 Union[ 

46 Annotated[float, Field(le=180, strict=True, ge=-180)], 

47 Annotated[int, Field(le=180, strict=True, ge=-180)], 

48 ] 

49 ] = None 

50 postal_code: Optional[StrictStr] = None 

51 timezone: Optional[StrictStr] = None 

52 city_name: Optional[StrictStr] = None 

53 country_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = None 

54 country_name: Optional[StrictStr] = None 

55 continent_code: Optional[Annotated[str, Field(min_length=2, strict=True, max_length=2)]] = None 

56 continent_name: Optional[StrictStr] = None 

57 subdivisions: Optional[list[GeolocationSubdivisionsInner]] = None 

58 __properties: ClassVar[list[str]] = [ 

59 'accuracy_radius', 

60 'latitude', 

61 'longitude', 

62 'postal_code', 

63 'timezone', 

64 'city_name', 

65 'country_code', 

66 'country_name', 

67 'continent_code', 

68 'continent_name', 

69 'subdivisions', 

70 ] 

71 

72 model_config = ConfigDict( 

73 populate_by_name=True, 

74 validate_assignment=True, 

75 protected_namespaces=(), 

76 ) 

77 

78 def to_str(self) -> str: 

79 """Returns the string representation of the model using alias""" 

80 return pprint.pformat(self.model_dump(by_alias=True)) 

81 

82 def to_json(self) -> str: 

83 """Returns the JSON representation of the model using alias""" 

84 # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead 

85 return json.dumps(self.to_dict()) 

86 

87 @classmethod 

88 def from_json(cls, json_str: str) -> Optional[Self]: 

89 """Create an instance of Geolocation from a JSON string""" 

90 return cls.from_dict(json.loads(json_str)) 

91 

92 def to_dict(self) -> dict[str, Any]: 

93 """Return the dictionary representation of the model using alias. 

94 

95 This has the following differences from calling pydantic's 

96 `self.model_dump(by_alias=True)`: 

97 

98 * `None` is only added to the output dict for nullable fields that 

99 were set at model initialization. Other fields with value `None` 

100 are ignored. 

101 """ 

102 excluded_fields: set[str] = set([]) 

103 

104 _dict = self.model_dump( 

105 by_alias=True, 

106 exclude=excluded_fields, 

107 exclude_none=True, 

108 ) 

109 # override the default output from pydantic by calling `to_dict()` of each item in subdivisions (list) 

110 _items = [] 

111 if self.subdivisions: 

112 for _item_subdivisions in self.subdivisions: 

113 if _item_subdivisions: 

114 _items.append(_item_subdivisions.to_dict()) 

115 _dict['subdivisions'] = _items 

116 return _dict 

117 

118 @classmethod 

119 def from_dict(cls, obj: Optional[dict[str, Any]]) -> Optional[Self]: 

120 """Create an instance of Geolocation from a dict""" 

121 if obj is None: 

122 return None 

123 

124 if not isinstance(obj, dict): 

125 return cls.model_validate(obj) 

126 

127 _obj = cls.model_validate( 

128 { 

129 'accuracy_radius': obj.get('accuracy_radius'), 

130 'latitude': obj.get('latitude'), 

131 'longitude': obj.get('longitude'), 

132 'postal_code': obj.get('postal_code'), 

133 'timezone': obj.get('timezone'), 

134 'city_name': obj.get('city_name'), 

135 'country_code': obj.get('country_code'), 

136 'country_name': obj.get('country_name'), 

137 'continent_code': obj.get('continent_code'), 

138 'continent_name': obj.get('continent_name'), 

139 'subdivisions': [ 

140 GeolocationSubdivisionsInner.from_dict(_item) for _item in obj['subdivisions'] 

141 ] 

142 if obj.get('subdivisions') is not None 

143 else None, 

144 } 

145 ) 

146 return _obj