diff --git a/src/renault_api/kamereon/helpers.py b/src/renault_api/kamereon/helpers.py index d487040f..b608b9d8 100644 --- a/src/renault_api/kamereon/helpers.py +++ b/src/renault_api/kamereon/helpers.py @@ -69,13 +69,13 @@ def get_total_minutes(start_time: Optional[str], duration: Optional[int] = None) def validate_charge_schedules(schedules: List[models.ChargeSchedule]) -> None: """Validate a list of ChargeSchedule.""" - for schedule in schedules: + for schedule in schedules: # pragma: no branch validate_charge_schedule(schedule) def validate_charge_schedule(schedule: models.ChargeSchedule) -> None: """Validate a ChargeSchedule.""" - for day in DAYS_OF_WEEK: + for day in DAYS_OF_WEEK: # pragma: no branch day_schedule: models.ChargeDaySchedule = getattr(schedule, day) if day_schedule: # pragma: no branch try: diff --git a/tests/kamereon/test_kamereon_charge_settings.py b/tests/kamereon/test_kamereon_charge_settings.py index 969107c6..3c41451e 100644 --- a/tests/kamereon/test_kamereon_charge_settings.py +++ b/tests/kamereon/test_kamereon_charge_settings.py @@ -10,11 +10,10 @@ from renault_api.kamereon.exceptions import ModelValidationException -@pytest.fixture -def charge_settings() -> models.KamereonVehicleChargingSettingsData: +def get_charge_settings(type: str) -> models.KamereonVehicleChargingSettingsData: """Test vehicle data for location.json.""" response: models.KamereonVehicleDataResponse = fixtures.get_file_content_as_schema( - f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicle_data/charging-settings.json", + f"{fixtures.KAMEREON_FIXTURE_PATH}/vehicle_data/charging-settings.{type}.json", schemas.KamereonVehicleDataResponseSchema, ) response.raise_for_error_code() @@ -25,17 +24,15 @@ def charge_settings() -> models.KamereonVehicleChargingSettingsData: ) -def test_validation_success( - charge_settings: models.KamereonVehicleChargingSettingsData, -) -> None: +def test_validation_success() -> None: """Test validation of a good schedule list.""" + charge_settings = get_charge_settings("multi") helpers.validate_charge_schedules(charge_settings.schedules) -def test_validation_invalid_start_time( - charge_settings: models.KamereonVehicleChargingSettingsData, -) -> None: +def test_validation_invalid_start_time() -> None: """Test validation of an invalid start time.""" + charge_settings = get_charge_settings("multi") charge_settings.schedules[0].monday.startTime = "12:00" with pytest.raises(ModelValidationException) as excinfo: @@ -43,10 +40,9 @@ def test_validation_invalid_start_time( assert "is not a valid start time" in str(excinfo.value) -def test_validation_invalid_duration( - charge_settings: models.KamereonVehicleChargingSettingsData, -) -> None: +def test_validation_invalid_duration() -> None: """Test validation of an invalid start time.""" + charge_settings = get_charge_settings("multi") charge_settings.schedules[0].monday.startTime = "T12:00Z" charge_settings.schedules[0].monday.duration = 14 with pytest.raises(ModelValidationException) as excinfo: @@ -54,10 +50,9 @@ def test_validation_invalid_duration( assert "is not a valid duration" in str(excinfo.value) -def test_validation_overlap( - charge_settings: models.KamereonVehicleChargingSettingsData, -) -> None: +def test_validation_overlap() -> None: """Test validation of an overlap with the next day.""" + charge_settings = get_charge_settings("multi") charge_settings.schedules[0].wednesday.startTime = "T22:30Z" charge_settings.schedules[0].wednesday.duration = 420 charge_settings.schedules[0].thursday.startTime = "T01:00Z"