mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-26 10:17:18 +00:00
@@ -0,0 +1,31 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from psa_car_controller.psa.RemoteClient import RemoteClient
|
||||
from psa_car_controller.psa.connected_car_api import Vehicles, ApiClient
|
||||
from psa_car_controller.psa.constants import DISCONNECTED
|
||||
from psa_car_controller.psacc.model.car import Car
|
||||
from tests.data.car_status import ELECTRIC_CAR_STATUS
|
||||
|
||||
|
||||
class TestUnit(unittest.TestCase):
|
||||
|
||||
def get_rc(self) -> RemoteClient:
|
||||
account_info = MagicMock()
|
||||
account_info.realm = ""
|
||||
return RemoteClient(account_info, Vehicles, None, None)
|
||||
|
||||
@patch('time.sleep', return_value=None)
|
||||
def test_fix_not_updated_api(self, patched_time_sleep):
|
||||
# GIVEN
|
||||
remote_client = self.get_rc()
|
||||
vin = "myvin"
|
||||
car = Car("a", "b", "c")
|
||||
car.status = ApiClient()._ApiClient__deserialize(ELECTRIC_CAR_STATUS, "Status")
|
||||
car.status.get_energy('Electric').charging.status = DISCONNECTED
|
||||
remote_client.vehicles_list.get_car_by_vin = MagicMock(return_value=car)
|
||||
remote_client.wakeup = MagicMock()
|
||||
# WHEN
|
||||
remote_client._fix_not_updated_api({'remaining_time': 1}, vin)
|
||||
# THEN
|
||||
remote_client.wakeup.assert_called_once_with(vin)
|
||||
@@ -7,6 +7,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import reverse_geocode
|
||||
from dateutil.tz import tzutc
|
||||
from greenery.lego import parse, charclass
|
||||
from pytz import UTC
|
||||
|
||||
from psa_car_controller import psa
|
||||
@@ -302,6 +303,15 @@ class TestUnit(unittest.TestCase):
|
||||
f.write(" ")
|
||||
assert github_file_need_to_be_downloaded(GITHUB_USER, GITHUB_REPO, "", filename) is True
|
||||
|
||||
def test_regex(self):
|
||||
car_models = CarModelRepository().models
|
||||
for x in range(0, len(car_models)):
|
||||
for y in range(x + 1, len(car_models)):
|
||||
reg_a = car_models[x].reg
|
||||
reg_b = car_models[y].reg
|
||||
res: charclass = parse(reg_a) & parse(reg_b)
|
||||
self.assertTrue(res.empty(), msg=f"{reg_a} and {reg_b} can match the same string")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
my_logger(handler_level=os.environ.get("DEBUG_LEVEL", 20))
|
||||
|
||||
Reference in New Issue
Block a user