m-car-api 1.2.0__tar.gz → 1.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: m_car_api
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Home-page: https://github.com/cbrand/m_car_api
5
5
  Author: Christoph Brand
6
6
  Author-email: christoph@brand.rest
@@ -26,6 +26,7 @@ Requires-Dist: coverage<7,>=5.1; extra == "test"
26
26
  Requires-Dist: faker<19,>=18; extra == "test"
27
27
  Requires-Dist: flake8<6,>=5.0.4; extra == "test"
28
28
  Requires-Dist: mypy>=0.961; extra == "test"
29
+ Requires-Dist: types-requests; extra == "test"
29
30
  Requires-Dist: pre-commit<4,>=3; extra == "test"
30
31
  Requires-Dist: pytest-cases<4,>=3.1.1; extra == "test"
31
32
  Requires-Dist: pytest-html; extra == "test"
@@ -41,3 +42,12 @@ Provides-Extra: pydantic-2
41
42
  Requires-Dist: pydantic<3,>=2; extra == "pydantic-2"
42
43
  Provides-Extra: pyproj
43
44
  Requires-Dist: pyproj; extra == "pyproj"
45
+ Dynamic: author
46
+ Dynamic: author-email
47
+ Dynamic: classifier
48
+ Dynamic: home-page
49
+ Dynamic: license
50
+ Dynamic: project-url
51
+ Dynamic: provides-extra
52
+ Dynamic: requires-dist
53
+ Dynamic: requires-python
@@ -26,7 +26,7 @@ def get_package_dir() -> Dict[str, str]:
26
26
  return {"": "src"}
27
27
 
28
28
 
29
- __version__ = "1.2.0"
29
+ __version__ = "1.2.2"
30
30
  requirements = ["requests", "mujson", "pydantic"]
31
31
  pydantic_1 = ["pydantic>=1,<2", "pydantic_computed"]
32
32
  pydantic_2 = ["pydantic>=2,<3"]
