mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Nextbus: Listify directions (#103337)
When a single value is returned, the list wrapper is not present in the json payload. This patch ensures that the result is always a list.
This commit is contained in:
parent
ae1117bc74
commit
51c3a5d11d
@ -16,6 +16,7 @@ from homeassistant.helpers.selector import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from .const import CONF_AGENCY, CONF_ROUTE, CONF_STOP, DOMAIN
|
from .const import CONF_AGENCY, CONF_ROUTE, CONF_STOP, DOMAIN
|
||||||
|
from .util import listify
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ def _get_stop_tags(
|
|||||||
title_counts = Counter(tags.values())
|
title_counts = Counter(tags.values())
|
||||||
|
|
||||||
stop_directions: dict[str, str] = {}
|
stop_directions: dict[str, str] = {}
|
||||||
for direction in route_config["route"]["direction"]:
|
for direction in listify(route_config["route"]["direction"]):
|
||||||
for stop in direction["stop"]:
|
for stop in direction["stop"]:
|
||||||
stop_directions[stop["tag"]] = direction["name"]
|
stop_directions[stop["tag"]] = direction["name"]
|
||||||
|
|
||||||
|
@ -1,11 +1,37 @@
|
|||||||
"""Test helpers for NextBus tests."""
|
"""Test helpers for NextBus tests."""
|
||||||
|
from typing import Any
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(
|
||||||
|
params=[
|
||||||
|
{"name": "Outbound", "stop": [{"tag": "5650"}]},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "Outbound",
|
||||||
|
"stop": [{"tag": "5650"}],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Inbound",
|
||||||
|
"stop": [{"tag": "5651"}],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def route_config_direction(request: pytest.FixtureRequest) -> Any:
|
||||||
|
"""Generate alternative directions values.
|
||||||
|
|
||||||
|
When only on edirection is returned, it is not returned as a list, but instead an object.
|
||||||
|
"""
|
||||||
|
return request.param
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_nextbus_lists(mock_nextbus: MagicMock) -> MagicMock:
|
def mock_nextbus_lists(
|
||||||
|
mock_nextbus: MagicMock, route_config_direction: Any
|
||||||
|
) -> MagicMock:
|
||||||
"""Mock all list functions in nextbus to test validate logic."""
|
"""Mock all list functions in nextbus to test validate logic."""
|
||||||
instance = mock_nextbus.return_value
|
instance = mock_nextbus.return_value
|
||||||
instance.get_agency_list.return_value = {
|
instance.get_agency_list.return_value = {
|
||||||
@ -22,16 +48,7 @@ def mock_nextbus_lists(mock_nextbus: MagicMock) -> MagicMock:
|
|||||||
# Error case test. Duplicate title with no unique direction
|
# Error case test. Duplicate title with no unique direction
|
||||||
{"tag": "5652", "title": "Market St & 7th St"},
|
{"tag": "5652", "title": "Market St & 7th St"},
|
||||||
],
|
],
|
||||||
"direction": [
|
"direction": route_config_direction,
|
||||||
{
|
|
||||||
"name": "Outbound",
|
|
||||||
"stop": [{"tag": "5650"}],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Inbound",
|
|
||||||
"stop": [{"tag": "5651"}],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user