This commit is contained in:
Florian Bezannier
2022-03-28 23:10:55 +02:00
parent 834a7e0a38
commit e98b0ff5db
6 changed files with 62 additions and 18 deletions
+31
View File
@@ -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)
+10
View File
@@ -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))