@@ -37,6 +37,7 @@ test_requirements = [
37
37
  "faker>=18,<19",
38
38
  "flake8>=5.0.4,<6",
39
39
  "mypy>=0.961",
40
+ "types-requests",
40
41
  "pre-commit>=3,<4",
41
42
  "pytest-cases>=3.1.1,<4",
42
43
  "pytest-html",
@@ -1,9 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  try:
4
- import mujson
4
+ import mujson # type: ignore[import-untyped]
5
5
  except ImportError:
6
- import json as mujson
6
+ import json as mujson # type: ignore[no-redef]
7
7
  import requests
8
8
  from urllib.parse import urljoin
9
9
 
@@ -69,7 +69,7 @@ class VehiclesSearchAPI(SubAPI):
69
69
  payload = mujson.loads(self.raw_json_response())
70
70
  result = parse_vehicles_payload(payload)
71
71
  if result.result != "OK":
72
- raise ValueError(result.message)
72
+ raise ValueError(result.response_text)
73
73
  return result.data
74
74
 
75
75
 
@@ -1,15 +1,13 @@
1
1
  from __future__ import annotations
2
- from typing import Tuple
2
+ from typing import Any, Tuple
3
3
 
4
4
 
5
+ geod: Any
5
6
  try:
6
- from pyproj import Geod
7
+ from pyproj import Geod # type: ignore[import-not-found, unused-ignore]
7
8
 
8
9
  geod = Geod(ellps="WGS84")
9
10
  except ImportError:
10
-
11
- class Geod: ...
12
-
13
11
  geod = None
14
12
 
15
13
 
@@ -23,7 +21,7 @@ def get_bounding_box(
23
21
 
24
22
 
25
23
  def _geod_get_bounding_box(
26
- geod: Geod, lat: float, lon: float, meters: float
24
+ geod: Any, lat: float, lon: float, meters: float
27
25
  ) -> Tuple[float, float, float, float]:
28
26
  lon_top_left, lat_top_left, _ = geod.fwd(lon, lat, 315, meters)
29
27
  lon_bottom_right, lat_bottom_right, _ = geod.fwd(lon, lat, 135, meters)
@@ -1,8 +1,10 @@
1
1
  # flake8: noqa: F401
2
2
 
3
+ from typing import TYPE_CHECKING
4
+
3
5
  from pydantic.version import VERSION
4
6
 
5
- if VERSION.startswith("1."):
7
+ if not TYPE_CHECKING and VERSION.startswith("1."):
6
8
  from m_car_api.objects_pydantic_1 import (
7
9
  DeviceInfo,
8
10
  Vehicle,
@@ -1,10 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
- import mujson
3
+ import mujson # type: ignore[import-untyped]
4
4
  from datetime import datetime
5
5
  from typing import Any, Generic, Literal, NamedTuple, TypeVar
6
6
  from pydantic import BaseModel, Field
7
- from pydantic_computed import computed, Computed
7
+ from pydantic_computed import ( # type: ignore[import-untyped]
8
+ computed,
9
+ Computed,
10
+ )
8
11
 
9
12
 
10
13
  def parse_vehicles_payload(payload: Any) -> VehiclesAPIReturn:
@@ -86,23 +89,23 @@ class VehicleQuery(NamedTuple):
86
89
 
87
90
 
88
91
  class RentalPrice(BaseModel):
89
- price: str
90
- unit: str
92
+ price: str | None = None
93
+ unit: str | None = None
91
94
  discounted: bool = False
92
- description: str = ""
95
+ description: str | None = ""
93
96
  discount_source: str | None = None
94
97
 
95
98
 
96
99
  class ParkingPrice(BaseModel):
97
- price: str
98
- unit: str
100
+ price: str | None = None
101
+ unit: str | None = None
99
102
  discounted: bool = False
100
103
 
101
104
 
102
105
  class UnlockFee(BaseModel):
103
- price: str
104
- unit: str
105
- discounted: bool
106
+ price: str | None = None
107
+ unit: str | None = None
108
+ discounted: bool = False
106
109
 
107
110
 
108
111
  class Destination(BaseModel):
@@ -111,31 +114,33 @@ class Destination(BaseModel):
111
114
 
112
115
  class DestinationWithPrice(Destination):
113
116
  city_id: str = Field(alias="idCity")
114
- price: str = Field(alias="Price")
115
- price_discounted: str | None = Field(alias="Price_discounted")
117
+ price: str | None = Field(default=None, alias="Price")
118
+ price_discounted: str | None = Field(default=None, alias="Price_discounted")
116
119
 
117
120
 
118
121
  class CityToCityOptions(BaseModel):
119
122
  origin_city: str = Field(alias="OriginCity")
120
123
  destinations_raw: list[DestinationWithPrice] | None = Field(
121
- alias="Destinations", exclude=True
124
+ default=None, alias="Destinations", exclude=True
122
125
  )
123
126
 
124
127
  destinations: Computed[list[DestinationWithPrice]]
125
128
 
126
129
  @computed("destinations")
130
+ @staticmethod
127
131
  def compute_destinations(
128
132
  destinations_raw: list[DestinationWithPrice] | None, **kwargs: Any
129
133
  ) -> list[DestinationWithPrice]:
130
134
  return destinations_raw or []
131
135
 
132
136
  not_possible_destinations_raw: list[Destination] | None = Field(
133
- alias="NotPossibleDestinations", exclude=True
137
+ default=None, alias="NotPossibleDestinations", exclude=True
134
138
  )
135
139
 
136
140
  not_possible_destinations: Computed[list[Destination]]
137
141
 
138
142
  @computed("not_possible_destinations")
143
+ @staticmethod
139
144
  def compute_not_possible_destinations(
140
145
  not_possible_destinations_raw: list[Destination] | None, **kwargs: Any
141
146
  ) -> list[Destination]:
@@ -146,36 +151,47 @@ class Vehicle(BaseModel):
146
151
  id: int = Field(alias="idVehicle")
147
152
  city_id: str = Field(alias="idCity")
148
153
  license_plate: str = Field(alias="LicensePlate")
149
- type: str = Field(alias="VehicleType")
150
- color: str = Field(alias="VehicleColor")
154
+ type: str | None = Field(default=None, alias="VehicleType")
155
+ color: str | None = Field(default=None, alias="VehicleColor")
151
156
  size: Literal["S", "M", "L", "X", "P"] = Field(alias="VehicleSize")
152
157
  electric: bool = Field(alias="isElectric")
153
158
  latitude: float = Field(alias="Latitude")
154
159
  longitude: float = Field(alias="Longitude")
155
- distance_from_user_position: float = Field(alias="DistanceFromUserPosition")
156
- distance_from_middle_position: float = Field(alias="DistanceFromMiddlePosition")
160
+ distance_from_user_position: float | None = Field(
161
+ default=None, alias="DistanceFromUserPosition"
162
+ )
163
+ distance_from_middle_position: float | None = Field(
164
+ default=None, alias="DistanceFromMiddlePosition"
165
+ )
157
166
  status: str = Field(alias="idVehicleStatus")
158
- gsm_coverage: int = Field(alias="GSMCoverage")
159
- satellite_number: int = Field(alias="SatelliteNumber")
167
+ gsm_coverage: int | None = Field(default=None, alias="GSMCoverage")
168
+ satellite_number: int | None = Field(default=None, alias="SatelliteNumber")
160
169
 
161
- rental_price_row_1: str = Field(alias="RentalPrice_row1", exclude=True)
162
- rental_price_row_1_unit: str = Field(alias="RentalPrice_row1unit", exclude=True)
170
+ rental_price_row_1: str | None = Field(
171
+ default=None, alias="RentalPrice_row1", exclude=True
172
+ )
173
+ rental_price_row_1_unit: str | None = Field(
174
+ default=None, alias="RentalPrice_row1unit", exclude=True
175
+ )
163
176
  rental_price_discounted: str | None = Field(
164
- alias="RentalPrice_discounted", exclude=True
177
+ default=None, alias="RentalPrice_discounted", exclude=True
178
+ )
179
+ rental_price_row_2: str | None = Field(
180
+ default=None, alias="RentalPrice_row2", exclude=True
165
181
  )
166
- rental_price_row_2: str = Field(alias="RentalPrice_row2", exclude=True)
167
182
  rental_price_discount_source: str | None = Field(
168
- alias="RentalPrice_discountSource", exclude=True
183
+ default=None, alias="RentalPrice_discountSource", exclude=True
169
184
  )
170
185
 
171
186
  rental_price: Computed[RentalPrice]
172
187
 
173
188
  @computed("rental_price")
189
+ @staticmethod
174
190
  def compute_rental_price(
175
- rental_price_row_1: str,
176
- rental_price_row_1_unit: str,
191
+ rental_price_row_1: str | None,
192
+ rental_price_row_1_unit: str | None,
177
193
  rental_price_discounted: str | None,
178
- rental_price_row_2: str,
194
+ rental_price_row_2: str | None,
179
195
  rental_price_discount_source: str | None,
180
196
  **kwargs: Any,
181
197
  ) -> RentalPrice:
@@ -187,18 +203,23 @@ class Vehicle(BaseModel):
187
203
  discount_source=rental_price_discount_source,
188
204
  )
189
205
 
190
- parking_price_item: str = Field(alias="ParkingPrice", exclude=True)
206
+ parking_price_item: str | None = Field(
207
+ default=None, alias="ParkingPrice", exclude=True
208
+ )
191
209
  parking_price_discounted: bool | str | None = Field(
192
- alias="ParkingPrice_discounted", exclude=True
210
+ default=None, alias="ParkingPrice_discounted", exclude=True
211
+ )
212
+ parking_price_unit: str | None = Field(
213
+ default=None, alias="ParkingPrice_unit", exclude=True
193
214
  )
194
- parking_price_unit: str = Field(alias="ParkingPrice_unit", exclude=True)
195
215
 
196
216
  parking_price: Computed[ParkingPrice]
197
217
 
198
218
  @computed("parking_price")
219
+ @staticmethod
199
220
  def compute_parking_price(
200
- parking_price_item: str,
201
- parking_price_unit: str,
221
+ parking_price_item: str | None,
222
+ parking_price_unit: str | None,
202
223
  parking_price_discounted: bool | str | None,
203
224
  **kwargs: Any,
204
225
  ) -> ParkingPrice:
@@ -208,18 +229,21 @@ class Vehicle(BaseModel):
208
229
  discounted=bool(parking_price_discounted),
209
230
  )
210
231
 
211
- unlock_fee_item: str = Field(alias="UnlockFee", exclude=True)
232
+ unlock_fee_item: str | None = Field(default=None, alias="UnlockFee", exclude=True)
212
233
  unlock_fee_discounted: str | None = Field(
213
- alias="UnlockFee_discounted", exclude=True
234
+ default=None, alias="UnlockFee_discounted", exclude=True
235
+ )
236
+ unlock_fee_unit: str | None = Field(
237
+ default=None, alias="UnlockFee_unit", exclude=True
214
238
  )
215
- unlock_fee_unit: str = Field(alias="UnlockFee_unit", exclude=True)
216
239
 
217
240
  unlock_fee: Computed[UnlockFee]
218
241
 
219
242
  @computed("unlock_fee")
243
+ @staticmethod
220
244
  def compute_unlock_fee(
221
- unlock_fee_item: str,
222
- unlock_fee_unit: str,
245
+ unlock_fee_item: str | None,
246
+ unlock_fee_unit: str | None,
223
247
  unlock_fee_discounted: str | None,
224
248
  **kwargs: Any,
225
249
  ) -> UnlockFee:
@@ -229,72 +253,88 @@ class Vehicle(BaseModel):
229
253
  discounted=bool(unlock_fee_discounted),
230
254
  )
