Skip to content

Commit

Permalink
add tests for data models
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Nov 15, 2024
1 parent 2b512e6 commit 54328dc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/data/polestar3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"getBatteryData": {
"averageEnergyConsumptionKwhPer100Km": 22.4,
"batteryChargeLevelPercentage": 34,
"chargerConnectionStatus": "CHARGER_CONNECTION_STATUS_DISCONNECTED",
"chargingCurrentAmps": null,
"chargingPowerWatts": null,
"chargingStatus": "CHARGING_STATUS_IDLE",
"estimatedChargingTimeMinutesToTargetDistance": 0,
"estimatedChargingTimeToFullMinutes": 0,
"estimatedDistanceToEmptyKm": 150,
"estimatedDistanceToEmptyMiles": 90,
"eventUpdatedTimestamp": {
"iso": "2024-11-11T17:47:13.000Z",
"unix": "1731347233"
}
},
"getConsumerCarsV2": {
"content": {
"images": {
"studio": {
"url": "https://cas.polestar.com/image/dynamic/MY24_2207/359/summary-transparent-v2/EA/1/72300/R80000/R102/LR02/EV02/K503/JB07/SW01/_/ET01/default.png?market=se"
}
},
"model": {
"name": "Polestar 3"
},
"specification": {
"battery": "400V lithium-ion battery, 111 kWh capacity, 17 modules",
"torque": "840 Nm / 620 lbf-ft"
}
},
"factoryCompleteDate": "2024-04-16",
"internalVehicleIdentifier": "1aaeb452-700e-46f3-9899-395b6219c8a6",
"registrationDate": null,
"registrationNo": "MLB007",
"software": {
"version": null,
"versionTimestamp": null
},
"vin": "YSMYKEAE7RB000000"
},
"getOdometerData": {
"averageSpeedKmPerHour": 42,
"eventUpdatedTimestamp": {
"iso": "2024-11-11T15:15:16.000Z",
"unix": "1731338116"
},
"odometerMeters": 2001000,
"tripMeterAutomaticKm": 4.2,
"tripMeterManualKm": 1984.0
}
}
26 changes: 26 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os
from pathlib import Path

from polestar_api.pypolestar.models import (
CarBatteryData,
CarInformationData,
CarOdometerData,
)

DATADIR = Path(os.path.abspath(os.path.dirname(__file__))) / "data"

with open(DATADIR / "polestar3.json") as fp:
POLESTAR_3 = json.load(fp)


def test_car_information_data():
_ = CarInformationData.from_dict(POLESTAR_3["getConsumerCarsV2"])


def test_car_battery_data():
_ = CarBatteryData.from_dict(POLESTAR_3["getBatteryData"])


def test_car_odometer_data():
_ = CarOdometerData.from_dict(POLESTAR_3["getOdometerData"])

0 comments on commit 54328dc

Please sign in to comment.