Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/workflows/hypervisor_downtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def get_number_of_hours(start_dt, end_time_str, duration):

:raises ValueError: if the input string is invalid or contains negative values
"""
end_time_str = end_time_str.strip()
duration = duration.strip()
if end_time_str is not None:
end_time_str = end_time_str.strip()
if duration is not None:
duration = duration.strip()
if not end_time_str and not duration:
raise ValueError("Input strings cannot be both empty at the same time")

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/workflows/test_hypervisor_downtimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ def test_both_single_space_raise_exception():
get_number_of_hours(start_dt, " ", " ")


def test_none_types_handled_too():
"""Test that both parameters as None in either field does not raise a ValueError"""
start_dt = datetime.datetime.strptime("2024-01-01 10:00", "%Y-%m-%d %H:%M").replace(
tzinfo=pytz.utc
)
result = get_number_of_hours(start_dt, "2024-01-01 11:00", None)
assert result == 1

result = get_number_of_hours(start_dt, None, "1h")
assert result == 1


def test_both_multiple_spaces_raise_exception():
"""Test that both parameters as multiple spaces raise ValueError"""
start_dt = datetime.datetime.strptime("2024-01-01 10:00", "%Y-%m-%d %H:%M").replace(
Expand Down