231
255
 
232
- fuel_percent: str = Field(alias="FuelPct")
233
- fuel_level_icon: int = Field(alias="FuelLevelIcon")
234
- remaining_range: str = Field(alias="RemainingRange")
235
- ev_plugged: bool = Field(alias="EVPlugged")
236
- fvd_price: str = Field(alias="FVDPrice")
237
- url_vehicle_image: str = Field(alias="URLVehicleImage")
238
- rookie_delay_txt: str = Field(alias="RookieDelayTxt")
239
- number_days_rookies_delay: int = Field(alias="nDaysRookieDelay")
240
- premium_restricted_txt: str = Field(alias="PremiumRestrictedTxt")
256
+ fuel_percent: str | None = Field(default=None, alias="FuelPct")
257
+ fuel_level_icon: int | None = Field(default=None, alias="FuelLevelIcon")
258
+ remaining_range: str | None = Field(default=None, alias="RemainingRange")
259
+ ev_plugged: bool | None = Field(default=None, alias="EVPlugged")
260
+ fvd_price: str | None = Field(default=None, alias="FVDPrice")
261
+ url_vehicle_image: str | None = Field(default=None, alias="URLVehicleImage")
262
+ rookie_delay_txt: str | None = Field(default=None, alias="RookieDelayTxt")
263
+ number_days_rookies_delay: int | None = Field(
264
+ default=None, alias="nDaysRookieDelay"
265
+ )
266
+ premium_restricted_txt: str | None = Field(
267
+ default=None, alias="PremiumRestrictedTxt"
268
+ )
241
269
  city_to_city_options_string: str | None = Field(
242
- alias="CityToCityOptions", exclude=True
270
+ default=None, alias="CityToCityOptions", exclude=True
243
271
  )
244
272
 
245
- city_to_city_options: Computed[CityToCityOptions]
273
+ city_to_city_options: Computed[CityToCityOptions | None]
246
274
 
247
275
  @computed("city_to_city_options")
276
+ @staticmethod
248
277
  def compute_city_to_city_options(
249
- city_to_city_options_string: str, **kwargs: Any
250
- ) -> CityToCityOptions:
278
+ city_to_city_options_string: str | None, **kwargs: Any
279
+ ) -> CityToCityOptions | None:
280
+ if not city_to_city_options_string:
281
+ return None
251
282
  payload = mujson.loads(city_to_city_options_string)
252
283
  return CityToCityOptions.parse_obj(payload)
253
284
 
