Skip to content

Commit

Permalink
Update code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet committed Jan 25, 2021
1 parent bd84a28 commit cbc47b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/renault_api/kamereon/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 10 additions & 15 deletions tests/kamereon/test_kamereon_charge_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -25,39 +24,35 @@ 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:
helpers.validate_charge_schedules(charge_settings.schedules)
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:
helpers.validate_charge_schedules(charge_settings.schedules)
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"
Expand Down

0 comments on commit cbc47b4

Please sign in to comment.