Skip to content

Commit

Permalink
mark old tests as legacy and add some new tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
CM000n committed Dec 1, 2023
1 parent b664326 commit 3f589ee
Show file tree
Hide file tree
Showing 15 changed files with 1,767 additions and 0 deletions.
127 changes: 127 additions & 0 deletions tests/legacy_test_hvac.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""pytest tests for mytoyota.models.hvac.Hvac."""

from mytoyota.models.hvac import Hvac


class TestHvac:
"""pytest functions to test Hvac."""

@staticmethod
def _create_example_data():
"""Create hvac with predefined data."""
return Hvac(
{
"currentTemperatureIndication": {
"timestamp": "2020-10-16T03:50:15Z",
"unit": "string",
"value": 22,
},
"targetTemperature": {
"timestamp": "2020-10-16T03:50:15Z",
"unit": "string",
"value": 21,
},
"startedAt": "",
"status": "",
"type": "",
"duration": 1,
"options": {
"frontDefogger": "",
"frontDriverSeatHeater": "",
"frontPassengerSeatHeater": "",
"mirrorHeater": "",
"rearDefogger": "",
"rearDriverSeatHeater": "",
"rearPassengerSeatHeater": "",
"steeringHeater": "",
},
"commandId": "",
},
)

@staticmethod
def _create_example_legacy_data():
"""Create legacy hvac with predefined data."""
return Hvac(
{
"BlowerStatus": 0,
"FrontDefoggerStatus": 0,
"InsideTemperature": 22,
"LatestAcStartTime": "2020-10-16T03:50:15Z",
"RearDefoggerStatus": 0,
"RemoteHvacMode": 0,
"RemoteHvacProhibitionSignal": 1,
"SettingTemperature": 21,
"TemperatureDisplayFlag": 0,
"Temperaturelevel": 29,
},
legacy=True,
)

def test_hvac(self):
"""Test Hvac."""
hvac = self._create_example_data()

assert hvac.legacy is False

assert hvac.current_temperature == 22
assert hvac.target_temperature == 21
assert hvac.started_at == ""
assert hvac.status == ""
assert hvac.type == ""
assert hvac.duration == 1
assert hvac.command_id == ""
assert isinstance(hvac.options, dict)
assert hvac.options == {
"frontDefogger": "",
"frontDriverSeatHeater": "",
"frontPassengerSeatHeater": "",
"mirrorHeater": "",
"rearDefogger": "",
"rearDriverSeatHeater": "",
"rearPassengerSeatHeater": "",
"steeringHeater": "",
}

assert hvac.last_updated == "2020-10-16T03:50:15Z"

assert hvac.front_defogger_is_on is None
assert hvac.rear_defogger_is_on is None
assert hvac.blower_on is None

def test_hvac_legacy(self):
"""Test legacy Hvac."""
hvac = self._create_example_legacy_data()

assert hvac.legacy is True

assert hvac.current_temperature == 22
assert hvac.target_temperature == 21
assert hvac.blower_on == 0
assert hvac.front_defogger_is_on is False
assert hvac.rear_defogger_is_on is False
assert hvac.last_updated is None

assert hvac.started_at is None
assert hvac.status is None
assert hvac.type is None
assert hvac.duration is None
assert hvac.options is None
assert hvac.command_id is None

def test_hvac_no_data(self):
"""Test Hvac with no initialization data."""
hvac = Hvac({})

assert hvac.legacy is False

assert hvac.current_temperature is None
assert hvac.target_temperature is None
assert hvac.started_at is None
assert hvac.status is None
assert hvac.type is None
assert hvac.duration is None
assert hvac.command_id is None
assert hvac.options is None

assert hvac.last_updated is None
107 changes: 107 additions & 0 deletions tests/legacy_test_lock_unlock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""pytest tests for mytoyota.client.MyT sending lock/unlock requests."""
import asyncio
from datetime import datetime

import pytest

from mytoyota.exceptions import ToyotaActionNotSupportedError
from mytoyota.models.lock_unlock import (
VehicleLockUnlockActionResponse,
VehicleLockUnlockStatusResponse,
)
from tests.test_myt import TestMyTHelper


class TestLockUnlock(TestMyTHelper):
"""Pytest functions to test locking and unlocking."""

successful_lock_request_id = "d4f873d2-5da2-494f-a6d9-6e56d18d2ce9"
failed_lock_request_id = "14f873d2-5da2-494f-a6d9-6e56d18d2ce9"
pending_lock_request_id = "24f873d2-5da2-494f-a6d9-6e56d18d2ce9"

def test_send_lock_request(self):
"""Test sending the lock request."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(myt.set_lock_vehicle(vehicle["vin"]))
assert isinstance(result, VehicleLockUnlockActionResponse)
assert result.raw_json == {
"id": self.pending_lock_request_id,
"status": "inprogress",
"type": "controlLock",
}
assert result.request_id == self.pending_lock_request_id
assert result.status == "inprogress"
assert result.type == "controlLock"

def test_send_unlock_request(self):
"""Test sending the unlock request."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(myt.set_unlock_vehicle(vehicle["vin"]))
assert isinstance(result, VehicleLockUnlockActionResponse)
assert result.raw_json == {
"id": self.pending_lock_request_id,
"status": "inprogress",
"type": "controlLock",
}

def test_get_successful_lock_status(self):
"""Test getting the lock status."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(
myt.get_lock_status(vehicle["vin"], self.successful_lock_request_id),
)
assert isinstance(result, VehicleLockUnlockStatusResponse)
assert result.raw_json == {
"id": self.successful_lock_request_id,
"status": "completed",
"requestTimestamp": "2022-10-22T08:49:20.071Z",
"type": "controlLock",
}
assert result.request_id == self.successful_lock_request_id
assert result.status == "completed"
assert result.type == "controlLock"
assert result.request_timestamp == datetime(2022, 10, 22, 8, 49, 20, 71000)
assert not result.is_in_progress
assert not result.is_error
assert result.is_success

def test_get_failed_lock_status(self):
"""Test getting the lock status."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 4444444)
result = asyncio.get_event_loop().run_until_complete(
myt.get_lock_status(vehicle["vin"], self.failed_lock_request_id),
)
assert isinstance(result, VehicleLockUnlockStatusResponse)
assert result.raw_json == {
"id": self.failed_lock_request_id,
"status": "error",
"errorCode": "LU0004",
"requestTimestamp": "2022-10-22T08:49:20.071Z",
"type": "controlLock",
}
assert result.request_id == self.failed_lock_request_id
assert result.status == "error"
assert result.error_code == "LU0004"
assert result.type == "controlLock"
assert result.request_timestamp == datetime(2022, 10, 22, 8, 49, 20, 71000)
assert not result.is_in_progress
assert result.is_error
assert not result.is_success

def test_set_lock_vehicle_unsupported(self):
"""Test sending the lock request to a vehicle for which it is not supported."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 1111111)
with pytest.raises(ToyotaActionNotSupportedError):
asyncio.get_event_loop().run_until_complete(myt.set_lock_vehicle(vehicle["vin"]))

def test_set_unlock_vehicle_unsupported(self):
"""Test sending the lock request to a vehicle for which it is not supported."""
myt = self._create_offline_myt()
vehicle = self._lookup_vehicle(myt, 1111111)
with pytest.raises(ToyotaActionNotSupportedError):
asyncio.get_event_loop().run_until_complete(myt.set_unlock_vehicle(vehicle["vin"]))
Loading

0 comments on commit 3f589ee

Please sign in to comment.