254
285
  json_vehicle_damages_input: str | None = Field(
255
- alias="JSONVehicleDamages", exclude=True
286
+ default=None, alias="JSONVehicleDamages", exclude=True
256
287
  )
257
288
 
258
289
  json_vehicle_damages: Computed[list[dict[str, Any]]]
259
290
 
260
291
  @computed("json_vehicle_damages")
292
+ @staticmethod
261
293
  def compute_json_vehicle_damages(
262
294
  json_vehicle_damages_input: str | None, **kwargs: Any
263
295
  ) -> list[dict[str, Any]]:
264
- if json_vehicle_damages_input is None:
296
+ if not json_vehicle_damages_input:
265
297
  return []
266
298
  else:
267
299
  return mujson.loads(json_vehicle_damages_input)
268
300
 
269
- json_vehicle_banner: str | None = Field(alias="JSONVehicleBanner")
301
+ json_vehicle_banner: str | None = Field(default=None, alias="JSONVehicleBanner")
270
302
 
271
303
 
272
304
  class VehicleResponse(BaseModel):
273
305
  result: str = Field(alias="Result")
274
- response_text: str | None = Field(alias="ResponseText")
275
- id_vehicle_booked: str | None = Field(alias="idVehicleBooked")
276
- id_ride: str | None = Field(alias="idRide")
277
- id_vehicle_in_ride: str | None = Field(alias="idVehicleInRide")
278
- nearest_id_city: str | None = Field(alias="NearestIdCity")
279
- live_payment: bool = Field(alias="LivePayment")
280
- top_up_required: bool = Field(alias="TopUpRequired")
281
- user_app_version: str | float = Field(alias="userAppVersion")
282
- n_filter_elements: int = Field(alias="nFilterElements")
283
- user_in_ops_mode: bool = Field(alias="UserInOpsMode")
284
- special_airport_rate: str | None = Field(alias="SpecialAirportRate")
285
- special_airport_rate_e: str | None = Field(alias="SpecialAirportRate_E")
286
- special_airport_rate_2: str | None = Field(alias="SpecialAirportRate_2")
287
- special_airport_rate_e_2: str | None = Field(alias="SpecialAirportRate_E_2")
288
- uses_ppc: bool = Field(alias="UsesPPC")
289
- current_subscription: str | None = Field(alias="CurrentSubscription")
290
- json_city_areas: str = Field(alias="JSONCityAreas")
291
- city_areas_timestamp: datetime = Field(alias="CityAreasTimestamp")
292
- additional_info: str = Field(alias="AdditionalInfo")
306
+ response_text: str | None = Field(default=None, alias="ResponseText")
307
+ id_vehicle_booked: str | None = Field(default=None, alias="idVehicleBooked")
308
+ id_ride: str | None = Field(default=None, alias="idRide")
309
+ id_vehicle_in_ride: str | None = Field(default=None, alias="idVehicleInRide")
310
+ nearest_id_city: str | None = Field(default=None, alias="NearestIdCity")
311
+ live_payment: bool | None = Field(default=None, alias="LivePayment")
312
+ top_up_required: bool | None = Field(default=None, alias="TopUpRequired")
313
+ user_app_version: str | float | None = Field(default=None, alias="userAppVersion")
314
+ n_filter_elements: int | None = Field(default=None, alias="nFilterElements")
315
+ user_in_ops_mode: bool | None = Field(default=None, alias="UserInOpsMode")
316
+ special_airport_rate: str | None = Field(default=None, alias="SpecialAirportRate")
317
+ special_airport_rate_e: str | None = Field(
318
+ default=None, alias="SpecialAirportRate_E"
319
+ )
320
+ special_airport_rate_2: str | None = Field(
321
+ default=None, alias="SpecialAirportRate_2"
322
+ )
323
+ special_airport_rate_e_2: str | None = Field(
324
+ default=None, alias="SpecialAirportRate_E_2"
325
+ )
326
+ uses_ppc: bool | None = Field(default=None, alias="UsesPPC")
327
+ current_subscription: str | None = Field(default=None, alias="CurrentSubscription")
328
+ json_city_areas: str | None = Field(default=None, alias="JSONCityAreas")
329
+ city_areas_timestamp: datetime | None = Field(
330
+ default=None, alias="CityAreasTimestamp"
331
+ )
332
+ additional_info: str | None = Field(default=None, alias="AdditionalInfo")
293
333
 
294
334
 
295
335
  class VehicleReturn(BaseModel):
296
- response: VehicleResponse = Field(alias="response")
297
- vehicles: list[Vehicle] = Field(alias="vehicles")
336
+ response: VehicleResponse | None = Field(default=None, alias="response")
337
+ vehicles: list[Vehicle] = Field(default_factory=list, alias="vehicles")
298
338
 
299
339
 
300
340
  APIData = TypeVar("APIData")
@@ -302,7 +342,7 @@ APIData = TypeVar("APIData")
302
342
 
303
343
  class APIReturn(BaseModel, Generic[APIData]):
304
344
  result: str = Field(alias="Result")
305
- response_text: str | None = Field(alias="ResponseText")
345
+ response_text: str | None = Field(default=None, alias="ResponseText")
306
346
  data: APIData = Field(alias="Data")
307
347
 
308
348
 
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- import mujson
3
+ import mujson # type: ignore[import-untyped]
4
4
  from datetime import datetime
5
5
  from typing import Any, Generic, Literal, NamedTuple, TypeVar
6
6
  from pydantic import BaseModel, Field, computed_field
@@ -85,23 +85,23 @@ class VehicleQuery(NamedTuple):
85
85
 
86
86
 
87
87
  class RentalPrice(BaseModel):
88
- price: str
89
- unit: str
88
+ price: str | None = None
89
+ unit: str | None = None
90
90
  discounted: bool = False
91
- description: str = ""
91
+ description: str | None = ""
92
92
  discount_source: str | None = None
93
93
 
94
94
 
95
95
  class ParkingPrice(BaseModel):
96
- price: str
97
- unit: str
96
+ price: str | None = None
97
+ unit: str | None = None
98
98
  discounted: bool = False
99
99
 
100
100
 
101
101
  class UnlockFee(BaseModel):
102
- price: str
103
- unit: str
104
- discounted: bool
102
+ price: str | None = None
103
+ unit: str | None = None
104
+ discounted: bool = False
105
105
 
106
106
 
107
107
  class Destination(BaseModel):
@@ -110,27 +110,25 @@ class Destination(BaseModel):
110
110
 
111
111
  class DestinationWithPrice(Destination):
112
112
  city_id: str = Field(alias="idCity")
113
- price: str = Field(alias="Price")
114
- price_discounted: str | None = Field(alias="Price_discounted")
113
+ price: str | None = Field(default=None, alias="Price")
114
+ price_discounted: str | None = Field(default=None, alias="Price_discounted")
115
115
 
116
116
 
117
117
  class CityToCityOptions(BaseModel):
118
118
  origin_city: str = Field(alias="OriginCity")
119
119
  destinations_raw: list[DestinationWithPrice] | None = Field(
120
- alias="Destinations", exclude=True
120
+ default=None, alias="Destinations", exclude=True
121
121
  )
122
122
 
123
123
  @property
124
- @computed_field
125
124
  def destinations(self) -> list[DestinationWithPrice]:
126
125
  return self.destinations_raw or []
127
126
 
128
127
  not_possible_destinations_raw: list[Destination] | None = Field(
129
- alias="NotPossibleDestinations", exclude=True
128
+ default=None, alias="NotPossibleDestinations", exclude=True
130
129
  )
131
130
 
132
131
  @property
133
- @computed_field
134
132
  def not_possible_destinations(self) -> list[Destination]:
135
133
  return self.not_possible_destinations_raw or []
136
134
 
@@ -139,29 +137,39 @@ class Vehicle(BaseModel):
139
137
  id: int = Field(alias="idVehicle")
140
138
  city_id: str = Field(alias="idCity")
141
139
  license_plate: str = Field(alias="LicensePlate")
142
- type: str = Field(alias="VehicleType")
143
- color: str = Field(alias="VehicleColor")
140
+ type: str | None = Field(default=None, alias="VehicleType")
141
+ color: str | None = Field(default=None, alias="VehicleColor")
144
142
  size: Literal["S", "M", "L", "X", "P"] = Field(alias="VehicleSize")
145
143
  electric: bool = Field(alias="isElectric")
146
144
  latitude: float = Field(alias="Latitude")
147
145
  longitude: float = Field(alias="Longitude")
148
- distance_from_user_position: float = Field(alias="DistanceFromUserPosition")
149
- distance_from_middle_position: float = Field(alias="DistanceFromMiddlePosition")
146
+ distance_from_user_position: float | None = Field(
147
+ default=None, alias="DistanceFromUserPosition"
148
+ )
149
+ distance_from_middle_position: float | None = Field(
150
+ default=None, alias="DistanceFromMiddlePosition"
151
+ )
150
152
  status: str = Field(alias="idVehicleStatus")
151
- gsm_coverage: int = Field(alias="GSMCoverage")
152
- satellite_number: int = Field(alias="SatelliteNumber")
153
+ gsm_coverage: int | None = Field(default=None, alias="GSMCoverage")
154
+ satellite_number: int | None = Field(default=None, alias="SatelliteNumber")
153
155
 
154
- rental_price_row_1: str = Field(alias="RentalPrice_row1", exclude=True)
155
- rental_price_row_1_unit: str = Field(alias="RentalPrice_row1unit", exclude=True)
156
+ rental_price_row_1: str | None = Field(
157
+ default=None, alias="RentalPrice_row1", exclude=True
158
+ )
159
+ rental_price_row_1_unit: str | None = Field(
160
+ default=None, alias="RentalPrice_row1unit", exclude=True
161
+ )
156
162
  rental_price_discounted: str | None = Field(
157
- alias="RentalPrice_discounted", exclude=True
163
+ default=None, alias="RentalPrice_discounted", exclude=True
164
+ )
165
+ rental_price_row_2: str | None = Field(
166
+ default=None, alias="RentalPrice_row2", exclude=True
158
167
  )
159
- rental_price_row_2: str = Field(alias="RentalPrice_row2", exclude=True)
160
168
  rental_price_discount_source: str | None = Field(
161
- alias="RentalPrice_discountSource", exclude=True
169
+ default=None, alias="RentalPrice_discountSource", exclude=True
162
170
  )
163
171
 
164
- @computed_field
172
+ @computed_field # type: ignore[prop-decorator, misc]
165
173
  @property
166
174
  def rental_price(self) -> RentalPrice:
167
175
  return RentalPrice(
@@ -172,13 +180,17 @@ class Vehicle(BaseModel):
172
180
  discount_source=self.rental_price_discount_source,
173
181
  )
174
182
 
175
- parking_price_item: str = Field(alias="ParkingPrice", exclude=True)
183
+ parking_price_item: str | None = Field(
184
+ default=None, alias="ParkingPrice", exclude=True
185
+ )
176
186
  parking_price_discounted: bool | str | None = Field(
177
- alias="ParkingPrice_discounted", exclude=True
187
+ default=None, alias="ParkingPrice_discounted", exclude=True
188
+ )
189
+ parking_price_unit: str | None = Field(
190
+ default=None, alias="ParkingPrice_unit", exclude=True
178
191
  )
179
- parking_price_unit: str = Field(alias="ParkingPrice_unit", exclude=True)
180
192
 
181
- @computed_field
193
+ @computed_field # type: ignore[prop-decorator, misc]
182
194
  @property
183
195
  def parking_price(self) -> ParkingPrice:
184
196
  return ParkingPrice(
@@ -187,13 +199,15 @@ class Vehicle(BaseModel):
187
199
  discounted=bool(self.parking_price_discounted),
188
200
  )
189
201
 
190
- unlock_fee_item: str = Field(alias="UnlockFee", exclude=True)
202
+ unlock_fee_item: str | None = Field(default=None, alias="UnlockFee", exclude=True)
191
203
  unlock_fee_discounted: str | None = Field(
192
- alias="UnlockFee_discounted", exclude=True
204
+ default=None, alias="UnlockFee_discounted", exclude=True
205
+ )
206
+ unlock_fee_unit: str | None = Field(
207
+ default=None, alias="UnlockFee_unit", exclude=True
193
208
  )
194
- unlock_fee_unit: str = Field(alias="UnlockFee_unit", exclude=True)
195
209
 
196
- @computed_field
210
+ @computed_field # type: ignore[prop-decorator, misc]
197
211
  @property
198
212
  def unlock_fee(self) -> UnlockFee:
199
213
  return UnlockFee(
@@ -202,65 +216,79 @@ class Vehicle(BaseModel):
202
216
  discounted=bool(self.unlock_fee_discounted),
203
217
  )
204
218
 
205
- fuel_percent: str = Field(alias="FuelPct")
206
- fuel_level_icon: int = Field(alias="FuelLevelIcon")
207
- remaining_range: str = Field(alias="RemainingRange")
208
- ev_plugged: bool = Field(alias="EVPlugged")
209
- fvd_price: str = Field(alias="FVDPrice")
210
- url_vehicle_image: str = Field(alias="URLVehicleImage")
211
- rookie_delay_txt: str = Field(alias="RookieDelayTxt")
212
- number_days_rookies_delay: int = Field(alias="nDaysRookieDelay")
213
- premium_restricted_txt: str = Field(alias="PremiumRestrictedTxt")
219
+ fuel_percent: str | None = Field(default=None, alias="FuelPct")
220
+ fuel_level_icon: int | None = Field(default=None, alias="FuelLevelIcon")
221
+ remaining_range: str | None = Field(default=None, alias="RemainingRange")
222
+ ev_plugged: bool | None = Field(default=None, alias="EVPlugged")
223
+ fvd_price: str | None = Field(default=None, alias="FVDPrice")
224
+ url_vehicle_image: str | None = Field(default=None, alias="URLVehicleImage")
225
+ rookie_delay_txt: str | None = Field(default=None, alias="RookieDelayTxt")
226
+ number_days_rookies_delay: int | None = Field(
227
+ default=None, alias="nDaysRookieDelay"
228
+ )
229
+ premium_restricted_txt: str | None = Field(
230
+ default=None, alias="PremiumRestrictedTxt"
231
+ )
214
232
  city_to_city_options_string: str | None = Field(
215
- alias="CityToCityOptions", exclude=True
233
+ default=None, alias="CityToCityOptions", exclude=True
216
234
  )
217
235
 
218
- @computed_field
236
+ @computed_field # type: ignore[prop-decorator, misc]
219
237
  @property
220
- def city_to_city_options(self) -> CityToCityOptions:
238
+ def city_to_city_options(self) -> CityToCityOptions | None:
239
+ if not self.city_to_city_options_string:
240
+ return None
221
241
  return CityToCityOptions.model_validate_json(self.city_to_city_options_string)
222
242
 
223
243
  json_vehicle_damages_input: str | None = Field(
224
- alias="JSONVehicleDamages", exclude=True
244
+ default=None, alias="JSONVehicleDamages", exclude=True
225
245
  )
226
246
 
227
- @computed_field
247
+ @computed_field # type: ignore[prop-decorator, misc]
228
248
  @property
229
249
  def json_vehicle_damages(self) -> list[dict[str, Any]]:
230
- if self.json_vehicle_damages_input is None:
250
+ if not self.json_vehicle_damages_input:
231
251
  return []
232
252
  else:
233
253
  return mujson.loads(self.json_vehicle_damages_input)
234
254
 
235
- json_vehicle_banner: str | None = Field(alias="JSONVehicleBanner")
255
+ json_vehicle_banner: str | None = Field(default=None, alias="JSONVehicleBanner")
236
256
 
237
257
 
238
258
  class VehicleResponse(BaseModel):
239
259
  result: str = Field(alias="Result")
240
- response_text: str | None = Field(alias="ResponseText")
241
- id_vehicle_booked: str | None = Field(alias="idVehicleBooked")
242
- id_ride: str | None = Field(alias="idRide")
243
- id_vehicle_in_ride: str | None = Field(alias="idVehicleInRide")
244
- nearest_id_city: str | None = Field(alias="NearestIdCity")
245
- live_payment: bool = Field(alias="LivePayment")
246
- top_up_required: bool = Field(alias="TopUpRequired")
247
- user_app_version: str | float = Field(alias="userAppVersion")
248
- n_filter_elements: int = Field(alias="nFilterElements")
249
- user_in_ops_mode: bool = Field(alias="UserInOpsMode")
250
- special_airport_rate: str | None = Field(alias="SpecialAirportRate")
251
- special_airport_rate_e: str | None = Field(alias="SpecialAirportRate_E")
252
- special_airport_rate_2: str | None = Field(alias="SpecialAirportRate_2")
253
- special_airport_rate_e_2: str | None = Field(alias="SpecialAirportRate_E_2")
254
- uses_ppc: bool = Field(alias="UsesPPC")
255
- current_subscription: str | None = Field(alias="CurrentSubscription")
256
- json_city_areas: str = Field(alias="JSONCityAreas")
257
- city_areas_timestamp: datetime = Field(alias="CityAreasTimestamp")
258
- additional_info: str = Field(alias="AdditionalInfo")
260
+ response_text: str | None = Field(default=None, alias="ResponseText")
261
+ id_vehicle_booked: str | None = Field(default=None, alias="idVehicleBooked")
262
+ id_ride: str | None = Field(default=None, alias="idRide")
263
+ id_vehicle_in_ride: str | None = Field(default=None, alias="idVehicleInRide")
264
+ nearest_id_city: str | None = Field(default=None, alias="NearestIdCity")
265
+ live_payment: bool | None = Field(default=None, alias="LivePayment")
266
+ top_up_required: bool | None = Field(default=None, alias="TopUpRequired")
267
+ user_app_version: str | float | None = Field(default=None, alias="userAppVersion")
268
+ n_filter_elements: int | None = Field(default=None, alias="nFilterElements")
269
+ user_in_ops_mode: bool | None = Field(default=None, alias="UserInOpsMode")
270
+ special_airport_rate: str | None = Field(default=None, alias="SpecialAirportRate")
271
+ special_airport_rate_e: str | None = Field(
272
+ default=None, alias="SpecialAirportRate_E"
273
+ )
274
+ special_airport_rate_2: str | None = Field(
275
+ default=None, alias="SpecialAirportRate_2"
276
+ )
277
+ special_airport_rate_e_2: str | None = Field(
278
+ default=None, alias="SpecialAirportRate_E_2"
279
+ )
280
+ uses_ppc: bool | None = Field(default=None, alias="UsesPPC")
281
+ current_subscription: str | None = Field(default=None, alias="CurrentSubscription")
282
+ json_city_areas: str | None = Field(default=None, alias="JSONCityAreas")
283
+ city_areas_timestamp: datetime | None = Field(
284
+ default=None, alias="CityAreasTimestamp"
285
+ )
286
+ additional_info: str | None = Field(default=None, alias="AdditionalInfo")
259
287
 
260
288
 
261
289
  class VehicleReturn(BaseModel):
262
- response: VehicleResponse = Field(alias="response")
263
- vehicles: list[Vehicle] = Field(alias="vehicles")
290
+ response: VehicleResponse | None = Field(default=None, alias="response")
291
+ vehicles: list[Vehicle] = Field(default_factory=list, alias="vehicles")
264
292
 
265
293
 
266
294
  APIData = TypeVar("APIData")
@@ -268,5 +296,5 @@ APIData = TypeVar("APIData")
268
296
 
269
297
  class APIReturn(BaseModel, Generic[APIData]):
270
298
  result: str = Field(alias="Result")
271
- response_text: str | None = Field(alias="ResponseText")
299
+ response_text: str | None = Field(default=None, alias="ResponseText")
272
300
  data: APIData = Field(alias="Data")
@@ -1,14 +1,16 @@
1
- from uuid import UUID, uuid4
1
+ from uuid import uuid4
2
2
  import pytest
3
3
  from m_car_api import vehicles, vehicles_meters_around_location
4
4
 
5
5
 
6
6
  @pytest.fixture
7
7
  def device_key(request: pytest.FixtureRequest) -> str:
8
- device_key = request.config.cache.get("mapi/device-key", None)
8
+ cache = request.config.cache
9
+ assert cache is not None
10
+ device_key = cache.get("mapi/device-key", None)
9
11
  if device_key is None:
10
12
  device_key = str(uuid4())
11
- request.config.cache.set("mapi/device-key", device_key)
13
+ cache.set("mapi/device-key", device_key)
12
14
  return device_key
13
15
 
14
16
 
@@ -0,0 +1,87 @@
1
+ import pytest
2
+
3
+ from json import loads
4
+ from pathlib import Path
5
+ from m_car_api.objects import APIReturn, VehicleReturn, parse_vehicles_payload
6
+
7
+
8
+ @pytest.fixture(scope="session")
9
+ def vehicle_json_path() -> Path:
10
+ return Path(__file__).parent / "vehicle_return.json"
11
+
12
+
13
+ @pytest.fixture(scope="session")
14
+ def vehicle_json(vehicle_json_path: str) -> str:
15
+ with open(vehicle_json_path) as f:
16
+ return f.read()
17
+
18
+
19
+ def test_vehicle_check(vehicle_json: str):
20
+ result = parse_vehicles_payload(loads(vehicle_json))
21
+ assert isinstance(result, APIReturn)
22
+ assert isinstance(result.data, VehicleReturn)
23
+ first_vehicle = result.data.vehicles[0]
24
+ first_vehicle.id == 10326
25
+ first_vehicle.license_plate == "B-MS 4309"
26
+
27
+
28
+ def test_vehicle_check_with_missing_and_null_fields(vehicle_json: str):
29
+ payload = loads(vehicle_json)
30
+ response = payload["Data"]["response"]
31
+ for key in (
32
+ "SpecialAirportRate",
33
+ "SpecialAirportRate_E",
34
+ "SpecialAirportRate_2",
35
+ "SpecialAirportRate_E_2",
36
+ "UsesPPC",
37
+ "CurrentSubscription",
38
+ "JSONCityAreas",
39
+ "CityAreasTimestamp",
40
+ "AdditionalInfo",
41
+ ):
42
+ response.pop(key, None)
43
+ for vehicle in payload["Data"]["vehicles"]:
44
+ for key in (
45
+ "RentalPrice_discounted",
46
+ "ParkingPrice_discounted",
47
+ "JSONVehicleBanner",
48
+ ):
49
+ vehicle.pop(key, None)
50
+ vehicle["FVDPrice"] = None
51
+ vehicle["UnknownNewField"] = "ignored"
52
+
53
+ result = parse_vehicles_payload(payload)
54
+ first_vehicle = result.data.vehicles[0]
55
+ assert len(result.data.vehicles) == len(payload["Data"]["vehicles"])
56
+ assert first_vehicle.fvd_price is None
57
+ assert first_vehicle.rental_price.discounted is False
58
+ assert first_vehicle.parking_price.discounted is False
59
+ assert result.data.response is not None
60
+ assert result.data.response.uses_ppc is None
61
+
62
+
63
+ def test_vehicle_check_with_minimal_vehicle():
64
+ payload = {
65
+ "Result": "OK",
66
+ "Data": {
67
+ "response": {"Result": "OK"},
68
+ "vehicles": [
69
+ {
70
+ "idVehicle": 1,
71
+ "idCity": "HAM",
72
+ "LicensePlate": "HH-AB 123",
73
+ "VehicleSize": "M",
74
+ "isElectric": True,
75
+ "Latitude": 53.5,
76
+ "Longitude": 10.0,
77
+ "idVehicleStatus": "DEPLOYED_FOR_RENTAL",
78
+ }
79
+ ],
80
+ },
81
+ }
82
+ result = parse_vehicles_payload(payload)
83
+ vehicle = result.data.vehicles[0]
84
+ assert vehicle.license_plate == "HH-AB 123"
85
+ assert vehicle.city_to_city_options is None
86
+ assert vehicle.json_vehicle_damages == []
87
+ assert vehicle.rental_price.price is None
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: m_car_api
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Home-page: https://github.com/cbrand/m_car_api
5
5
  Author: Christoph Brand
6
6
  Author-email: christoph@brand.rest
@@ -26,6 +26,7 @@ Requires-Dist: coverage<7,>=5.1; extra == "test"
26
26
  Requires-Dist: faker<19,>=18; extra == "test"
27
27
  Requires-Dist: flake8<6,>=5.0.4; extra == "test"
28
28
  Requires-Dist: mypy>=0.961; extra == "test"
29
+ Requires-Dist: types-requests; extra == "test"
29
30
  Requires-Dist: pre-commit<4,>=3; extra == "test"
30
31
  Requires-Dist: pytest-cases<4,>=3.1.1; extra == "test"
31
32
  Requires-Dist: pytest-html; extra == "test"
@@ -41,3 +42,12 @@ Provides-Extra: pydantic-2
41
42
  Requires-Dist: pydantic<3,>=2; extra == "pydantic-2"
42
43
  Provides-Extra: pyproj
43
44
  Requires-Dist: pyproj; extra == "pyproj"
45
+ Dynamic: author
46
+ Dynamic: author-email
47
+ Dynamic: classifier
48
+ Dynamic: home-page
49
+ Dynamic: license
50
+ Dynamic: project-url
51
+ Dynamic: provides-extra
52
+ Dynamic: requires-dist
53
+ Dynamic: requires-python
@@ -18,6 +18,7 @@ coverage<7,>=5.1
18
18
  faker<19,>=18
19
19
  flake8<6,>=5.0.4
20
20
  mypy>=0.961
21
+ types-requests
21
22
  pre-commit<4,>=3
22
23
  pytest-cases<4,>=3.1.1
23
24
  pytest-html
@@ -1,24 +0,0 @@
1
- import pytest
2
-
3
- from json import loads
4
- from pathlib import Path
5
- from m_car_api.objects import APIReturn, VehicleReturn, parse_vehicles_payload
6
-
7
-
8
- @pytest.fixture(scope="session")
9
- def vehicle_json_path() -> Path:
10
- return Path(__file__).parent / "vehicle_return.json"
11
-
12
-
13
- @pytest.fixture(scope="session")
14
- def vehicle_json(vehicle_json_path: str) -> str:
15
- with open(vehicle_json_path) as f:
16
- return f.read()
17
-
18
-
19
- def test_vehicle_check(vehicle_json: str):
20
- result = parse_vehicles_payload(loads(vehicle_json))
21
- assert isinstance(result, APIReturn[VehicleReturn])
22
- first_vehicle = result.data.vehicles[0]
23
- first_vehicle.id == 10326
24
- first_vehicle.license_plate == "B-MS 4309"
File without changes